From 904e02869068e31d7aab747318b610f6973bcd3f Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 19 Jul 2018 10:04:24 -0700 Subject: [PATCH 1/8] Make cluster stats response contain cluster UUID --- .../action/admin/cluster/stats/ClusterStatsResponse.java | 8 ++++++++ .../admin/cluster/stats/TransportClusterStatsAction.java | 1 + 2 files changed, 9 insertions(+) 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 227b1359d4f09..66b258670c128 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 @@ -74,6 +74,7 @@ protected ClusterStatsResponse newResponse(ClusterStatsRequest request, List responses, List failures) { return new ClusterStatsResponse( System.currentTimeMillis(), + clusterService.state().metaData().clusterUUID(), clusterService.getClusterName(), responses, failures); From 28859e76de86172504aef545c86ccef38223ee09 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 19 Jul 2018 10:09:25 -0700 Subject: [PATCH 2/8] Updating constructor usage in Monitoring tests --- .../collector/cluster/ClusterStatsMonitoringDocTests.java | 1 + 1 file changed, 1 insertion(+) 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..17176087cae0d 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, + "Z7R4gXE2RvyLDG0ROIP_8g", clusterName, singletonList(mockNodeResponse), emptyList()); From bd80a8872caf6cb7a134bef577f2e6c13b7f7130 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 20 Jul 2018 05:56:30 -0700 Subject: [PATCH 3/8] Adding cluster_uuid field to Cluster Stats API reference doc --- docs/reference/cluster/stats.asciidoc | 1 + 1 file changed, 1 insertion(+) 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", From e4b5e11bed08e926a198394ef603dc95fcb65e2a Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 26 Jul 2018 15:11:45 -0700 Subject: [PATCH 4/8] Adding rest api spec test for expecting cluster_uuid in cluster stats response --- .../test/cluster.stats/10_basic.yml | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) 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..393f9afafac52 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 \ No newline at end of file From d454c97b00379f8be1c9681fc4addf400eeda1f6 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Mon, 30 Jul 2018 15:19:42 -0700 Subject: [PATCH 5/8] Adding missing newline --- .../resources/rest-api-spec/test/cluster.stats/10_basic.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 393f9afafac52..cce26a5937818 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 @@ -65,4 +65,4 @@ - is_true: nodes.jvm - is_true: nodes.fs - is_true: nodes.plugins - - is_true: nodes.network_types \ No newline at end of file + - is_true: nodes.network_types From bb2705148b7df08da0a99f3ae88f86aba52c27f2 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 31 Jul 2018 10:18:26 -0700 Subject: [PATCH 6/8] Indenting do section properly --- .../resources/rest-api-spec/test/cluster.stats/10_basic.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 cce26a5937818..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 @@ -37,7 +37,7 @@ reason: "cluster stats including cluster_uuid at the top level is new in v6.5.0 and higher" - do: - cluster.stats: {} + cluster.stats: {} - is_true: cluster_uuid - is_true: timestamp From f421640f060b4bda8415ee76854452226aec680a Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 31 Jul 2018 12:12:05 -0700 Subject: [PATCH 7/8] Missed a spot! --- .../collector/cluster/ClusterStatsMonitoringDocTests.java | 1 + 1 file changed, 1 insertion(+) 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 17176087cae0d..c5e3fe3daeee3 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 @@ -354,6 +354,7 @@ public void testToXContent() throws IOException { + (needToEnableTLS ? ",\"cluster_needs_tls\":true" : "") + "}," + "\"cluster_stats\":{" + + "\"cluster_uuid\":\"_cluster\"," + "\"timestamp\":1451606400000," + "\"status\":\"red\"," + "\"indices\":{" From 30a9cc3672dcccd03736e6762c3ae92d32fe924a Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 31 Jul 2018 13:36:02 -0700 Subject: [PATCH 8/8] Fixing the test cluster ID --- .../collector/cluster/ClusterStatsMonitoringDocTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c5e3fe3daeee3..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,7 +302,7 @@ public void testToXContent() throws IOException { when(mockNodeResponse.shardsStats()).thenReturn(new ShardStats[]{mockShardStats}); final ClusterStatsResponse clusterStats = new ClusterStatsResponse(1451606400000L, - "Z7R4gXE2RvyLDG0ROIP_8g", + "_cluster", clusterName, singletonList(mockNodeResponse), emptyList());