Add extra validation into `cluster/stats`
The cluster health and cluster stats disagree on the status. Add a extra validation step in `cluster/stats`. closes #7390
This commit is contained in:
parent
aae60e5b6e
commit
f33184329f
|
@ -34,6 +34,7 @@ import org.elasticsearch.cluster.ClusterService;
|
||||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
||||||
import org.elasticsearch.cluster.routing.IndexRoutingTable;
|
import org.elasticsearch.cluster.routing.IndexRoutingTable;
|
||||||
|
import org.elasticsearch.cluster.routing.RoutingTableValidation;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
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.index.shard.IndexShard;
|
||||||
import org.elasticsearch.indices.IndicesService;
|
import org.elasticsearch.indices.IndicesService;
|
||||||
import org.elasticsearch.node.service.NodeService;
|
import org.elasticsearch.node.service.NodeService;
|
||||||
|
import org.elasticsearch.rest.RestStatus;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.transport.TransportService;
|
import org.elasticsearch.transport.TransportService;
|
||||||
|
|
||||||
|
@ -134,6 +136,14 @@ public class TransportClusterStatsAction extends TransportNodesAction<ClusterSta
|
||||||
break;
|
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()]));
|
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();
|
ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
|
||||||
assertThat(response.getNodesStats().getOs().getAllocatedProcessors(), equalTo(7));
|
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