diff --git a/docs/reference/cluster/stats.asciidoc b/docs/reference/cluster/stats.asciidoc index 191da2660d668..3de850418719d 100644 --- a/docs/reference/cluster/stats.asciidoc +++ b/docs/reference/cluster/stats.asciidoc @@ -22,6 +22,7 @@ Will return, for example: "successful" : 1, "failed" : 0 }, + "cluster_uuid": "YjAvIhsCQ9CbjWZb2qJw3Q", "cluster_name": "elasticsearch", "timestamp": 1459427693515, "status": "green", diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/cluster.stats/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/cluster.stats/10_basic.yml index 29f048068b4a0..0ff5708b93efe 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/cluster.stats/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/cluster.stats/10_basic.yml @@ -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 diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsResponse.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsResponse.java index 469106c9a6102..372704afaf666 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsResponse.java @@ -40,15 +40,18 @@ public class ClusterStatsResponse extends BaseNodesResponse nodes, List failures) { super(clusterName, nodes, failures); + this.clusterUUID = clusterUUID; this.timestamp = timestamp; nodesStats = new ClusterStatsNodes(nodes); indicesStats = new ClusterStatsIndices(nodes); @@ -61,6 +64,10 @@ public ClusterStatsResponse(long timestamp, } } + public String getClusterUUID() { + return this.clusterUUID; + } + public long getTimestamp() { return this.timestamp; } @@ -111,6 +118,7 @@ protected void writeNodesTo(StreamOutput out, List 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)); diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/stats/TransportClusterStatsAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/stats/TransportClusterStatsAction.java index 00d344831882d..5dca19716d774 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/stats/TransportClusterStatsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/stats/TransportClusterStatsAction.java @@ -77,6 +77,7 @@ protected ClusterStatsResponse newResponse(ClusterStatsRequest request, List responses, List failures) { return new ClusterStatsResponse( System.currentTimeMillis(), + clusterService.state().metaData().clusterUUID(), clusterService.getClusterName(), responses, failures); diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java index 098f4190b0e88..c7ddb3c4d2427 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java @@ -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()); @@ -353,6 +354,7 @@ public void testToXContent() throws IOException { + (needToEnableTLS ? ",\"cluster_needs_tls\":true" : "") + "}," + "\"cluster_stats\":{" + + "\"cluster_uuid\":\"_cluster\"," + "\"timestamp\":1451606400000," + "\"status\":\"red\"," + "\"indices\":{"