Skip to content

Commit

Permalink
[Rest Api Compatibility] Typed indexing stats (#74181)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pgomulka authored Jun 17, 2021
1 parent 2350369 commit fdc301f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 11 deletions.
25 changes: 15 additions & 10 deletions rest-api-spec/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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',
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Route> routes() {
Expand Down Expand Up @@ -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<String> metrics = Strings.tokenizeByCommaToSet(request.param("metric", "_all"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Route> routes() {
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fdc301f

Please sign in to comment.