Browse Source

Remove Repository Stats API (#62309)

Now the Repository Stats API is deprecated in 7.10.0 (#62297) 
we can remove it in 8.0.0.

I'm labeling this as >breaking to respect the development 
process but we're talking about an experimental API that 
was never released (behind a feature flag).
Tanguy Leroux 5 years ago
parent
commit
be0dd124c9

+ 0 - 86
x-pack/plugin/searchable-snapshots/qa/rest/src/test/resources/rest-api-spec/test/repository_stats.yml

@@ -1,86 +0,0 @@
----
-setup:
-
-  - do:
-      indices.create:
-        index: docs
-        body:
-          settings:
-            number_of_shards:   1
-            number_of_replicas: 0
-
-  - do:
-      bulk:
-        body:
-          - index:
-              _index: docs
-              _id:    1
-          - field: foo
-          - index:
-              _index: docs
-              _id:    2
-          - field: bar
-          - index:
-              _index: docs
-              _id:    3
-          - field: baz
-
-  - do:
-      snapshot.create_repository:
-        repository: repository-fs
-        body:
-          type: fs
-          settings:
-            location: "repository-fs"
-
-  # Remove the snapshot if a previous test failed to delete it.
-  # Useful for third party tests that runs the test against a real external service.
-  - do:
-      snapshot.delete:
-        repository: repository-fs
-        snapshot: snapshot
-        ignore: 404
-
-  - do:
-      snapshot.create:
-        repository: repository-fs
-        snapshot: snapshot
-        wait_for_completion: true
-
-  - do:
-      indices.delete:
-        index: docs
----
-teardown:
-
-  - do:
-      snapshot.delete:
-        repository: repository-fs
-        snapshot: snapshot
-        ignore: 404
-
-  - do:
-      snapshot.delete_repository:
-        repository: repository-fs
-
----
-"Tests repository stats":
-  - skip:
-      version: " - 7.9.99"
-      reason:  Deprecated in 7.10.0 and removed in 8.0.0, will not issue warnings before 7.10.0
-      features: "warnings"
-
-  - do:
-      snapshot.restore:
-        repository: repository-fs
-        snapshot: snapshot
-        wait_for_completion: true
-
-  - do:
-      warnings:
-        - "[/_snapshot/{repository}/_stats] is deprecated, use the Repositories Metering API [/_nodes/{nodeId}/_repositories_metering] in the future."
-      searchable_snapshots.repository_stats:
-        repository: repository-fs
-
-  - is_true: _all
-  - is_true: nodes

+ 1 - 6
x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshots.java

@@ -56,17 +56,14 @@ import org.elasticsearch.xpack.core.action.XPackInfoFeatureAction;
 import org.elasticsearch.xpack.core.action.XPackUsageFeatureAction;
 import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotAction;
 import org.elasticsearch.xpack.searchablesnapshots.action.ClearSearchableSnapshotsCacheAction;
-import org.elasticsearch.xpack.searchablesnapshots.action.RepositoryStatsAction;
 import org.elasticsearch.xpack.searchablesnapshots.action.SearchableSnapshotsStatsAction;
 import org.elasticsearch.xpack.searchablesnapshots.action.TransportClearSearchableSnapshotsCacheAction;
 import org.elasticsearch.xpack.searchablesnapshots.action.TransportMountSearchableSnapshotAction;
-import org.elasticsearch.xpack.searchablesnapshots.action.TransportRepositoryStatsAction;
 import org.elasticsearch.xpack.searchablesnapshots.action.TransportSearchableSnapshotsStatsAction;
 import org.elasticsearch.xpack.searchablesnapshots.cache.CacheService;
 import org.elasticsearch.xpack.searchablesnapshots.cache.NodeEnvironmentCacheCleaner;
 import org.elasticsearch.xpack.searchablesnapshots.rest.RestClearSearchableSnapshotsCacheAction;
 import org.elasticsearch.xpack.searchablesnapshots.rest.RestMountSearchableSnapshotAction;
-import org.elasticsearch.xpack.searchablesnapshots.rest.RestRepositoryStatsAction;
 import org.elasticsearch.xpack.searchablesnapshots.rest.RestSearchableSnapshotsStatsAction;
 
 import java.util.Collection;
@@ -265,7 +262,6 @@ public class SearchableSnapshots extends Plugin implements IndexStorePlugin, Eng
             new ActionHandler<>(SearchableSnapshotsStatsAction.INSTANCE, TransportSearchableSnapshotsStatsAction.class),
             new ActionHandler<>(ClearSearchableSnapshotsCacheAction.INSTANCE, TransportClearSearchableSnapshotsCacheAction.class),
             new ActionHandler<>(MountSearchableSnapshotAction.INSTANCE, TransportMountSearchableSnapshotAction.class),
-            new ActionHandler<>(RepositoryStatsAction.INSTANCE, TransportRepositoryStatsAction.class),
             new ActionHandler<>(XPackUsageFeatureAction.SEARCHABLE_SNAPSHOTS, SearchableSnapshotsUsageTransportAction.class),
             new ActionHandler<>(XPackInfoFeatureAction.SEARCHABLE_SNAPSHOTS, SearchableSnapshotsInfoTransportAction.class)
         );
@@ -283,8 +279,7 @@ public class SearchableSnapshots extends Plugin implements IndexStorePlugin, Eng
         return List.of(
             new RestSearchableSnapshotsStatsAction(),
             new RestClearSearchableSnapshotsCacheAction(),
-            new RestMountSearchableSnapshotAction(),
-            new RestRepositoryStatsAction()
+            new RestMountSearchableSnapshotAction()
         );
     }
 

