From fdc301f04585a22af25542447fb0d087f5f6acea Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Thu, 17 Jun 2021 14:21:21 +0200 Subject: [PATCH] [Rest Api Compatibility] Typed indexing stats (#74181) the per type indexing stats is simplified and when _types is requested it will return total stats for the index repeated under types/_doc/ the removal #47203 relates main meta issue #51816 relates types removal issue #54160 --- rest-api-spec/build.gradle | 25 +++++++++++-------- .../index/shard/IndexingStats.java | 9 +++++++ .../admin/cluster/RestNodesStatsAction.java | 10 ++++++++ .../admin/indices/RestIndicesStatsAction.java | 11 ++++++++ .../document/RestMultiTermVectorsAction.java | 2 +- 5 files changed, 46 insertions(+), 11 deletions(-) diff --git a/rest-api-spec/build.gradle b/rest-api-spec/build.gradle index b6d603898f2a3..59e4360fc2339 100644 --- a/rest-api-spec/build.gradle +++ b/rest-api-spec/build.gradle @@ -65,6 +65,10 @@ def v7compatiblityNotSupportedTests = { 'mget/16_basic_with_types/Basic multi-get', // asserting about type not found won't work as we ignore the type information 'explain/40_mix_typeless_typeful/Explain with typeless API on an index that has types', + // translog settings removal is not supported under compatible api + 'indices.stats/20_translog/Translog retention settings are deprecated', + 'indices.stats/20_translog/Translog retention without soft_deletes', + 'indices.stats/20_translog/Translog stats on closed indices without soft-deletes' ] } tasks.named("yamlRestCompatTest").configure { @@ -86,16 +90,6 @@ tasks.named("yamlRestCompatTest").configure { 'indices.put_template/11_basic_with_types/Put template with empty mappings', 'indices.shrink/30_copy_settings/Copy settings during shrink index', 'indices.split/30_copy_settings/Copy settings during split index', - 'indices.stats/15_types/Types - _all metric', - 'indices.stats/15_types/Types - indexing metric', - 'indices.stats/15_types/Types - multi', - 'indices.stats/15_types/Types - multi metric', - 'indices.stats/15_types/Types - one', - 'indices.stats/15_types/Types - pattern', - 'indices.stats/15_types/Types - star', - 'indices.stats/20_translog/Translog retention settings are deprecated', - 'indices.stats/20_translog/Translog retention without soft_deletes', - 'indices.stats/20_translog/Translog stats on closed indices without soft-deletes', 'indices.upgrade/10_basic/Basic test for upgrade indices', 'indices.upgrade/10_basic/Upgrade indices allow no indices', 'indices.upgrade/10_basic/Upgrade indices disallow no indices', @@ -236,6 +230,17 @@ tasks.named("transformV7RestTests").configure({ task -> task.replaceValueInMatch("docs.0._type", "_doc", "IDs") task.replaceValueInMatch("docs.1._type", "_doc", "IDs") task.replaceValueInMatch("docs.2._type", "_doc", "Routing") + + //overrides for indices.stats + //TODO fix to remove the below match + task.replaceKeyInMatch("_all.primaries.indexing.types.baz.index_total", + "_all.primaries.indexing.types._doc.index_total" + ) + task.replaceKeyInMatch("_all.primaries.indexing.types.bar.index_total", + "_all.primaries.indexing.types._doc.index_total" + ) + task.replaceValueInMatch("_all.primaries.indexing.types._doc.index_total", 2) + }) tasks.register('enforceYamlTestConvention').configure { diff --git a/server/src/main/java/org/elasticsearch/index/shard/IndexingStats.java b/server/src/main/java/org/elasticsearch/index/shard/IndexingStats.java index 054bc8eb4764e..e4122cfd001a9 100644 --- a/server/src/main/java/org/elasticsearch/index/shard/IndexingStats.java +++ b/server/src/main/java/org/elasticsearch/index/shard/IndexingStats.java @@ -12,6 +12,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.core.RestApiVersion; import org.elasticsearch.core.TimeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment; @@ -214,12 +215,20 @@ public Stats getTotal() { public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { builder.startObject(Fields.INDEXING); totalStats.toXContent(builder, params); + if(builder.getRestApiVersion() == RestApiVersion.V_7 && params.param("types") != null){ + builder.startObject(Fields.TYPES); + builder.startObject(MapperService.SINGLE_MAPPING_NAME); + totalStats.toXContent(builder, params); + builder.endObject(); + builder.endObject(); + } builder.endObject(); return builder; } static final class Fields { static final String INDEXING = "indexing"; + static final String TYPES = "types"; static final String INDEX_TOTAL = "index_total"; static final String INDEX_TIME = "index_time"; static final String INDEX_TIME_IN_MILLIS = "index_time_in_millis"; 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 6879b6f6de596..07f5edeb4769e 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 @@ -13,6 +13,8 @@ import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags.Flag; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.logging.DeprecationLogger; +import org.elasticsearch.core.RestApiVersion; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions.NodesResponseRestListener; @@ -31,6 +33,9 @@ import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestNodesStatsAction extends BaseRestHandler { + private DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestNodesStatsAction.class); + private static final String TYPES_DEPRECATION_MESSAGE = + "[types removal] " + "Specifying types in nodes stats requests is deprecated."; @Override public List routes() { @@ -71,6 +76,11 @@ public String getName() { @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { + if(request.getRestApiVersion() == RestApiVersion.V_7 && request.hasParam("types")){ + deprecationLogger.compatibleApiWarning("nodes_stats_types", TYPES_DEPRECATION_MESSAGE); + request.param("types"); + } + String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodeId")); Set metrics = Strings.tokenizeByCommaToSet(request.param("metric", "_all")); 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 3d84403e63f95..0fe0a93e07f4f 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 @@ -14,10 +14,13 @@ import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.logging.DeprecationLogger; +import org.elasticsearch.core.RestApiVersion; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestCancellableNodeClient; import org.elasticsearch.rest.action.RestToXContentListener; +import org.elasticsearch.rest.action.document.RestMultiTermVectorsAction; import java.io.IOException; import java.util.Collections; @@ -32,6 +35,9 @@ import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestIndicesStatsAction extends BaseRestHandler { + private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestMultiTermVectorsAction.class); + private static final String TYPES_DEPRECATION_MESSAGE = + "[types removal] " + "Specifying types in indices stats requests is deprecated."; @Override public List routes() { @@ -64,6 +70,11 @@ public boolean allowSystemIndexAccessByDefault() { @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { + if(request.getRestApiVersion() == RestApiVersion.V_7 && request.hasParam("types")){ + deprecationLogger.compatibleApiWarning("indices_stats_types", TYPES_DEPRECATION_MESSAGE); + request.param("types"); + } + IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest(); boolean forbidClosedIndices = request.paramAsBoolean("forbid_closed_indices", true); IndicesOptions defaultIndicesOption = forbidClosedIndices ? indicesStatsRequest.indicesOptions() diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java index c6472ff7df940..ec0cf8cd9cce2 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java @@ -26,7 +26,7 @@ import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestMultiTermVectorsAction extends BaseRestHandler { - DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestMultiTermVectorsAction.class); + private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestMultiTermVectorsAction.class); static final String TYPES_DEPRECATION_MESSAGE = "[types removal] " + "Specifying types in multi term vector requests is deprecated."; @Override