Skip to content

Commit f4a96f5

Browse files
Revert "Refactor nodes stats request builders to match requests (#54363)"
This reverts commit d6d664c.
1 parent ddcb2ed commit f4a96f5

File tree

19 files changed

+213
-107
lines changed

19 files changed

+213
-107
lines changed

modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/IngestRestartIT.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import java.util.function.Consumer;
3939
import java.util.function.Function;
4040

41-
import static org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest.Metric.INGEST;
4241
import static org.hamcrest.Matchers.equalTo;
4342
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
4443

@@ -96,9 +95,7 @@ public void testFailureInConditionalProcessor() {
9695
);
9796
assertTrue(e.getMessage().contains("this script always fails"));
9897

99-
NodesStatsResponse r = client().admin().cluster().prepareNodesStats(internalCluster().getNodeNames())
100-
.addMetric(INGEST.metricName())
101-
.get();
98+
NodesStatsResponse r = client().admin().cluster().prepareNodesStats(internalCluster().getNodeNames()).setIngest(true).get();
10299
int nodeCount = r.getNodes().size();
103100
for (int k = 0; k < nodeCount; k++) {
104101
List<IngestStats.ProcessorStat> stats = r.getNodes().get(k).getIngestStats().getProcessorStats().get(pipelineId);

modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/Netty4TransportMultiPortIntegrationIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
import java.util.Locale;
3333

34-
import static org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest.Metric.TRANSPORT;
3534
import static org.hamcrest.Matchers.allOf;
3635
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
3736
import static org.hamcrest.Matchers.hasKey;
@@ -64,7 +63,7 @@ protected Settings nodeSettings(int nodeOrdinal) {
6463

6564
@Network
6665
public void testThatInfosAreExposed() throws Exception {
67-
NodesInfoResponse response = client().admin().cluster().prepareNodesInfo().clear().addMetric(TRANSPORT.metricName()).get();
66+
NodesInfoResponse response = client().admin().cluster().prepareNodesInfo().clear().setTransport(true).get();
6867
for (NodeInfo nodeInfo : response.getNodes()) {
6968
assertThat(nodeInfo.getTransport().getProfileAddresses().keySet(), hasSize(1));
7069
assertThat(nodeInfo.getTransport().getProfileAddresses(), hasKey("client1"));

server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequestBuilder.java

Lines changed: 79 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.elasticsearch.action.support.nodes.NodesOperationRequestBuilder;
2323
import org.elasticsearch.client.ElasticsearchClient;
2424

25+
// TODO: This class's interface should match that of NodesInfoRequest
2526
public class NodesInfoRequestBuilder extends NodesOperationRequestBuilder<NodesInfoRequest, NodesInfoResponse, NodesInfoRequestBuilder> {
2627

2728
public NodesInfoRequestBuilder(ElasticsearchClient client, NodesInfoAction action) {
@@ -45,24 +46,90 @@ public NodesInfoRequestBuilder all() {
4546
}
4647

4748
/**
48-
* Add a single metric to the request.
49-
*
50-
* @param metric Name of metric as a string.
51-
* @return This, for request chaining.
49+
* Should the node settings be returned.
5250
*/
53-
public NodesInfoRequestBuilder addMetric(String metric) {
54-
request.addMetric(metric);
51+
public NodesInfoRequestBuilder setSettings(boolean settings) {
52+
addOrRemoveMetric(settings, NodesInfoRequest.Metric.SETTINGS);
5553
return this;
5654
}
5755

5856
/**
59-
* Add an array of metrics to the request.
60-
*
61-
* @param metrics Metric names as strings.
62-
* @return This, for request chaining.
57+
* Should the node OS info be returned.
6358
*/
64-
public NodesInfoRequestBuilder addMetrics(String... metrics) {
65-
request.addMetrics(metrics);
59+
public NodesInfoRequestBuilder setOs(boolean os) {
60+
addOrRemoveMetric(os, NodesInfoRequest.Metric.OS);
6661
return this;
6762
}
63+
64+
/**
65+
* Should the node OS process be returned.
66+
*/
67+
public NodesInfoRequestBuilder setProcess(boolean process) {
68+
addOrRemoveMetric(process, NodesInfoRequest.Metric.PROCESS);
69+
return this;
70+
}
71+
72+
/**
73+
* Should the node JVM info be returned.
74+
*/
75+
public NodesInfoRequestBuilder setJvm(boolean jvm) {
76+
addOrRemoveMetric(jvm, NodesInfoRequest.Metric.JVM);
77+
return this;
78+
}
79+
80+
/**
81+
* Should the node thread pool info be returned.
82+
*/
83+
public NodesInfoRequestBuilder setThreadPool(boolean threadPool) {
84+
addOrRemoveMetric(threadPool, NodesInfoRequest.Metric.THREAD_POOL);
85+
return this;
86+
}
87+
88+
/**
89+
* Should the node Transport info be returned.
90+
*/
91+
public NodesInfoRequestBuilder setTransport(boolean transport) {
92+
addOrRemoveMetric(transport, NodesInfoRequest.Metric.TRANSPORT);
93+
return this;
94+
}
95+
96+
/**
97+
* Should the node HTTP info be returned.
98+
*/
99+
public NodesInfoRequestBuilder setHttp(boolean http) {
100+
addOrRemoveMetric(http, NodesInfoRequest.Metric.HTTP);
101+
return this;
102+
}
103+
104+
/**
105+
* Should the node plugins info be returned.
106+
*/
107+
public NodesInfoRequestBuilder setPlugins(boolean plugins) {
108+
addOrRemoveMetric(plugins, NodesInfoRequest.Metric.PLUGINS);
109+
return this;
110+
}
111+
112+
/**
113+
* Should the node ingest info be returned.
114+
*/
115+
public NodesInfoRequestBuilder setIngest(boolean ingest) {
116+
addOrRemoveMetric(ingest, NodesInfoRequest.Metric.INGEST);
117+
return this;
118+
}
119+
120+
/**
121+
* Should the node indices info be returned.
122+
*/
123+
public NodesInfoRequestBuilder setIndices(boolean indices) {
124+
addOrRemoveMetric(indices, NodesInfoRequest.Metric.INDICES);
125+
return this;
126+
}
127+
128+
private void addOrRemoveMetric(boolean includeMetric, NodesInfoRequest.Metric metric) {
129+
if (includeMetric) {
130+
request.addMetric(metric.metricName());
131+
} else {
132+
request.removeMetric(metric.metricName());
133+
}
134+
}
68135
}

server/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsRequestBuilder.java

Lines changed: 103 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,40 +47,125 @@ public NodesStatsRequestBuilder clear() {
4747
}
4848

4949
/**
50-
* Add a single metric to the request.
51-
*
52-
* @param metric Name of metric as a string.
53-
* @return This, for request chaining.
50+
* Should the node indices stats be returned.
5451
*/
55-
public NodesStatsRequestBuilder addMetric(String metric) {
56-
request.addMetric(metric);
52+
public NodesStatsRequestBuilder setIndices(boolean indices) {
53+
request.indices(indices);
5754
return this;
5855
}
5956

60-
/**
61-
* Add an array of metrics to the request.
62-
*
63-
* @param metrics Metric names as strings.
64-
* @return This, for request chaining.
65-
*/
66-
public NodesStatsRequestBuilder addMetrics(String... metrics) {
67-
request.addMetrics(metrics);
57+
public NodesStatsRequestBuilder setBreaker(boolean breaker) {
58+
addOrRemoveMetric(breaker, NodesStatsRequest.Metric.BREAKER);
59+
return this;
60+
}
61+
62+
public NodesStatsRequestBuilder setScript(boolean script) {
63+
addOrRemoveMetric(script, NodesStatsRequest.Metric.SCRIPT);
6864
return this;
6965
}
7066

7167
/**
7268
* Should the node indices stats be returned.
7369
*/
74-
public NodesStatsRequestBuilder setIndices(boolean indices) {
70+
public NodesStatsRequestBuilder setIndices(CommonStatsFlags indices) {
7571
request.indices(indices);
7672
return this;
7773
}
7874

7975
/**
80-
* Should the node indices stats be returned.
76+
* Should the node OS stats be returned.
8177
*/
82-
public NodesStatsRequestBuilder setIndices(CommonStatsFlags indices) {
83-
request.indices(indices);
78+
public NodesStatsRequestBuilder setOs(boolean os) {
79+
addOrRemoveMetric(os, NodesStatsRequest.Metric.OS);
80+
return this;
81+
}
82+
83+
/**
84+
* Should the node OS stats be returned.
85+
*/
86+
public NodesStatsRequestBuilder setProcess(boolean process) {
87+
addOrRemoveMetric(process, NodesStatsRequest.Metric.PROCESS);
88+
return this;
89+
}
90+
91+
/**
92+
* Should the node JVM stats be returned.
93+
*/
94+
public NodesStatsRequestBuilder setJvm(boolean jvm) {
95+
addOrRemoveMetric(jvm, NodesStatsRequest.Metric.JVM);
96+
return this;
97+
}
98+
99+
/**
100+
* Should the node thread pool stats be returned.
101+
*/
102+
public NodesStatsRequestBuilder setThreadPool(boolean threadPool) {
103+
addOrRemoveMetric(threadPool, NodesStatsRequest.Metric.THREAD_POOL);
104+
return this;
105+
}
106+
107+
/**
108+
* Should the node file system stats be returned.
109+
*/
110+
public NodesStatsRequestBuilder setFs(boolean fs) {
111+
addOrRemoveMetric(fs, NodesStatsRequest.Metric.FS);
84112
return this;
85113
}
114+
115+
/**
116+
* Should the node Transport stats be returned.
117+
*/
118+
public NodesStatsRequestBuilder setTransport(boolean transport) {
119+
addOrRemoveMetric(transport, NodesStatsRequest.Metric.TRANSPORT);
120+
return this;
121+
}
122+
123+
/**
124+
* Should the node HTTP stats be returned.
125+
*/
126+
public NodesStatsRequestBuilder setHttp(boolean http) {
127+
addOrRemoveMetric(http, NodesStatsRequest.Metric.HTTP);
128+
return this;
129+
}
130+
131+
/**
132+
* Should the discovery stats be returned.
133+
*/
134+
public NodesStatsRequestBuilder setDiscovery(boolean discovery) {
135+
addOrRemoveMetric(discovery, NodesStatsRequest.Metric.DISCOVERY);
136+
return this;
137+
}
138+
139+
/**
140+
* Should ingest statistics be returned.
141+
*/
142+
public NodesStatsRequestBuilder setIngest(boolean ingest) {
143+
addOrRemoveMetric(ingest, NodesStatsRequest.Metric.INGEST);
144+
return this;
145+
}
146+
147+
public NodesStatsRequestBuilder setAdaptiveSelection(boolean adaptiveSelection) {
148+
addOrRemoveMetric(adaptiveSelection, NodesStatsRequest.Metric.ADAPTIVE_SELECTION);
149+
return this;
150+
}
151+
152+
/**
153+
* Should script context cache statistics be returned
154+
*/
155+
public NodesStatsRequestBuilder setScriptCache(boolean scriptCache) {
156+
addOrRemoveMetric(scriptCache, NodesStatsRequest.Metric.SCRIPT_CACHE);
157+
return this;
158+
}
159+
160+
/**
161+
* Helper method for adding metrics to a request
162+
*/
163+
private void addOrRemoveMetric(boolean includeMetric, NodesStatsRequest.Metric metric) {
164+
if (includeMetric) {
165+
request.addMetric(metric.metricName());
166+
} else {
167+
request.removeMetric(metric.metricName());
168+
}
169+
}
170+
86171
}

server/src/test/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import java.util.Map;
4242
import java.util.concurrent.ExecutionException;
4343

44-
import static org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest.Metric.OS;
4544
import static org.hamcrest.Matchers.equalTo;
4645
import static org.hamcrest.Matchers.is;
4746

@@ -194,7 +193,7 @@ public void testValuesSmokeScreen() throws IOException, ExecutionException, Inte
194193
assertThat(msg, response.nodesStats.getProcess().getMinOpenFileDescriptors(), Matchers.greaterThanOrEqualTo(-1L));
195194
assertThat(msg, response.nodesStats.getProcess().getMaxOpenFileDescriptors(), Matchers.greaterThanOrEqualTo(-1L));
196195

197-
NodesStatsResponse nodesStatsResponse = client().admin().cluster().prepareNodesStats().addMetric(OS.metricName()).get();
196+
NodesStatsResponse nodesStatsResponse = client().admin().cluster().prepareNodesStats().setOs(true).get();
198197
long total = 0;
199198
long free = 0;
200199
long used = 0;

server/src/test/java/org/elasticsearch/cluster/coordination/ZenDiscoveryIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import java.util.concurrent.TimeUnit;
4747
import java.util.concurrent.TimeoutException;
4848

49-
import static org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest.Metric.DISCOVERY;
5049
import static org.hamcrest.Matchers.containsString;
5150
import static org.hamcrest.Matchers.equalTo;
5251
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
@@ -158,7 +157,7 @@ public void testDiscoveryStats() throws Exception {
158157
equalTo(0))); // see https://github.com/elastic/elasticsearch/issues/24388
159158

160159
logger.info("--> request node discovery stats");
161-
NodesStatsResponse statsResponse = client().admin().cluster().prepareNodesStats().clear().addMetric(DISCOVERY.metricName()).get();
160+
NodesStatsResponse statsResponse = client().admin().cluster().prepareNodesStats().clear().setDiscovery(true).get();
162161
assertThat(statsResponse.getNodes().size(), equalTo(1));
163162

164163
DiscoveryStats stats = statsResponse.getNodes().get(0).getDiscoveryStats();

server/src/test/java/org/elasticsearch/cluster/settings/SettingsFilteringIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import java.util.Collection;
3434
import java.util.List;
3535

36-
import static org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest.Metric.SETTINGS;
3736
import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE;
3837
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
3938
import static org.hamcrest.Matchers.equalTo;
@@ -90,7 +89,7 @@ public void testSettingsFiltering() {
9089
}
9190

9291
public void testNodeInfoIsFiltered() {
93-
NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().clear().addMetric(SETTINGS.metricName()).get();
92+
NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().clear().setSettings(true).get();
9493
for(NodeInfo info : nodeInfos.getNodes()) {
9594
Settings settings = info.getSettings();
9695
assertNotNull(settings);

server/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@
107107
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomAsciiLettersOfLength;
108108
import static java.util.Collections.emptyMap;
109109
import static java.util.Collections.emptySet;
110-
import static org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest.Metric.BREAKER;
111110
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
112111
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.NONE;
113112
import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS;
@@ -565,7 +564,7 @@ private void checkAccountingBreaker() {
565564
CircuitBreaker acctBreaker = breakerService.getBreaker(CircuitBreaker.ACCOUNTING);
566565
long usedMem = acctBreaker.getUsed();
567566
assertThat(usedMem, greaterThan(0L));
568-
NodesStatsResponse response = client().admin().cluster().prepareNodesStats().setIndices(true).addMetric(BREAKER.metricName()).get();
567+
NodesStatsResponse response = client().admin().cluster().prepareNodesStats().setIndices(true).setBreaker(true).get();
569568
NodeStats stats = response.getNodes().get(0);
570569
assertNotNull(stats);
571570
SegmentsStats segmentsStats = stats.getIndices().getSegments();

server/src/test/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
import java.util.stream.Collectors;
8989
import java.util.stream.StreamSupport;
9090

91-
import static org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest.Metric.FS;
9291
import static org.elasticsearch.common.util.CollectionUtils.iterableAsArrayList;
9392
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
9493
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
@@ -598,7 +597,7 @@ private Path getPathToShardData(String indexName, String dirSuffix) {
598597
}
599598

600599
public static Path getPathToShardData(String nodeId, ShardId shardId, String shardPathSubdirectory) {
601-
final NodesStatsResponse nodeStatsResponse = client().admin().cluster().prepareNodesStats(nodeId).addMetric(FS.metricName()).get();
600+
final NodesStatsResponse nodeStatsResponse = client().admin().cluster().prepareNodesStats(nodeId).setFs(true).get();
602601
final Set<Path> paths = StreamSupport.stream(nodeStatsResponse.getNodes().get(0).getFs().spliterator(), false)
603602
.map(nodePath -> PathUtils.get(nodePath.getPath())
604603
.resolve(NodeEnvironment.INDICES_FOLDER)

0 commit comments

Comments
 (0)