浏览代码

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.
Jason Tedor 7 年之前
父节点
当前提交
0045111ce2

+ 0 - 1
docs/reference/cluster/nodes-stats.asciidoc

@@ -346,7 +346,6 @@ Supported metrics are:
 * `search`
 * `segments`
 * `store`
-* `suggest`
 * `translog`
 * `warmer`
 

+ 4 - 0
server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsAction.java

@@ -146,6 +146,10 @@ public class RestNodesStatsAction extends BaseRestHandler {
                     for (final String indexMetric : indexMetrics) {
                         final Consumer<CommonStatsFlags> handler = FLAGS.get(indexMetric);
                         if (handler != null) {
+                            if ("suggest".equals(indexMetric)) {
+                                deprecationLogger.deprecated(
+                                        "the suggest index metric is deprecated on the nodes stats API [" + request.uri() + "]");
+                            }
                             handler.accept(flags);
                         } else {
                             invalidIndexMetrics.add(indexMetric);

+ 3 - 0
server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsAction.java

@@ -102,6 +102,9 @@ public class RestIndicesStatsAction extends BaseRestHandler {
             for (final String metric : metrics) {
                 final Consumer<IndicesStatsRequest> consumer = METRICS.get(metric);
                 if (consumer != null) {
+                    if ("suggest".equals(metric)) {
+                        deprecationLogger.deprecated("the suggest metric is deprecated on the indices stats API [" + request.uri() + "]");
+                    }
                     consumer.accept(indicesStatsRequest);
                 } else {
                     invalidMetrics.add(metric);

+ 14 - 0
server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsActionTests.java

@@ -20,6 +20,7 @@
 package org.elasticsearch.rest.action.admin.cluster;
 
 import org.elasticsearch.client.node.NodeClient;
+import org.elasticsearch.common.collect.Tuple;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.rest.RestController;
 import org.elasticsearch.rest.RestRequest;
@@ -31,7 +32,10 @@ import java.io.IOException;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Map;
 import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.object.HasToString.hasToString;
@@ -144,4 +148,14 @@ public class RestNodesStatsActionTests extends ESTestCase {
                 containsString("request [/_nodes/stats] contains index metrics [" + indexMetric + "] but all stats requested")));
     }
 
+    public void testSuggestIsDeprecated() throws IOException {
+        final Map<String, String> params =
+                Stream.of(Tuple.tuple("metric", "indices"), Tuple.tuple("index_metric", "suggest"))
+                        .collect(Collectors.toMap(Tuple::v1, Tuple::v2));
+        final RestRequest request =
+                new FakeRestRequest.Builder(xContentRegistry()).withPath("/_nodes/stats").withParams(params).build();
+        action.prepareRequest(request, mock(NodeClient.class));
+        assertWarnings("the suggest index metric is deprecated on the nodes stats API [/_nodes/stats]" );
+    }
+
 }

+ 8 - 0
server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsActionTests.java

@@ -30,6 +30,7 @@ import org.elasticsearch.usage.UsageService;
 import java.io.IOException;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Map;
 
 import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.object.HasToString.hasToString;
@@ -83,4 +84,11 @@ public class RestIndicesStatsActionTests extends ESTestCase {
         assertThat(e, hasToString(containsString("request [/_stats] contains _all and individual metrics [_all," + metric + "]")));
     }
 
+    public void testSuggestIsDeprecated() throws IOException {
+        final Map<String, String> params = Collections.singletonMap("metric", "suggest");
+        final RestRequest request = new FakeRestRequest.Builder(xContentRegistry()).withPath("/_stats").withParams(params).build();
+        action.prepareRequest(request, mock(NodeClient.class));
+        assertWarnings("the suggest metric is deprecated on the indices stats API [/_stats]");
+    }
+
 }