Merge pull request #14699 from xuzha/cluster_health
Add extra validation into `cluster/stats` close #7390
This commit is contained in:
commit
85ce81c34e
|
@ -34,6 +34,7 @@ import org.elasticsearch.cluster.ClusterService;
|
|||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
||||
import org.elasticsearch.cluster.routing.IndexRoutingTable;
|
||||
import org.elasticsearch.cluster.routing.RoutingTableValidation;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
|
@ -42,6 +43,7 @@ import org.elasticsearch.index.IndexService;
|
|||
import org.elasticsearch.index.shard.IndexShard;
|
||||
import org.elasticsearch.indices.IndicesService;
|
||||
import org.elasticsearch.node.service.NodeService;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
|
@ -134,6 +136,14 @@ public class TransportClusterStatsAction extends TransportNodesAction<ClusterSta
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
RoutingTableValidation validation = clusterService.state().routingTable().validate(clusterService.state().metaData());
|
||||
|
||||
if (!validation.failures().isEmpty()) {
|
||||
clusterStatus = ClusterHealthStatus.RED;
|
||||
} else if (clusterService.state().blocks().hasGlobalBlock(RestStatus.SERVICE_UNAVAILABLE)) {
|
||||
clusterStatus = ClusterHealthStatus.RED;
|
||||
}
|
||||
}
|
||||
|
||||
return new ClusterStatsNodeResponse(nodeInfo.getNode(), clusterStatus, nodeInfo, nodeStats, shardsStats.toArray(new ShardStats[shardsStats.size()]));
|
||||
|
|
|
@ -170,4 +170,17 @@ public class ClusterStatsIT extends ESIntegTestCase {
|
|||
ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
|
||||
assertThat(response.getNodesStats().getOs().getAllocatedProcessors(), equalTo(7));
|
||||
}
|
||||
|
||||
public void testClusterStatus() throws Exception {
|
||||
// stop all other nodes
|
||||
internalCluster().ensureAtMostNumDataNodes(0);
|
||||
|
||||
internalCluster().startNode(Settings.builder().put("gateway.recover_after_nodes", 2).build());
|
||||
ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
|
||||
assertThat(response.getStatus(), equalTo(ClusterHealthStatus.RED));
|
||||
|
||||
internalCluster().ensureAtLeastNumDataNodes(3);
|
||||
response = client().admin().cluster().prepareClusterStats().get();
|
||||
assertThat(response.getStatus(), equalTo(ClusterHealthStatus.GREEN));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue