Skip to content

Commit 0045111

Browse files
committed
Deprecate the suggest metrics (#29627)
The suggest stats were folded into the search stats as part of the indices stats API in 5.0.0. However, the suggest metric remained as a synonym for the search metric for BWC reasons. This commit deprecates usage of the suggest metric on the indices stats API. Similarly, due to the changes to fold the suggest stats into the search stats, requesting the suggest index metric on the indices metric on the nodes stats API has produced an empty object as the response since 5.0.0. This commit deprecates this index metric on the indices metric on the nodes stats API.
1 parent dfc7ca7 commit 0045111

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

docs/reference/cluster/nodes-stats.asciidoc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@ Supported metrics are:
346346
* `search`
347347
* `segments`
348348
* `store`
349-
* `suggest`
350349
* `translog`
351350
* `warmer`
352351

server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsAction.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
146146
for (final String indexMetric : indexMetrics) {
147147
final Consumer<CommonStatsFlags> handler = FLAGS.get(indexMetric);
148148
if (handler != null) {
149+
if ("suggest".equals(indexMetric)) {
150+
deprecationLogger.deprecated(
151+
"the suggest index metric is deprecated on the nodes stats API [" + request.uri() + "]");
152+
}
149153
handler.accept(flags);
150154
} else {
151155
invalidIndexMetrics.add(indexMetric);

server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsAction.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
102102
for (final String metric : metrics) {
103103
final Consumer<IndicesStatsRequest> consumer = METRICS.get(metric);
104104
if (consumer != null) {
105+
if ("suggest".equals(metric)) {
106+
deprecationLogger.deprecated("the suggest metric is deprecated on the indices stats API [" + request.uri() + "]");
107+
}
105108
consumer.accept(indicesStatsRequest);
106109
} else {
107110
invalidMetrics.add(metric);

server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsActionTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.elasticsearch.rest.action.admin.cluster;
2121

2222
import org.elasticsearch.client.node.NodeClient;
23+
import org.elasticsearch.common.collect.Tuple;
2324
import org.elasticsearch.common.settings.Settings;
2425
import org.elasticsearch.rest.RestController;
2526
import org.elasticsearch.rest.RestRequest;
@@ -31,7 +32,10 @@
3132
import java.util.Collections;
3233
import java.util.HashMap;
3334
import java.util.HashSet;
35+
import java.util.Map;
3436
import java.util.Set;
37+
import java.util.stream.Collectors;
38+
import java.util.stream.Stream;
3539

3640
import static org.hamcrest.CoreMatchers.containsString;
3741
import static org.hamcrest.object.HasToString.hasToString;
@@ -144,4 +148,14 @@ public void testIndexMetricsRequestOnAllRequest() throws IOException {
144148
containsString("request [/_nodes/stats] contains index metrics [" + indexMetric + "] but all stats requested")));
145149
}
146150

151+
public void testSuggestIsDeprecated() throws IOException {
152+
final Map<String, String> params =
153+
Stream.of(Tuple.tuple("metric", "indices"), Tuple.tuple("index_metric", "suggest"))
154+
.collect(Collectors.toMap(Tuple::v1, Tuple::v2));
155+
final RestRequest request =
156+
new FakeRestRequest.Builder(xContentRegistry()).withPath("/_nodes/stats").withParams(params).build();
157+
action.prepareRequest(request, mock(NodeClient.class));
158+
assertWarnings("the suggest index metric is deprecated on the nodes stats API [/_nodes/stats]" );
159+
}
160+
147161
}

server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsActionTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.io.IOException;
3131
import java.util.Collections;
3232
import java.util.HashMap;
33+
import java.util.Map;
3334

3435
import static org.hamcrest.CoreMatchers.containsString;
3536
import static org.hamcrest.object.HasToString.hasToString;
@@ -83,4 +84,11 @@ public void testAllRequestWithOtherMetrics() throws IOException {
8384
assertThat(e, hasToString(containsString("request [/_stats] contains _all and individual metrics [_all," + metric + "]")));
8485
}
8586

87+
public void testSuggestIsDeprecated() throws IOException {
88+
final Map<String, String> params = Collections.singletonMap("metric", "suggest");
89+
final RestRequest request = new FakeRestRequest.Builder(xContentRegistry()).withPath("/_stats").withParams(params).build();
90+
action.prepareRequest(request, mock(NodeClient.class));
91+
assertWarnings("the suggest metric is deprecated on the indices stats API [/_stats]");
92+
}
93+
8694
}

0 commit comments

Comments
 (0)