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 28da917fedff3..c9e4e1ebb4bbf 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 @@ -38,6 +38,7 @@ 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; @@ -95,7 +96,9 @@ public void testFailureInConditionalProcessor() { ); 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 47af90d2bf39e..a1a9bee9dcf33 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 @@ -31,6 +31,7 @@ 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; @@ -63,7 +64,7 @@ protected Settings nodeSettings(int nodeOrdinal) { @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 97b55b7fd496a..a73c0e82b2d2f 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 @@ 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 NodesInfoRequestBuilder all() { } /** - * Should the node settings be returned. + * Add a single metric to the request. + * + * @param metric Name of metric as a string. + * @return This, for request chaining. */ - public NodesInfoRequestBuilder setSettings(boolean settings) { - addOrRemoveMetric(settings, NodesInfoRequest.Metric.SETTINGS); + public NodesInfoRequestBuilder addMetric(String metric) { + request.addMetric(metric); return this; } /** - * Should the node OS info be returned. + * Add an array of metrics to the request. + * + * @param metrics Metric names as strings. + * @return This, for request chaining. */ - public NodesInfoRequestBuilder setOs(boolean os) { - addOrRemoveMetric(os, NodesInfoRequest.Metric.OS); + public NodesInfoRequestBuilder addMetrics(String... metrics) { + request.addMetrics(metrics); return this; } - - /** - * Should the node OS process be returned. - */ - public NodesInfoRequestBuilder setProcess(boolean process) { - addOrRemoveMetric(process, NodesInfoRequest.Metric.PROCESS); - return this; - } - - /** - * Should the node JVM info be returned. - */ - public NodesInfoRequestBuilder setJvm(boolean jvm) { - addOrRemoveMetric(jvm, NodesInfoRequest.Metric.JVM); - return this; - } - - /** - * Should the node thread pool info be returned. - */ - public NodesInfoRequestBuilder setThreadPool(boolean threadPool) { - addOrRemoveMetric(threadPool, NodesInfoRequest.Metric.THREAD_POOL); - return this; - } - - /** - * Should the node Transport info be returned. - */ - public NodesInfoRequestBuilder setTransport(boolean transport) { - addOrRemoveMetric(transport, NodesInfoRequest.Metric.TRANSPORT); - return this; - } - - /** - * Should the node HTTP info be returned. - */ - public NodesInfoRequestBuilder setHttp(boolean http) { - addOrRemoveMetric(http, NodesInfoRequest.Metric.HTTP); - return this; - } - - /** - * Should the node plugins info be returned. - */ - public NodesInfoRequestBuilder setPlugins(boolean plugins) { - addOrRemoveMetric(plugins, NodesInfoRequest.Metric.PLUGINS); - return this; - } - - /** - * Should the node ingest info be returned. - */ - public NodesInfoRequestBuilder setIngest(boolean ingest) { - addOrRemoveMetric(ingest, NodesInfoRequest.Metric.INGEST); - return this; - } - - /** - * Should the node indices info be returned. - */ - public NodesInfoRequestBuilder setIndices(boolean indices) { - addOrRemoveMetric(indices, NodesInfoRequest.Metric.INDICES); - return this; - } - - private void addOrRemoveMetric(boolean includeMetric, NodesInfoRequest.Metric metric) { - if (includeMetric) { - request.addMetric(metric.metricName()); - } else { - request.removeMetric(metric.metricName()); - } - } } diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsRequestBuilder.java index 2ce3cb2b03e1a..cc6b74dbc5a11 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsRequestBuilder.java @@ -47,125 +47,40 @@ public NodesStatsRequestBuilder clear() { } /** - * Should the node indices stats be returned. - */ - public NodesStatsRequestBuilder setIndices(boolean indices) { - request.indices(indices); - return this; - } - - public NodesStatsRequestBuilder setBreaker(boolean breaker) { - addOrRemoveMetric(breaker, NodesStatsRequest.Metric.BREAKER); - return this; - } - - public NodesStatsRequestBuilder setScript(boolean script) { - addOrRemoveMetric(script, NodesStatsRequest.Metric.SCRIPT); - return this; - } - - /** - * Should the node indices stats be returned. - */ - public NodesStatsRequestBuilder setIndices(CommonStatsFlags indices) { - request.indices(indices); - return this; - } - - /** - * Should the node OS stats be returned. - */ - public NodesStatsRequestBuilder setOs(boolean os) { - addOrRemoveMetric(os, NodesStatsRequest.Metric.OS); - return this; - } - - /** - * Should the node OS stats be returned. - */ - public NodesStatsRequestBuilder setProcess(boolean process) { - addOrRemoveMetric(process, NodesStatsRequest.Metric.PROCESS); - return this; - } - - /** - * Should the node JVM stats be returned. - */ - public NodesStatsRequestBuilder setJvm(boolean jvm) { - addOrRemoveMetric(jvm, NodesStatsRequest.Metric.JVM); - return this; - } - - /** - * Should the node thread pool stats be returned. - */ - public NodesStatsRequestBuilder setThreadPool(boolean threadPool) { - addOrRemoveMetric(threadPool, NodesStatsRequest.Metric.THREAD_POOL); - return this; - } - - /** - * Should the node file system stats be returned. + * Add a single metric to the request. + * + * @param metric Name of metric as a string. + * @return This, for request chaining. */ - public NodesStatsRequestBuilder setFs(boolean fs) { - addOrRemoveMetric(fs, NodesStatsRequest.Metric.FS); + public NodesStatsRequestBuilder addMetric(String metric) { + request.addMetric(metric); return this; } /** - * Should the node Transport stats be returned. + * Add an array of metrics to the request. + * + * @param metrics Metric names as strings. + * @return This, for request chaining. */ - public NodesStatsRequestBuilder setTransport(boolean transport) { - addOrRemoveMetric(transport, NodesStatsRequest.Metric.TRANSPORT); + public NodesStatsRequestBuilder addMetrics(String... metrics) { + request.addMetrics(metrics); return this; } /** - * Should the node HTTP stats be returned. - */ - public NodesStatsRequestBuilder setHttp(boolean http) { - addOrRemoveMetric(http, NodesStatsRequest.Metric.HTTP); - return this; - } - - /** - * Should the discovery stats be returned. - */ - public NodesStatsRequestBuilder setDiscovery(boolean discovery) { - addOrRemoveMetric(discovery, NodesStatsRequest.Metric.DISCOVERY); - return this; - } - - /** - * Should ingest statistics be returned. + * Should the node indices stats be returned. */ - public NodesStatsRequestBuilder setIngest(boolean ingest) { - addOrRemoveMetric(ingest, NodesStatsRequest.Metric.INGEST); - return this; - } - - public NodesStatsRequestBuilder setAdaptiveSelection(boolean adaptiveSelection) { - addOrRemoveMetric(adaptiveSelection, NodesStatsRequest.Metric.ADAPTIVE_SELECTION); + public NodesStatsRequestBuilder setIndices(boolean indices) { + request.indices(indices); return this; } /** - * Should script context cache statistics be returned + * Should the node indices stats be returned. */ - public NodesStatsRequestBuilder setScriptCache(boolean scriptCache) { - addOrRemoveMetric(scriptCache, NodesStatsRequest.Metric.SCRIPT_CACHE); + public NodesStatsRequestBuilder setIndices(CommonStatsFlags indices) { + request.indices(indices); return this; } - - /** - * Helper method for adding metrics to a request - */ - private void addOrRemoveMetric(boolean includeMetric, NodesStatsRequest.Metric metric) { - if (includeMetric) { - request.addMetric(metric.metricName()); - } else { - request.removeMetric(metric.metricName()); - } - } - } diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIT.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIT.java index e5126203b988d..6879f52eb7344 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIT.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIT.java @@ -41,6 +41,7 @@ import java.util.Map; import java.util.concurrent.ExecutionException; +import static org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest.Metric.OS; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; @@ -193,7 +194,7 @@ public void testValuesSmokeScreen() throws IOException, ExecutionException, Inte assertThat(msg, response.nodesStats.getProcess().getMinOpenFileDescriptors(), Matchers.greaterThanOrEqualTo(-1L)); assertThat(msg, response.nodesStats.getProcess().getMaxOpenFileDescriptors(), Matchers.greaterThanOrEqualTo(-1L)); - NodesStatsResponse nodesStatsResponse = client().admin().cluster().prepareNodesStats().setOs(true).get(); + NodesStatsResponse nodesStatsResponse = client().admin().cluster().prepareNodesStats().addMetric(OS.metricName()).get(); long total = 0; long free = 0; long used = 0; diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/ZenDiscoveryIT.java b/server/src/test/java/org/elasticsearch/cluster/coordination/ZenDiscoveryIT.java index 2aa8ffd7e5a00..d7dd172e347ed 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/ZenDiscoveryIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/ZenDiscoveryIT.java @@ -46,6 +46,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import static org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest.Metric.DISCOVERY; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo; @@ -157,7 +158,7 @@ public void testDiscoveryStats() throws Exception { equalTo(0))); // see https://github.com/elastic/elasticsearch/issues/24388 logger.info("--> 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 08a16b89eca05..dab959122f2de 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.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 void testSettingsFiltering() { } 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 95c3002157d7b..21687c68157ea 100644 --- a/server/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java +++ b/server/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java @@ -107,6 +107,7 @@ 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; @@ -564,7 +565,7 @@ private void checkAccountingBreaker() { 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 798ee74075c13..9d8a8a3be1293 100644 --- a/server/src/test/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandIT.java +++ b/server/src/test/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandIT.java @@ -88,6 +88,7 @@ import java.util.stream.Collectors; 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; @@ -597,7 +598,7 @@ private Path getPathToShardData(String indexName, String dirSuffix) { } 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 8fe0b1db483a8..260ae8b179757 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.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 @@ private ShardRouting corruptRandomPrimaryFile(final boolean includePerCommitFile 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 @@ private static boolean isPerSegmentFile(String fileName) { } 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 7d0cb30dc8ad9..2a321d7479da0 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.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 void teardown() { /** 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 void testMemoryBreaker() throws Exception { 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 void testRamAccountingTermsEnum() throws Exception { 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); @@ -296,8 +303,9 @@ public void testBucketBreaker() throws Exception { 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(), @@ -326,7 +334,9 @@ public void testCustomCircuitBreakerRegistration() throws Exception { } } - 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 1fb278ba31311..339f172b68c31 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 @@ -54,6 +54,7 @@ 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; @@ -72,8 +73,9 @@ protected boolean addMockInternalEngine() { } 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)); } @@ -153,8 +155,9 @@ public void testBreakerWithRandomExceptions() throws IOException, InterruptedExc 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)); } @@ -189,8 +192,9 @@ public void testBreakerWithRandomExceptions() throws IOException, InterruptedExc // 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 615bf5431276e..a0a6c1c7de1f5 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 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 void testNodesInfosTotalIndexingBuffer() throws Exception { 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 245188f8eb129..90cb113e87ce9 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ExternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ExternalTestCluster.java @@ -52,6 +52,9 @@ import java.util.function.Function; import java.util.stream.Collectors; +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; @@ -112,7 +115,9 @@ public ExternalTestCluster(Path tempDir, Settings additionalSettings, Collection Client client = clientWrapper.apply(node.client()); try { node.start(); - 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()]; int dataNodes = 0; int masterAndDataNodes = 0; @@ -187,8 +192,10 @@ public void close() throws IOException { @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 f4023df66c91e..60cdaadf5fe80 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 @@ -59,6 +59,7 @@ 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; @@ -400,7 +401,9 @@ public void disableMonitoring() throws Exception { 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 98ed44f845482..b7d16bb8e34b6 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 @@ -55,6 +55,7 @@ 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; @@ -216,7 +217,7 @@ public void assertXPackIsInstalled() { } 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 7471d96789cf4..97aea0b859149 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 @@ -38,6 +38,7 @@ 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; @@ -148,7 +149,7 @@ public void assertXPackIsInstalled() { } 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 df701aacb26e2..3a413c1fba3e7 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.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.is; @@ -71,7 +72,7 @@ public void testConnection() throws Exception { 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 c4c810681e9b0..3d160a65f8d6f 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 @@ -48,6 +48,8 @@ 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 static void main(String[] args) throws Exception { 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 void run() { 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())) {