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

Add cluster UUID to Cluster Stats API response #32206

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -74,6 +74,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