Add cluster UUID to Cluster Stats API response (#32206)

* 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
This commit is contained in:
Shaunak Kashyap 2018-08-02 17:14:19 -07:00 committed by GitHub
parent eb3accb721
commit 0a83968650
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 0 deletions

View File

@ -22,6 +22,7 @@ Will return, for example:
"successful" : 1,
"failed" : 0
},
"cluster_uuid": "YjAvIhsCQ9CbjWZb2qJw3Q",
"cluster_name": "elasticsearch",
"timestamp": 1459427693515,
"status": "green",

View File

@ -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

View File

@ -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);
@ -61,6 +64,10 @@ public class ClusterStatsResponse extends BaseNodesResponse<ClusterStatsNodeResp
}
}
public String getClusterUUID() {
return this.clusterUUID;
}
public long getTimestamp() {
return this.timestamp;
}
@ -111,6 +118,7 @@ public class ClusterStatsResponse extends BaseNodesResponse<ClusterStatsNodeResp
@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));

View File

@ -74,6 +74,7 @@ public class TransportClusterStatsAction extends TransportNodesAction<ClusterSta
List<ClusterStatsNodeResponse> responses, List<FailedNodeException> failures) {
return new ClusterStatsResponse(
System.currentTimeMillis(),
clusterService.state().metaData().clusterUUID(),
clusterService.getClusterName(),
responses,
failures);

View File

@ -302,6 +302,7 @@ public class ClusterStatsMonitoringDocTests extends BaseMonitoringDocTestCase<Cl
when(mockNodeResponse.shardsStats()).thenReturn(new ShardStats[]{mockShardStats});
final ClusterStatsResponse clusterStats = new ClusterStatsResponse(1451606400000L,
"_cluster",
clusterName,
singletonList(mockNodeResponse),
emptyList());
@ -353,6 +354,7 @@ public class ClusterStatsMonitoringDocTests extends BaseMonitoringDocTestCase<Cl
+ (needToEnableTLS ? ",\"cluster_needs_tls\":true" : "")
+ "},"
+ "\"cluster_stats\":{"
+ "\"cluster_uuid\":\"_cluster\","
+ "\"timestamp\":1451606400000,"
+ "\"status\":\"red\","
+ "\"indices\":{"