Skip to content

Commit

Permalink
Add cluster_manager_node into cluster state metric
Browse files Browse the repository at this point in the history
Signed-off-by: Tianli Feng <[email protected]>
  • Loading branch information
Tianli Feng committed Mar 9, 2022
1 parent c3712a5 commit c73c35c
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"nodes",
"routing_table",
"master_node",
"cluster_manager_node",
"version"
],
"description":"Limit the information returned to the specified metrics. Defaults to all but metadata"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"routing_table",
"routing_nodes",
"master_node",
"cluster_manager_node",
"version"
],
"description":"Limit the information returned to the specified metrics"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,18 @@
"Basic sanity check":
- do:
cluster.reroute: {}

---
"Cluster reroute returns cluster_manager_node":
- skip:
version: " - 1.4.99"
reason: "The metric cluster_manager_node is added to cluster state in version 2.0.0"

- do:
cluster.reroute: {}

- set:
state.cluster_manager_node: node_id

- match: {state.master_node: $node_id}
- match: {state.cluster_manager_node: $node_id}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- do:
cluster.reroute: {}
- is_false: state.metadata

---
"return metadata if requested":
- do:
Expand All @@ -12,3 +13,15 @@
- is_true: state.metadata
- is_false: state.nodes

---
"Filter the cluster reroute by cluster_manager_node only should work":
- skip:
version: " - 1.4.99"
reason: "The metric cluster_manager_node is added to cluster state in version 2.0.0"

- do:
cluster.reroute:
metric: [ cluster_manager_node ]

- is_true: state.cluster_manager_node
- is_false: state.master_node
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,18 @@

- is_true: cluster_uuid
- is_true: master_node

---
"Get cluster state returns cluster_manager_node":
- skip:
version: " - 1.4.99"
reason: "The metric cluster_manager_node is added to cluster state in version 2.0.0"

- do:
cluster.state: {}

- set:
cluster_manager_node: node_id

- match: {master_node: $node_id}
- match: {cluster_manager_node: $node_id}
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,16 @@ setup:

- match: { cluster_uuid: $cluster_uuid }
- is_true: routing_table

---
"Filter the cluster state by cluster_manager_node only should work":
- skip:
version: " - 1.4.99"
reason: "The metric cluster_manager_node is added to cluster state in version 2.0.0"

- do:
cluster.state:
metric: [ cluster_manager_node ]

- is_true: cluster_manager_node
- is_false: master_node
6 changes: 6 additions & 0 deletions server/src/main/java/org/opensearch/cluster/ClusterState.java
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ public boolean supersedes(ClusterState other) {
public enum Metric {
VERSION("version"),
MASTER_NODE("master_node"),
CLUSTER_MANAGER_NODE("cluster_manager_node"),
BLOCKS("blocks"),
NODES("nodes"),
METADATA("metadata"),
Expand Down Expand Up @@ -467,6 +468,11 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.field("master_node", nodes().getMasterNodeId());
}

// Value of the field is identical with the above, and aims to replace the above field.
if (metrics.contains(Metric.CLUSTER_MANAGER_NODE)) {
builder.field("cluster_manager_node", nodes().getMasterNodeId());
}

if (metrics.contains(Metric.BLOCKS)) {
builder.startObject("blocks");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
if (request.hasParam("metric")) {
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.nodes(
metrics.contains(ClusterState.Metric.NODES)
|| metrics.contains(ClusterState.Metric.MASTER_NODE)
|| metrics.contains(ClusterState.Metric.CLUSTER_MANAGER_NODE)
);
/*
* there is no distinction in Java api between routing_table and routing_nodes, it's the same info set over the wire, one single
* flag to ask for it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public void testToXContent() throws IOException {
+ " \"version\" : 0,\n"
+ " \"state_uuid\" : \"stateUUID\",\n"
+ " \"master_node\" : \"masterNodeId\",\n"
+ " \"cluster_manager_node\" : \"masterNodeId\",\n"
+ " \"blocks\" : {\n"
+ " \"global\" : {\n"
+ " \"1\" : {\n"
Expand Down Expand Up @@ -354,6 +355,7 @@ public void testToXContent_FlatSettingTrue_ReduceMappingFalse() throws IOExcepti
+ " \"version\" : 0,\n"
+ " \"state_uuid\" : \"stateUUID\",\n"
+ " \"master_node\" : \"masterNodeId\",\n"
+ " \"cluster_manager_node\" : \"masterNodeId\",\n"
+ " \"blocks\" : {\n"
+ " \"global\" : {\n"
+ " \"1\" : {\n"
Expand Down Expand Up @@ -554,6 +556,7 @@ public void testToXContent_FlatSettingFalse_ReduceMappingTrue() throws IOExcepti
+ " \"version\" : 0,\n"
+ " \"state_uuid\" : \"stateUUID\",\n"
+ " \"master_node\" : \"masterNodeId\",\n"
+ " \"cluster_manager_node\" : \"masterNodeId\",\n"
+ " \"blocks\" : {\n"
+ " \"global\" : {\n"
+ " \"1\" : {\n"
Expand Down Expand Up @@ -780,6 +783,7 @@ public void testToXContentSameTypeName() throws IOException {
+ " \"version\" : 0,\n"
+ " \"state_uuid\" : \"stateUUID\",\n"
+ " \"master_node\" : null,\n"
+ " \"cluster_manager_node\" : null,\n"
+ " \"blocks\" : { },\n"
+ " \"nodes\" : { },\n"
+ " \"metadata\" : {\n"
Expand Down

0 comments on commit c73c35c

Please sign in to comment.