+ 0 - 23
x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/RepositoryStatsAction.java

@@ -1,23 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
- */
-
-package org.elasticsearch.xpack.searchablesnapshots.action;
-
-import org.elasticsearch.action.ActionType;
-
-/**
- * @deprecated This action is superseded by the Repositories Metering action
- */
-@Deprecated
-public class RepositoryStatsAction extends ActionType<RepositoryStatsResponse> {
-
-    public static final RepositoryStatsAction INSTANCE = new RepositoryStatsAction();
-    public static final String NAME = "cluster:admin/repository/stats";
-
-    private RepositoryStatsAction() {
-        super(NAME, RepositoryStatsResponse::new);
-    }
-}

+ 0 - 37
x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/RepositoryStatsNodeRequest.java

@@ -1,37 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
- */
-
-package org.elasticsearch.xpack.searchablesnapshots.action;
-
-import org.elasticsearch.common.io.stream.StreamInput;
-import org.elasticsearch.common.io.stream.StreamOutput;
-import org.elasticsearch.transport.TransportRequest;
-
-import java.io.IOException;
-
-@Deprecated
-public class RepositoryStatsNodeRequest extends TransportRequest {
-
-    private final String repository;
-
-    public RepositoryStatsNodeRequest(String repository) {
-        this.repository = repository;
-    }
-
-    public RepositoryStatsNodeRequest(StreamInput in) throws IOException {
-        this.repository = in.readString();
-    }
-
-    public String getRepository() {
-        return repository;
-    }
-
-    @Override
-    public void writeTo(StreamOutput out) throws IOException {
-        out.writeString(repository);
-    }
-
-}

+ 0 - 54
x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/RepositoryStatsNodeResponse.java

@@ -1,54 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
- */
-
-package org.elasticsearch.xpack.searchablesnapshots.action;
-
-import org.elasticsearch.action.support.nodes.BaseNodeResponse;
-import org.elasticsearch.cluster.node.DiscoveryNode;
-import org.elasticsearch.common.io.stream.StreamInput;
-import org.elasticsearch.common.io.stream.StreamOutput;
-import org.elasticsearch.common.xcontent.ToXContentObject;
-import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.repositories.RepositoryStats;
-
-import java.io.IOException;
-
-@Deprecated
-public class RepositoryStatsNodeResponse extends BaseNodeResponse implements ToXContentObject {
-
-    private final RepositoryStats repositoryStats;
-
-    public RepositoryStatsNodeResponse(StreamInput in) throws IOException {
-        super(in);
-        repositoryStats = new RepositoryStats(in);
-    }
-
-    public RepositoryStatsNodeResponse(DiscoveryNode node, RepositoryStats repositoryStats) {
-        super(node);
-        this.repositoryStats = repositoryStats;
-    }
-
-    @Override
-    public void writeTo(StreamOutput out) throws IOException {
-        super.writeTo(out);
-        repositoryStats.writeTo(out);
-    }
-
-    @Override
-    public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
-        builder.startObject();
-        if (repositoryStats.requestCounts.isEmpty() == false) {
-            builder.field("stats", repositoryStats.requestCounts);
-        }
-        builder.endObject();
-        return builder;
-    }
-
-    public RepositoryStats getRepositoryStats() {
-        return repositoryStats;
-    }
-
-}

+ 0 - 40
x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/RepositoryStatsRequest.java

