From 0045111ce2817f3d029569630c1ff017eea91f04 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Fri, 20 Apr 2018 09:46:01 -0400 Subject: [PATCH] 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. --- docs/reference/cluster/nodes-stats.asciidoc | 1 - .../action/admin/cluster/RestNodesStatsAction.java | 4 ++++ .../admin/indices/RestIndicesStatsAction.java | 3 +++ .../admin/cluster/RestNodesStatsActionTests.java | 14 ++++++++++++++ .../admin/indices/RestIndicesStatsActionTests.java | 8 ++++++++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/reference/cluster/nodes-stats.asciidoc b/docs/reference/cluster/nodes-stats.asciidoc index ec25d27d253..eb3abb19d1a 100644 --- a/docs/reference/cluster/nodes-stats.asciidoc +++ b/docs/reference/cluster/nodes-stats.asciidoc @@ -346,7 +346,6 @@ Supported metrics are: * `search` * `segments` * `store` -* `suggest` * `translog` * `warmer` diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsAction.java index 14c8655e48c..624f7d1b9dc 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsAction.java +++ b/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 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); diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsAction.java index 1dbbd6f1696..f868a8d6c43 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsAction.java +++ b/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 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); diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsActionTests.java index 640b97605af..90e0cfa656b 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsActionTests.java +++ b/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 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]" ); + } + } diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsActionTests.java index 26c1e1fa177..38edbee673e 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsActionTests.java +++ b/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 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]"); + } + }