Skip to content

Commit 0a83968

Browse files
authored
Add cluster UUID to Cluster Stats API response (elastic#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
1 parent eb3accb commit 0a83968

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

docs/reference/cluster/stats.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Will return, for example:
2222
"successful" : 1,
2323
"failed" : 0
2424
},
25+
"cluster_uuid": "YjAvIhsCQ9CbjWZb2qJw3Q",
2526
"cluster_name": "elasticsearch",
2627
"timestamp": 1459427693515,
2728
"status": "green",

rest-api-spec/src/main/resources/rest-api-spec/test/cluster.stats/10_basic.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,40 @@
2929
- is_true: nodes.fs
3030
- is_true: nodes.plugins
3131
- is_true: nodes.network_types
32+
33+
---
34+
"get cluster stats returns cluster_uuid at the top level":
35+
- skip:
36+
version: " - 6.99.99"
37+
reason: "cluster stats including cluster_uuid at the top level is new in v6.5.0 and higher"
38+
39+
- do:
40+
cluster.stats: {}
41+
42+
- is_true: cluster_uuid
43+
- is_true: timestamp
44+
- is_true: cluster_name
45+
- match: {status: green}
46+
- gte: { indices.count: 0}
47+
- is_true: indices.docs
48+
- is_true: indices.store
49+
- is_true: indices.fielddata
50+
- is_true: indices.query_cache
51+
- is_true: indices.completion
52+
- is_true: indices.segments
53+
- gte: { nodes.count.total: 1}
54+
- gte: { nodes.count.master: 1}
55+
- gte: { nodes.count.data: 1}
56+
- gte: { nodes.count.ingest: 0}
57+
- gte: { nodes.count.coordinating_only: 0}
58+
- is_true: nodes.os
59+
- is_true: nodes.os.mem.total_in_bytes
60+
- is_true: nodes.os.mem.free_in_bytes
61+
- is_true: nodes.os.mem.used_in_bytes
62+
- gte: { nodes.os.mem.free_percent: 0 }
63+
- gte: { nodes.os.mem.used_percent: 0 }
64+
- is_true: nodes.process
65+
- is_true: nodes.jvm
66+
- is_true: nodes.fs
67+
- is_true: nodes.plugins
68+
- is_true: nodes.network_types

server/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsResponse.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,18 @@ public class ClusterStatsResponse extends BaseNodesResponse<ClusterStatsNodeResp
4040
ClusterStatsIndices indicesStats;
4141
ClusterHealthStatus status;
4242
long timestamp;
43+
String clusterUUID;
4344

4445
ClusterStatsResponse() {
4546
}
4647

4748
public ClusterStatsResponse(long timestamp,
49+
String clusterUUID,
4850
ClusterName clusterName,
4951
List<ClusterStatsNodeResponse> nodes,
5052
List<FailedNodeException> failures) {
5153
super(clusterName, nodes, failures);
54+
this.clusterUUID = clusterUUID;
5255
this.timestamp = timestamp;
5356
nodesStats = new ClusterStatsNodes(nodes);
5457
indicesStats = new ClusterStatsIndices(nodes);
@@ -61,6 +64,10 @@ public ClusterStatsResponse(long timestamp,
6164
}
6265
}
6366

67+
public String getClusterUUID() {
68+
return this.clusterUUID;
69+
}
70+
6471
public long getTimestamp() {
6572
return this.timestamp;
6673
}
@@ -111,6 +118,7 @@ protected void writeNodesTo(StreamOutput out, List<ClusterStatsNodeResponse> nod
111118

112119
@Override
113120
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
121+
builder.field("cluster_uuid", getClusterUUID());
114122
builder.field("timestamp", getTimestamp());
115123
if (status != null) {
116124
builder.field("status", status.name().toLowerCase(Locale.ROOT));

server/src/main/java/org/elasticsearch/action/admin/cluster/stats/TransportClusterStatsAction.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ protected ClusterStatsResponse newResponse(ClusterStatsRequest request,
7474
List<ClusterStatsNodeResponse> responses, List<FailedNodeException> failures) {
7575
return new ClusterStatsResponse(
7676
System.currentTimeMillis(),
77+
clusterService.state().metaData().clusterUUID(),
7778
clusterService.getClusterName(),
7879
responses,
7980
failures);

x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ public void testToXContent() throws IOException {
302302
when(mockNodeResponse.shardsStats()).thenReturn(new ShardStats[]{mockShardStats});
303303

304304
final ClusterStatsResponse clusterStats = new ClusterStatsResponse(1451606400000L,
305+
"_cluster",
305306
clusterName,
306307
singletonList(mockNodeResponse),
307308
emptyList());
@@ -353,6 +354,7 @@ public void testToXContent() throws IOException {
353354
+ (needToEnableTLS ? ",\"cluster_needs_tls\":true" : "")
354355
+ "},"
355356
+ "\"cluster_stats\":{"
357+
+ "\"cluster_uuid\":\"_cluster\","
356358
+ "\"timestamp\":1451606400000,"
357359
+ "\"status\":\"red\","
358360
+ "\"indices\":{"

0 commit comments

Comments
 (0)