@@ -1,40 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
- */
-
-package org.elasticsearch.xpack.searchablesnapshots.action;
-
-import org.elasticsearch.action.support.nodes.BaseNodesRequest;
-import org.elasticsearch.common.io.stream.StreamInput;
-import org.elasticsearch.common.io.stream.StreamOutput;
-
-import java.io.IOException;
-
-@Deprecated
-public class RepositoryStatsRequest extends BaseNodesRequest<RepositoryStatsRequest> {
-
-    private final String repository;
-
-    public RepositoryStatsRequest(StreamInput in) throws IOException {
-        super(in);
-        repository = in.readString();
-    }
-
-    public RepositoryStatsRequest(String repository, String... nodesIds) {
-        super(nodesIds);
-        this.repository = repository;
-    }
-
-    @Override
-    public void writeTo(StreamOutput out) throws IOException {
-        super.writeTo(out);
-        out.writeString(repository);
-    }
-
-    public String getRepository() {
-        return repository;
-    }
-
-}

+ 0 - 67
x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/RepositoryStatsResponse.java

@@ -1,67 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
- */
-
-package org.elasticsearch.xpack.searchablesnapshots.action;
-
-import org.elasticsearch.action.FailedNodeException;
-import org.elasticsearch.action.support.nodes.BaseNodesResponse;
-import org.elasticsearch.cluster.ClusterName;
-import org.elasticsearch.common.io.stream.StreamInput;
-import org.elasticsearch.common.io.stream.StreamOutput;
-import org.elasticsearch.common.xcontent.ToXContentObject;
-import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.repositories.RepositoryStats;
-
-import java.io.IOException;
-import java.util.List;
-
-@Deprecated
-public class RepositoryStatsResponse extends BaseNodesResponse<RepositoryStatsNodeResponse> implements ToXContentObject {
-
-    private final RepositoryStats globalStats;
-
-    public RepositoryStatsResponse(ClusterName clusterName, List<RepositoryStatsNodeResponse> nodes, List<FailedNodeException> failures) {
-        super(clusterName, nodes, failures);
-        globalStats = computeGlobalStats(getNodes());
-    }
-
-    public RepositoryStatsResponse(StreamInput in) throws IOException {
-        super(in);
-        globalStats = computeGlobalStats(getNodes());
-    }
-
-    private static RepositoryStats computeGlobalStats(List<RepositoryStatsNodeResponse> nodes) {
-        if (nodes.isEmpty()) {
-            return RepositoryStats.EMPTY_STATS;
-        } else {
-            return nodes.stream().map(RepositoryStatsNodeResponse::getRepositoryStats).reduce(RepositoryStats::merge).get();
-        }
-    }
-
-    @Override
-    protected List<RepositoryStatsNodeResponse> readNodesFrom(StreamInput in) throws IOException {
-        return in.readList(RepositoryStatsNodeResponse::new);
-    }
-
-    @Override
-    protected void writeNodesTo(StreamOutput out, List<RepositoryStatsNodeResponse> nodes) throws IOException {
-        out.writeList(nodes);
-    }
-
-    @Override
-    public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
-        builder.startObject();
-        builder.field("_all", globalStats.requestCounts);
-        builder.startArray("nodes");
-        for (RepositoryStatsNodeResponse node : getNodes()) {
-            node.toXContent(builder, params);
-        }
-        builder.endArray();
-        builder.endObject();
-
-        return builder;
-    }
-}

+ 0 - 93
x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/TransportRepositoryStatsAction.java

