Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make routing_nodes an independent metric option in cluster state api #10412

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion rest-api-spec/api/cluster.state.json
Expand Up @@ -16,7 +16,7 @@
},
"metric" : {
"type" : "list",
"options" : ["_all", "blocks", "metadata", "nodes", "routing_table", "master_node", "version"],
"options" : ["_all", "blocks", "metadata", "nodes", "routing_table", "routing_nodes", "master_node", "version"],
"description" : "Limit the information returned to the specified metrics"
}
},
Expand Down
12 changes: 12 additions & 0 deletions rest-api-spec/test/cluster.state/20_filtering.yaml
Expand Up @@ -83,6 +83,18 @@ setup:
- is_true: routing_table
- is_true: routing_nodes

---
"Filtering the cluster state by routing nodes only should work":
- do:
cluster.state:
metric: [ routing_nodes ]

- is_false: blocks
- is_false: nodes
- is_false: metadata
- is_false: routing_table
- is_true: routing_nodes

---
"Filtering the cluster state by indices should work in routing table and metadata":
- do:
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/elasticsearch/cluster/ClusterState.java
Expand Up @@ -261,6 +261,7 @@ public enum Metric {
NODES("nodes"),
METADATA("metadata"),
ROUTING_TABLE("routing_table"),
ROUTING_NODES("routing_nodes"),
CUSTOMS("customs");

private static Map<String, Metric> valueToEnum;
Expand Down Expand Up @@ -465,7 +466,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
}

// routing nodes
if (metrics.contains(Metric.ROUTING_TABLE)) {
// keep ROUTING_TABLE for backward compatibility
if (metrics.contains(Metric.ROUTING_TABLE) || metrics.contains(Metric.ROUTING_NODES)) {
builder.startObject("routing_nodes");
builder.startArray("unassigned");
for (ShardRouting shardRouting : readOnlyRoutingNodes().unassigned()) {
Expand Down
Expand Up @@ -72,7 +72,7 @@ public void handleRequest(final RestRequest request, final RestChannel channel,
EnumSet<ClusterState.Metric> metrics = ClusterState.Metric.parseString(request.param("metric"), true);
// do not ask for what we do not need.
clusterStateRequest.nodes(metrics.contains(ClusterState.Metric.NODES) || metrics.contains(ClusterState.Metric.MASTER_NODE));
clusterStateRequest.routingTable(metrics.contains(ClusterState.Metric.ROUTING_TABLE));
clusterStateRequest.routingTable(metrics.contains(ClusterState.Metric.ROUTING_TABLE) || metrics.contains(ClusterState.Metric.ROUTING_NODES));
clusterStateRequest.metaData(metrics.contains(ClusterState.Metric.METADATA));
clusterStateRequest.blocks(metrics.contains(ClusterState.Metric.BLOCKS));
}
Expand Down