Skip to content

Commit

Permalink
Deprecate the suggest metrics (#29627)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jasontedor committed Apr 20, 2018
1 parent dfc7ca7 commit 0045111
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
1 change: 0 additions & 1 deletion docs/reference/cluster/nodes-stats.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ Supported metrics are:
* `search`
* `segments`
* `store`
* `suggest`
* `translog`
* `warmer`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +32,10 @@
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;
Expand Down Expand Up @@ -144,4 +148,14 @@ public void testIndexMetricsRequestOnAllRequest() throws IOException {
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]" );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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;
Expand Down Expand Up @@ -83,4 +84,11 @@ public void testAllRequestWithOtherMetrics() throws IOException {
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]");
}

}

0 comments on commit 0045111

Please sign in to comment.