@@ -1,93 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
- */
-
-package org.elasticsearch.xpack.searchablesnapshots.action;
-
-import org.elasticsearch.action.FailedNodeException;
-import org.elasticsearch.action.support.ActionFilters;
-import org.elasticsearch.action.support.nodes.TransportNodesAction;
-import org.elasticsearch.cluster.service.ClusterService;
-import org.elasticsearch.common.inject.Inject;
-import org.elasticsearch.common.io.stream.StreamInput;
-import org.elasticsearch.license.XPackLicenseState;
-import org.elasticsearch.repositories.RepositoriesService;
-import org.elasticsearch.repositories.Repository;
-import org.elasticsearch.repositories.RepositoryStats;
-import org.elasticsearch.tasks.Task;
-import org.elasticsearch.threadpool.ThreadPool;
-import org.elasticsearch.transport.TransportService;
-import org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.Objects;
-
-/**
- * @deprecated This API is superseded by the Repositories Metering API
- */
-@Deprecated
-public class TransportRepositoryStatsAction extends TransportNodesAction<
-    RepositoryStatsRequest,
-    RepositoryStatsResponse,
-    RepositoryStatsNodeRequest,
-    RepositoryStatsNodeResponse> {
-
-    private final RepositoriesService repositoriesService;
-    private final XPackLicenseState licenseState;
-
-    @Inject
-    public TransportRepositoryStatsAction(
-        ThreadPool threadPool,
-        ClusterService clusterService,
-        TransportService transportService,
-        ActionFilters actionFilters,
-        RepositoriesService repositoriesService,
-        XPackLicenseState licenseState
-    ) {
-        super(
-            RepositoryStatsAction.NAME,
-            threadPool,
-            clusterService,
-            transportService,
-            actionFilters,
-            RepositoryStatsRequest::new,
-            RepositoryStatsNodeRequest::new,
-            ThreadPool.Names.SAME,
-            RepositoryStatsNodeResponse.class
-        );
-        this.repositoriesService = repositoriesService;
-        this.licenseState = Objects.requireNonNull(licenseState);
-    }
-
-    @Override
-    protected RepositoryStatsResponse newResponse(
-        RepositoryStatsRequest request,
-        List<RepositoryStatsNodeResponse> nodes,
-        List<FailedNodeException> failures
-    ) {
-        return new RepositoryStatsResponse(clusterService.getClusterName(), nodes, failures);
-    }
-
-    @Override
-    protected RepositoryStatsNodeRequest newNodeRequest(RepositoryStatsRequest request) {
-        return new RepositoryStatsNodeRequest(request.getRepository());
-    }
-
-    @Override
-    protected RepositoryStatsNodeResponse newNodeResponse(StreamInput in) throws IOException {
-        return new RepositoryStatsNodeResponse(in);
-    }
-
-    @Override
-    protected RepositoryStatsNodeResponse nodeOperation(RepositoryStatsNodeRequest request, Task task) {
-        SearchableSnapshots.ensureValidLicense(licenseState);
-        if (clusterService.localNode().isMasterNode() == false && clusterService.localNode().isDataNode() == false) {
-            return new RepositoryStatsNodeResponse(clusterService.localNode(), RepositoryStats.EMPTY_STATS);
-        }
-        final Repository repository = repositoriesService.repository(request.getRepository());
-        return new RepositoryStatsNodeResponse(clusterService.localNode(), repository.stats());
-    }
-}

+ 0 - 58
x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/rest/RestRepositoryStatsAction.java

@@ -1,58 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
- */
-
-package org.elasticsearch.xpack.searchablesnapshots.rest;
-
-import org.elasticsearch.client.node.NodeClient;
-import org.elasticsearch.rest.BaseRestHandler;
-import org.elasticsearch.rest.RestHandler;
-import org.elasticsearch.rest.RestRequest;
-import org.elasticsearch.rest.action.RestToXContentListener;
-import org.elasticsearch.xpack.searchablesnapshots.action.RepositoryStatsAction;
-import org.elasticsearch.xpack.searchablesnapshots.action.RepositoryStatsRequest;
-
-import java.util.Collections;
-import java.util.List;
-
-import static org.elasticsearch.rest.RestRequest.Method.GET;
-
-/**
- * @deprecated This API is superseded by the Repositories Metering API
- */
-@Deprecated
-public class RestRepositoryStatsAction extends BaseRestHandler {
-
-    private static final String ENDPOINT = "/_snapshot/{repository}/_stats";
-
-    @Override
-    public String getName() {
-        return "repository_stats_action";
-    }
-
-    @Override
-    public List<RestHandler.Route> routes() {
-        return Collections.emptyList();
-    }
-
-    @Override
-    public List<DeprecatedRoute> deprecatedRoutes() {
-        return List.of(
-            new DeprecatedRoute(
-                GET,
-                ENDPOINT,
-                '['
-                    + ENDPOINT
-                    + "] is deprecated, use the Repositories Metering API [/_nodes/{nodeId}/_repositories_metering] in the future."
-            )
-        );
-    }
-
-    @Override
-    protected BaseRestHandler.RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) {
-        final RepositoryStatsRequest repositoryStatsRequest = new RepositoryStatsRequest(request.param("repository"));
-        return channel -> client.execute(RepositoryStatsAction.INSTANCE, repositoryStatsRequest, new RestToXContentListener<>(channel));
-    }
-}

+ 0 - 25
x-pack/plugin/src/test/resources/rest-api-spec/api/searchable_snapshots.repository_stats.json

@@ -1,25 +0,0 @@
-{
-  "searchable_snapshots.repository_stats": {
-    "documentation": {
-      "url": "https://www.elastic.co/guide/en/elasticsearch/reference/master/searchable-snapshots-apis.html",
-      "description": "DEPRECATED: This API is replaced by the Repositories Metering API."
-    },
-    "stability": "experimental",
-    "url": {
-      "paths": [
-        {
-          "path": "/_snapshot/{repository}/_stats",
-          "methods": [
-            "GET"
-          ],
-          "parts": {
-            "repository": {
-              "type": "string",
-              "description": "The repository for which to get the stats for"
-            }
-          }
-        }
-      ]
-    }
-  }
-}