Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<IngestStats.ProcessorStat> stats = r.getNodes().get(k).getIngestStats().getProcessorStats().get(pipelineId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NodesInfoRequest, NodesInfoResponse, NodesInfoRequestBuilder> {

public NodesInfoRequestBuilder(ElasticsearchClient client, NodesInfoAction action) {
Expand All @@ -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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Path> paths = StreamSupport.stream(nodeStatsResponse.getNodes().get(0).getFs().spliterator(), false)
.map(nodePath -> PathUtils.get(nodePath.getPath())
.resolve(NodeEnvironment.INDICES_FOLDER)
Expand Down
Loading