From 958e9d1b7800fc9fdff25048f49e69edcf3d269f Mon Sep 17 00:00:00 2001 From: William Brafford Date: Wed, 1 Apr 2020 17:03:04 -0400 Subject: [PATCH] Refactor nodes stats request builders to match requests (#54363) (#54604) * Refactor nodes stats request builders to match requests (#54363) * Remove hard-coded setters from NodesInfoRequestBuilder * Remove hard-coded setters from NodesStatsRequest * Use static imports to reduce clutter * Remove uses of old info APIs --- .../ingest/common/IngestRestartIT.java | 5 +- ...Netty4TransportMultiPortIntegrationIT.java | 3 +- .../node/info/NodesInfoRequestBuilder.java | 91 ++---------- .../node/stats/NodesStatsRequestBuilder.java | 129 +++--------------- .../admin/cluster/stats/ClusterStatsIT.java | 3 +- .../cluster/coordination/ZenDiscoveryIT.java | 3 +- .../cluster/settings/SettingsFilteringIT.java | 3 +- .../index/shard/IndexShardIT.java | 3 +- .../RemoveCorruptedShardDataCommandIT.java | 3 +- .../index/store/CorruptedFileIT.java | 9 +- .../breaker/CircuitBreakerServiceIT.java | 22 ++- .../RandomExceptionCircuitBreakerIT.java | 16 ++- .../nodesinfo/SimpleNodesInfoIT.java | 3 +- .../test/ExternalTestCluster.java | 13 +- .../monitoring/integration/MonitoringIT.java | 5 +- .../test/SecurityIntegTestCase.java | 3 +- .../test/SecuritySingleNodeTestCase.java | 3 +- .../transport/ssl/EllipticCurveSSLTests.java | 3 +- .../bench/WatcherScheduleEngineBenchmark.java | 8 +- .../example/realm/CustomRealmIT.java | 3 +- .../SmokeTestMonitoringWithSecurityIT.java | 3 +- 21 files changed, 115 insertions(+), 219 deletions(-) diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/IngestRestartIT.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/IngestRestartIT.java index 1b5cc65a5bc..316a1436fd8 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/IngestRestartIT.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/IngestRestartIT.java @@ -39,6 +39,7 @@ import java.util.Map; import java.util.function.Consumer; import java.util.function.Function; +import static org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest.Metric.INGEST; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo; @@ -99,7 +100,9 @@ public class IngestRestartIT extends ESIntegTestCase { ); assertTrue(e.getMessage().contains("this script always fails")); - NodesStatsResponse r = client().admin().cluster().prepareNodesStats(internalCluster().getNodeNames()).setIngest(true).get(); + NodesStatsResponse r = client().admin().cluster().prepareNodesStats(internalCluster().getNodeNames()) + .addMetric(INGEST.metricName()) + .get(); int nodeCount = r.getNodes().size(); for (int k = 0; k < nodeCount; k++) { List stats = r.getNodes().get(k).getIngestStats().getProcessorStats().get(pipelineId); diff --git a/modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/Netty4TransportMultiPortIntegrationIT.java b/modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/Netty4TransportMultiPortIntegrationIT.java index 999c6ea0ded..ef899a5a3fe 100644 --- a/modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/Netty4TransportMultiPortIntegrationIT.java +++ b/modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/Netty4TransportMultiPortIntegrationIT.java @@ -40,6 +40,7 @@ import java.net.InetAddress; import java.util.Arrays; import java.util.Locale; +import static org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest.Metric.TRANSPORT; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.hasKey; @@ -88,7 +89,7 @@ public class Netty4TransportMultiPortIntegrationIT extends ESNetty4IntegTestCase @Network public void testThatInfosAreExposed() throws Exception { - NodesInfoResponse response = client().admin().cluster().prepareNodesInfo().clear().setTransport(true).get(); + NodesInfoResponse response = client().admin().cluster().prepareNodesInfo().clear().addMetric(TRANSPORT.metricName()).get(); for (NodeInfo nodeInfo : response.getNodes()) { assertThat(nodeInfo.getTransport().getProfileAddresses().keySet(), hasSize(1)); assertThat(nodeInfo.getTransport().getProfileAddresses(), hasKey("client1")); diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequestBuilder.java index 97b55b7fd49..a73c0e82b2d 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequestBuilder.java @@ -22,7 +22,6 @@ package org.elasticsearch.action.admin.cluster.node.info; import org.elasticsearch.action.support.nodes.NodesOperationRequestBuilder; import org.elasticsearch.client.ElasticsearchClient; -// TODO: This class's interface should match that of NodesInfoRequest public class NodesInfoRequestBuilder extends NodesOperationRequestBuilder { public NodesInfoRequestBuilder(ElasticsearchClient client, NodesInfoAction action) { @@ -46,90 +45,24 @@ public class NodesInfoRequestBuilder extends NodesOperationRequestBuilder request node discovery stats"); - NodesStatsResponse statsResponse = client().admin().cluster().prepareNodesStats().clear().setDiscovery(true).get(); + NodesStatsResponse statsResponse = client().admin().cluster().prepareNodesStats().clear().addMetric(DISCOVERY.metricName()).get(); assertThat(statsResponse.getNodes().size(), equalTo(1)); DiscoveryStats stats = statsResponse.getNodes().get(0).getDiscoveryStats(); diff --git a/server/src/test/java/org/elasticsearch/cluster/settings/SettingsFilteringIT.java b/server/src/test/java/org/elasticsearch/cluster/settings/SettingsFilteringIT.java index 08a16b89eca..dab959122f2 100644 --- a/server/src/test/java/org/elasticsearch/cluster/settings/SettingsFilteringIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/settings/SettingsFilteringIT.java @@ -33,6 +33,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; +import static org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest.Metric.SETTINGS; import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; @@ -89,7 +90,7 @@ public class SettingsFilteringIT extends ESIntegTestCase { } public void testNodeInfoIsFiltered() { - NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().clear().setSettings(true).get(); + NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().clear().addMetric(SETTINGS.metricName()).get(); for(NodeInfo info : nodeInfos.getNodes()) { Settings settings = info.getSettings(); assertNotNull(settings); diff --git a/server/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java b/server/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java index 8476a1d9769..08a67e9a7bc 100644 --- a/server/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java +++ b/server/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java @@ -110,6 +110,7 @@ import java.util.stream.Stream; import static com.carrotsearch.randomizedtesting.RandomizedTest.randomAsciiLettersOfLength; import static java.util.Collections.emptyMap; import static java.util.Collections.emptySet; +import static org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest.Metric.BREAKER; import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.NONE; import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS; @@ -583,7 +584,7 @@ public class IndexShardIT extends ESSingleNodeTestCase { CircuitBreaker acctBreaker = breakerService.getBreaker(CircuitBreaker.ACCOUNTING); long usedMem = acctBreaker.getUsed(); assertThat(usedMem, greaterThan(0L)); - NodesStatsResponse response = client().admin().cluster().prepareNodesStats().setIndices(true).setBreaker(true).get(); + NodesStatsResponse response = client().admin().cluster().prepareNodesStats().setIndices(true).addMetric(BREAKER.metricName()).get(); NodeStats stats = response.getNodes().get(0); assertNotNull(stats); SegmentsStats segmentsStats = stats.getIndices().getSegments(); diff --git a/server/src/test/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandIT.java b/server/src/test/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandIT.java index ba4dcdee484..64175fdd374 100644 --- a/server/src/test/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandIT.java +++ b/server/src/test/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandIT.java @@ -89,6 +89,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; +import static org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest.Metric.FS; import static org.elasticsearch.common.util.CollectionUtils.iterableAsArrayList; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; @@ -599,7 +600,7 @@ public class RemoveCorruptedShardDataCommandIT extends ESIntegTestCase { } public static Path getPathToShardData(String nodeId, ShardId shardId, String shardPathSubdirectory) { - final NodesStatsResponse nodeStatsResponse = client().admin().cluster().prepareNodesStats(nodeId).setFs(true).get(); + final NodesStatsResponse nodeStatsResponse = client().admin().cluster().prepareNodesStats(nodeId).addMetric(FS.metricName()).get(); final Set paths = StreamSupport.stream(nodeStatsResponse.getNodes().get(0).getFs().spliterator(), false) .map(nodePath -> PathUtils.get(nodePath.getPath()) .resolve(NodeEnvironment.INDICES_FOLDER) diff --git a/server/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java b/server/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java index 63de40b6824..cdd78c72fa1 100644 --- a/server/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java +++ b/server/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java @@ -96,6 +96,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; +import static org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest.Metric.FS; import static org.elasticsearch.common.util.CollectionUtils.iterableAsArrayList; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAllSuccessful; @@ -649,7 +650,9 @@ public class CorruptedFileIT extends ESIntegTestCase { assertTrue(shardRouting.primary()); assertTrue(shardRouting.assignedToNode()); String nodeId = shardRouting.currentNodeId(); - NodesStatsResponse nodeStatses = client().admin().cluster().prepareNodesStats(nodeId).setFs(true).get(); + NodesStatsResponse nodeStatses = client().admin().cluster().prepareNodesStats(nodeId) + .addMetric(FS.metricName()) + .get(); Set files = new TreeSet<>(); // treeset makes sure iteration order is deterministic for (FsInfo.Path info : nodeStatses.getNodes().get(0).getFs()) { String path = info.getPath(); @@ -690,7 +693,9 @@ public class CorruptedFileIT extends ESIntegTestCase { } public List listShardFiles(ShardRouting routing) throws IOException { - NodesStatsResponse nodeStatses = client().admin().cluster().prepareNodesStats(routing.currentNodeId()).setFs(true).get(); + NodesStatsResponse nodeStatses = client().admin().cluster().prepareNodesStats(routing.currentNodeId()) + .addMetric(FS.metricName()) + .get(); ClusterState state = client().admin().cluster().prepareState().get().getState(); final Index test = state.metadata().index("test").getIndex(); assertThat(routing.toString(), nodeStatses.getNodes().size(), equalTo(1)); diff --git a/server/src/test/java/org/elasticsearch/indices/memory/breaker/CircuitBreakerServiceIT.java b/server/src/test/java/org/elasticsearch/indices/memory/breaker/CircuitBreakerServiceIT.java index 68a19b08e77..01de6cbd2eb 100644 --- a/server/src/test/java/org/elasticsearch/indices/memory/breaker/CircuitBreakerServiceIT.java +++ b/server/src/test/java/org/elasticsearch/indices/memory/breaker/CircuitBreakerServiceIT.java @@ -58,6 +58,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; import java.util.stream.Stream; +import static org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest.Metric.BREAKER; import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.elasticsearch.search.aggregations.AggregationBuilders.cardinality; @@ -108,7 +109,9 @@ public class CircuitBreakerServiceIT extends ESIntegTestCase { /** Returns true if any of the nodes used a noop breaker */ private boolean noopBreakerUsed() { - NodesStatsResponse stats = client().admin().cluster().prepareNodesStats().setBreaker(true).get(); + NodesStatsResponse stats = client().admin().cluster().prepareNodesStats() + .addMetric(BREAKER.metricName()) + .get(); for (NodeStats nodeStats : stats.getNodes()) { if (nodeStats.getBreaker().getStats(CircuitBreaker.REQUEST).getLimit() == NoopCircuitBreaker.LIMIT) { return true; @@ -159,7 +162,9 @@ public class CircuitBreakerServiceIT extends ESIntegTestCase { errMsg = "which is larger than the limit of [100/100b]"; assertFailures(searchRequest, RestStatus.INTERNAL_SERVER_ERROR, containsString(errMsg)); - NodesStatsResponse stats = client.admin().cluster().prepareNodesStats().setBreaker(true).get(); + NodesStatsResponse stats = client.admin().cluster().prepareNodesStats() + .addMetric(BREAKER.metricName()) + .get(); int breaks = 0; for (NodeStats stat : stats.getNodes()) { CircuitBreakerStats breakerStats = stat.getBreaker().getStats(CircuitBreaker.FIELDDATA); @@ -211,7 +216,9 @@ public class CircuitBreakerServiceIT extends ESIntegTestCase { errMsg = "which is larger than the limit of [100/100b]"; assertFailures(searchRequest, RestStatus.INTERNAL_SERVER_ERROR, containsString(errMsg)); - NodesStatsResponse stats = client.admin().cluster().prepareNodesStats().setBreaker(true).get(); + NodesStatsResponse stats = client.admin().cluster().prepareNodesStats() + .addMetric(BREAKER.metricName()) + .get(); int breaks = 0; for (NodeStats stat : stats.getNodes()) { CircuitBreakerStats breakerStats = stat.getBreaker().getStats(CircuitBreaker.FIELDDATA); @@ -298,8 +305,9 @@ public class CircuitBreakerServiceIT extends ESIntegTestCase { public void clearFieldData() throws Exception { client().admin().indices().prepareClearCache().setFieldDataCache(true).execute().actionGet(); assertBusy(() -> { - NodesStatsResponse resp = client().admin().cluster().prepareNodesStats() - .clear().setBreaker(true).get(new TimeValue(15, TimeUnit.SECONDS)); + NodesStatsResponse resp = client().admin().cluster().prepareNodesStats().clear() + .addMetric(BREAKER.metricName()) + .get(new TimeValue(15, TimeUnit.SECONDS)); for (NodeStats nStats : resp.getNodes()) { assertThat("fielddata breaker never reset back to 0", nStats.getBreaker().getStats(CircuitBreaker.FIELDDATA).getEstimated(), @@ -328,7 +336,9 @@ public class CircuitBreakerServiceIT extends ESIntegTestCase { } } - NodesStatsResponse stats = client().admin().cluster().prepareNodesStats().clear().setBreaker(true).get(); + NodesStatsResponse stats = client().admin().cluster().prepareNodesStats().clear() + .addMetric(BREAKER.metricName()) + .get(); int breaks = 0; for (NodeStats stat : stats.getNodes()) { CircuitBreakerStats breakerStats = stat.getBreaker().getStats(breakerName); diff --git a/server/src/test/java/org/elasticsearch/indices/memory/breaker/RandomExceptionCircuitBreakerIT.java b/server/src/test/java/org/elasticsearch/indices/memory/breaker/RandomExceptionCircuitBreakerIT.java index b86b622705e..45313a91261 100644 --- a/server/src/test/java/org/elasticsearch/indices/memory/breaker/RandomExceptionCircuitBreakerIT.java +++ b/server/src/test/java/org/elasticsearch/indices/memory/breaker/RandomExceptionCircuitBreakerIT.java @@ -55,6 +55,7 @@ import java.util.List; import java.util.Random; import java.util.concurrent.ExecutionException; +import static org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest.Metric.BREAKER; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAllSuccessful; import static org.hamcrest.Matchers.equalTo; @@ -73,8 +74,9 @@ public class RandomExceptionCircuitBreakerIT extends ESIntegTestCase { } public void testBreakerWithRandomExceptions() throws IOException, InterruptedException, ExecutionException { - for (NodeStats node : client().admin().cluster().prepareNodesStats() - .clear().setBreaker(true).execute().actionGet().getNodes()) { + for (NodeStats node : client().admin().cluster().prepareNodesStats().clear() + .addMetric(BREAKER.metricName()) + .execute().actionGet().getNodes()) { assertThat("Breaker is not set to 0", node.getBreaker().getStats(CircuitBreaker.FIELDDATA).getEstimated(), equalTo(0L)); } @@ -156,8 +158,9 @@ public class RandomExceptionCircuitBreakerIT extends ESIntegTestCase { refreshFailed, refreshResponse.getFailedShards(), refreshResponse.getShardFailures().length, refreshResponse.getSuccessfulShards(), refreshResponse.getTotalShards()); final int numSearches = scaledRandomIntBetween(50, 150); - NodesStatsResponse resp = client().admin().cluster().prepareNodesStats() - .clear().setBreaker(true).execute().actionGet(); + NodesStatsResponse resp = client().admin().cluster().prepareNodesStats().clear() + .addMetric(BREAKER.metricName()) + .execute().actionGet(); for (NodeStats stats : resp.getNodes()) { assertThat("Breaker is set to 0", stats.getBreaker().getStats(CircuitBreaker.FIELDDATA).getEstimated(), equalTo(0L)); } @@ -192,8 +195,9 @@ public class RandomExceptionCircuitBreakerIT extends ESIntegTestCase { // Clean up the cache, ensuring that entries' listeners have been called fdCache.getCache().refresh(); } - NodesStatsResponse nodeStats = client().admin().cluster().prepareNodesStats() - .clear().setBreaker(true).execute().actionGet(); + NodesStatsResponse nodeStats = client().admin().cluster().prepareNodesStats().clear() + .addMetric(BREAKER.metricName()) + .execute().actionGet(); for (NodeStats stats : nodeStats.getNodes()) { assertThat("Breaker reset to 0 last search success: " + success + " mapping: " + mapping, stats.getBreaker().getStats(CircuitBreaker.FIELDDATA).getEstimated(), equalTo(0L)); diff --git a/server/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoIT.java b/server/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoIT.java index 615bf543127..a0a6c1c7de1 100644 --- a/server/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoIT.java +++ b/server/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoIT.java @@ -30,6 +30,7 @@ import org.elasticsearch.test.ESIntegTestCase.Scope; import java.util.List; +import static org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest.Metric.INDICES; import static org.elasticsearch.client.Requests.nodesInfoRequest; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; @@ -101,7 +102,7 @@ public class SimpleNodesInfoIT extends ESIntegTestCase { assertThat(response.getNodesMap().get(server2NodeId).getTotalIndexingBuffer().getBytes(), greaterThan(0L)); // again, using only the indices flag - response = client().admin().cluster().prepareNodesInfo().clear().setIndices(true).execute().actionGet(); + response = client().admin().cluster().prepareNodesInfo().clear().addMetric(INDICES.metricName()).execute().actionGet(); assertThat(response.getNodes().size(), is(2)); assertThat(response.getNodesMap().get(server1NodeId), notNullValue()); assertNotNull(response.getNodesMap().get(server1NodeId).getTotalIndexingBuffer()); diff --git a/test/framework/src/main/java/org/elasticsearch/test/ExternalTestCluster.java b/test/framework/src/main/java/org/elasticsearch/test/ExternalTestCluster.java index c45ad85dbdb..868ed7511c0 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ExternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ExternalTestCluster.java @@ -46,6 +46,9 @@ import java.util.Collection; import java.util.Collections; import java.util.concurrent.atomic.AtomicInteger; +import static org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest.Metric.HTTP; +import static org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest.Metric.SETTINGS; +import static org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest.Metric.BREAKER; import static org.elasticsearch.test.ESTestCase.getTestTransportType; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; @@ -94,7 +97,9 @@ public final class ExternalTestCluster extends TestCluster { MockTransportClient client = new MockTransportClient(clientSettings, pluginClasses); try { client.addTransportAddresses(transportAddresses); - NodesInfoResponse nodeInfos = client.admin().cluster().prepareNodesInfo().clear().setSettings(true).setHttp(true).get(); + NodesInfoResponse nodeInfos = client.admin().cluster().prepareNodesInfo().clear() + .addMetrics(SETTINGS.metricName(), HTTP.metricName()) + .get(); httpAddresses = new InetSocketAddress[nodeInfos.getNodes().size()]; this.clusterName = nodeInfos.getClusterName().value(); int dataNodes = 0; @@ -158,8 +163,10 @@ public final class ExternalTestCluster extends TestCluster { @Override public void ensureEstimatedStats() { if (size() > 0) { - NodesStatsResponse nodeStats = client().admin().cluster().prepareNodesStats() - .clear().setBreaker(true).setIndices(true).execute().actionGet(); + NodesStatsResponse nodeStats = client().admin().cluster().prepareNodesStats().clear() + .setIndices(true) + .addMetric(BREAKER.metricName()) + .execute().actionGet(); for (NodeStats stats : nodeStats.getNodes()) { assertThat("Fielddata breaker not reset to 0 on node: " + stats.getNode(), stats.getBreaker().getStats(CircuitBreaker.FIELDDATA).getEstimated(), equalTo(0L)); diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/integration/MonitoringIT.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/integration/MonitoringIT.java index 7a631d6f488..cb031e853ec 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/integration/MonitoringIT.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/integration/MonitoringIT.java @@ -67,6 +67,7 @@ import java.util.Optional; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; +import static org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest.Metric.THREAD_POOL; import static org.elasticsearch.common.xcontent.ToXContent.EMPTY_PARAMS; import static org.elasticsearch.common.xcontent.support.XContentMapValues.extractValue; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; @@ -631,7 +632,9 @@ public class MonitoringIT extends ESSingleNodeTestCase { assertBusy(() -> { try { // now wait until Monitoring has actually stopped - final NodesStatsResponse response = client().admin().cluster().prepareNodesStats().clear().setThreadPool(true).get(); + final NodesStatsResponse response = client().admin().cluster().prepareNodesStats().clear() + .addMetric(THREAD_POOL.metricName()) + .get(); for (final NodeStats nodeStats : response.getNodes()) { boolean foundBulkThreads = false; diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/test/SecurityIntegTestCase.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/test/SecurityIntegTestCase.java index b69f940fde3..1294c3480eb 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/test/SecurityIntegTestCase.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/test/SecurityIntegTestCase.java @@ -64,6 +64,7 @@ import java.util.concurrent.TimeUnit; import java.util.function.Function; import java.util.stream.Collectors; +import static org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest.Metric.PLUGINS; import static org.elasticsearch.test.SecuritySettingsSourceField.TEST_PASSWORD_SECURE_STRING; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout; @@ -225,7 +226,7 @@ public abstract class SecurityIntegTestCase extends ESIntegTestCase { } protected void doAssertXPackIsInstalled() { - NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().clear().setPlugins(true).get(); + NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().clear().addMetric(PLUGINS.metricName()).get(); for (NodeInfo nodeInfo : nodeInfos.getNodes()) { // TODO: disable this assertion for now, due to random runs with mock plugins. perhaps run without mock plugins? // assertThat(nodeInfo.getPlugins().getInfos(), hasSize(2)); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/test/SecuritySingleNodeTestCase.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/test/SecuritySingleNodeTestCase.java index ec612a99054..e369fd06dd4 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/test/SecuritySingleNodeTestCase.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/test/SecuritySingleNodeTestCase.java @@ -39,6 +39,7 @@ import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import static org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest.Metric.PLUGINS; import static org.elasticsearch.test.SecuritySettingsSourceField.TEST_PASSWORD_SECURE_STRING; import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue; import static org.hamcrest.core.IsCollectionContaining.hasItem; @@ -149,7 +150,7 @@ public abstract class SecuritySingleNodeTestCase extends ESSingleNodeTestCase { } private void doAssertXPackIsInstalled() { - NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().clear().setPlugins(true).get(); + NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().clear().addMetric(PLUGINS.metricName()).get(); for (NodeInfo nodeInfo : nodeInfos.getNodes()) { // TODO: disable this assertion for now, due to random runs with mock plugins. perhaps run without mock plugins? // assertThat(nodeInfo.getPlugins().getInfos(), hasSize(2)); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/ssl/EllipticCurveSSLTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/ssl/EllipticCurveSSLTests.java index c3bb88f3642..d4a5cf27401 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/ssl/EllipticCurveSSLTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/ssl/EllipticCurveSSLTests.java @@ -33,6 +33,7 @@ import java.util.Collections; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference; +import static org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest.Metric.TRANSPORT; import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; @@ -86,7 +87,7 @@ public class EllipticCurveSSLTests extends SecurityIntegTestCase { new TrustManager[]{CertParsingUtils.trustManager(CertParsingUtils.readCertificates(Collections.singletonList(certPath)))}, new SecureRandom()); SSLSocketFactory socketFactory = sslContext.getSocketFactory(); - NodesInfoResponse response = client().admin().cluster().prepareNodesInfo().setTransport(true).get(); + NodesInfoResponse response = client().admin().cluster().prepareNodesInfo().addMetric(TRANSPORT.metricName()).get(); TransportAddress address = randomFrom(response.getNodes()).getTransport().getAddress().publishAddress(); final CountDownLatch latch = new CountDownLatch(1); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherScheduleEngineBenchmark.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherScheduleEngineBenchmark.java index 9c7c9027e7f..8a93492719c 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherScheduleEngineBenchmark.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherScheduleEngineBenchmark.java @@ -47,6 +47,8 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import static java.util.Collections.emptyMap; +import static org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest.Metric.JVM; +import static org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest.Metric.THREAD_POOL; import static org.elasticsearch.search.aggregations.AggregationBuilders.histogram; import static org.elasticsearch.search.aggregations.AggregationBuilders.percentiles; import static org.elasticsearch.search.aggregations.AggregationBuilders.terms; @@ -173,7 +175,9 @@ public class WatcherScheduleEngineBenchmark { public void run() { try { while (start.get()) { - NodesStatsResponse response = client.admin().cluster().prepareNodesStats("_master").setJvm(true).get(); + NodesStatsResponse response = client.admin().cluster().prepareNodesStats("_master") + .addMetric(JVM.metricName()) + .get(); ByteSizeValue heapUsed = response.getNodes().get(0).getJvm().getMem().getHeapUsed(); jvmUsedHeapSpace.inc(heapUsed.getBytes()); Thread.sleep(1000); @@ -187,7 +191,7 @@ public class WatcherScheduleEngineBenchmark { start.set(false); sampleThread.join(); - NodesStatsResponse response = client.admin().cluster().prepareNodesStats().setThreadPool(true).get(); + NodesStatsResponse response = client.admin().cluster().prepareNodesStats().addMetric(THREAD_POOL.metricName()).get(); for (NodeStats nodeStats : response.getNodes()) { for (ThreadPoolStats.Stats threadPoolStats : nodeStats.getThreadPool()) { if ("watcher".equals(threadPoolStats.getName())) { diff --git a/x-pack/qa/security-example-spi-extension/src/test/java/org/elasticsearch/example/realm/CustomRealmIT.java b/x-pack/qa/security-example-spi-extension/src/test/java/org/elasticsearch/example/realm/CustomRealmIT.java index 4487187a80b..2e242cf853d 100644 --- a/x-pack/qa/security-example-spi-extension/src/test/java/org/elasticsearch/example/realm/CustomRealmIT.java +++ b/x-pack/qa/security-example-spi-extension/src/test/java/org/elasticsearch/example/realm/CustomRealmIT.java @@ -28,6 +28,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import static org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest.Metric; import static org.hamcrest.Matchers.is; /** @@ -114,7 +115,7 @@ public class CustomRealmIT extends ESIntegTestCase { } public void testSettingsFiltering() throws Exception { - NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().clear().setSettings(true).get(); + NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().clear().addMetric(Metric.SETTINGS.metricName()).get(); for(NodeInfo info : nodeInfos.getNodes()) { Settings settings = info.getSettings(); assertNotNull(settings); diff --git a/x-pack/qa/smoke-test-plugins-ssl/src/test/java/org/elasticsearch/smoketest/SmokeTestMonitoringWithSecurityIT.java b/x-pack/qa/smoke-test-plugins-ssl/src/test/java/org/elasticsearch/smoketest/SmokeTestMonitoringWithSecurityIT.java index 6164a4d782e..eb300e68157 100644 --- a/x-pack/qa/smoke-test-plugins-ssl/src/test/java/org/elasticsearch/smoketest/SmokeTestMonitoringWithSecurityIT.java +++ b/x-pack/qa/smoke-test-plugins-ssl/src/test/java/org/elasticsearch/smoketest/SmokeTestMonitoringWithSecurityIT.java @@ -31,6 +31,7 @@ import java.util.List; import java.util.Optional; import java.util.concurrent.TimeUnit; +import static org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest.Metric; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; @@ -170,7 +171,7 @@ public class SmokeTestMonitoringWithSecurityIT extends ESIntegTestCase { } private String randomNodeHttpAddress() { - List nodes = client().admin().cluster().prepareNodesInfo().clear().setHttp(true).get().getNodes(); + List nodes = client().admin().cluster().prepareNodesInfo().clear().addMetric(Metric.HTTP.metricName()).get().getNodes(); assertThat(nodes.size(), greaterThan(0)); InetSocketAddress[] httpAddresses = new InetSocketAddress[nodes.size()];