Skip to content

Commit

Permalink
Add cluster UUID to Cluster Stats API response (#32206)
Browse files Browse the repository at this point in the history
* Make cluster stats response contain cluster UUID

* Updating constructor usage in Monitoring tests

* Adding cluster_uuid field to Cluster Stats API reference doc

* Adding rest api spec test for expecting cluster_uuid in cluster stats response

* Adding missing newline

* Indenting do section properly

* Missed a spot!

* Fixing the test cluster ID
  • Loading branch information
ycombinator committed Aug 3, 2018
1 parent 98f2945 commit 60583f2
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/reference/cluster/stats.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Will return, for example:
"successful" : 1,
"failed" : 0
},
"cluster_uuid": "YjAvIhsCQ9CbjWZb2qJw3Q",
"cluster_name": "elasticsearch",
"timestamp": 1459427693515,
"status": "green",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,40 @@
- is_true: nodes.fs
- is_true: nodes.plugins
- is_true: nodes.network_types

---
"get cluster stats returns cluster_uuid at the top level":
- skip:
version: " - 6.99.99"
reason: "cluster stats including cluster_uuid at the top level is new in v6.5.0 and higher"

- do:
cluster.stats: {}

- is_true: cluster_uuid
- is_true: timestamp
- is_true: cluster_name
- match: {status: green}
- gte: { indices.count: 0}
- is_true: indices.docs
- is_true: indices.store
- is_true: indices.fielddata
- is_true: indices.query_cache
- is_true: indices.completion
- is_true: indices.segments
- gte: { nodes.count.total: 1}
- gte: { nodes.count.master: 1}
- gte: { nodes.count.data: 1}
- gte: { nodes.count.ingest: 0}
- gte: { nodes.count.coordinating_only: 0}
- is_true: nodes.os
- is_true: nodes.os.mem.total_in_bytes
- is_true: nodes.os.mem.free_in_bytes
- is_true: nodes.os.mem.used_in_bytes
- gte: { nodes.os.mem.free_percent: 0 }
- gte: { nodes.os.mem.used_percent: 0 }
- is_true: nodes.process
- is_true: nodes.jvm
- is_true: nodes.fs
- is_true: nodes.plugins
- is_true: nodes.network_types
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,18 @@ public class ClusterStatsResponse extends BaseNodesResponse<ClusterStatsNodeResp
ClusterStatsIndices indicesStats;
ClusterHealthStatus status;
long timestamp;
String clusterUUID;

ClusterStatsResponse() {
}

public ClusterStatsResponse(long timestamp,
String clusterUUID,
ClusterName clusterName,
List<ClusterStatsNodeResponse> nodes,
List<FailedNodeException> failures) {
super(clusterName, nodes, failures);
this.clusterUUID = clusterUUID;
this.timestamp = timestamp;
nodesStats = new ClusterStatsNodes(nodes);
indicesStats = new ClusterStatsIndices(nodes);
Expand All @@ -61,6 +64,10 @@ public ClusterStatsResponse(long timestamp,
}
}

public String getClusterUUID() {
return this.clusterUUID;
}

public long getTimestamp() {
return this.timestamp;
}
Expand Down Expand Up @@ -111,6 +118,7 @@ protected void writeNodesTo(StreamOutput out, List<ClusterStatsNodeResponse> nod

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field("cluster_uuid", getClusterUUID());
builder.field("timestamp", getTimestamp());
if (status != null) {
builder.field("status", status.name().toLowerCase(Locale.ROOT));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ protected ClusterStatsResponse newResponse(ClusterStatsRequest request,
List<ClusterStatsNodeResponse> responses, List<FailedNodeException> failures) {
return new ClusterStatsResponse(
System.currentTimeMillis(),
clusterService.state().metaData().clusterUUID(),
clusterService.getClusterName(),
responses,
failures);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ public void testToXContent() throws IOException {
when(mockNodeResponse.shardsStats()).thenReturn(new ShardStats[]{mockShardStats});

final ClusterStatsResponse clusterStats = new ClusterStatsResponse(1451606400000L,
"_cluster",
clusterName,
singletonList(mockNodeResponse),
emptyList());
Expand Down Expand Up @@ -353,6 +354,7 @@ public void testToXContent() throws IOException {
+ (needToEnableTLS ? ",\"cluster_needs_tls\":true" : "")
+ "},"
+ "\"cluster_stats\":{"
+ "\"cluster_uuid\":\"_cluster\","
+ "\"timestamp\":1451606400000,"
+ "\"status\":\"red\","
+ "\"indices\":{"
Expand Down

0 comments on commit 60583f2

Please sign in to comment.