From 0a83968650d93144cabec755baf5ec1d93754aba Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 2 Aug 2018 17:14:19 -0700 Subject: [PATCH] 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 --- docs/reference/cluster/stats.asciidoc | 1 + .../test/cluster.stats/10_basic.yml | 37 +++++++++++++++++++ .../cluster/stats/ClusterStatsResponse.java | 8 ++++ .../stats/TransportClusterStatsAction.java | 1 + .../ClusterStatsMonitoringDocTests.java | 2 + 5 files changed, 49 insertions(+) diff --git a/docs/reference/cluster/stats.asciidoc b/docs/reference/cluster/stats.asciidoc index 191da2660d6..3de85041871 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 29f048068b4..0ff5708b93e 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 469106c9a61..372704afaf6 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 class ClusterStatsResponse extends BaseNodesResponse 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 098f4190b0e..c7ddb3c4d24 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 class ClusterStatsMonitoringDocTests extends BaseMonitoringDocTestCase