From b9331d3dcbca34f0262a7dbb624d20e97a7efc66 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Tue, 8 Jan 2019 13:07:23 +0100 Subject: [PATCH] [CCR] Follow stats api should return a 404 when requesting stats for non existing indices. Currently it returns an empty response with a 200 response code. Closes #37021 --- .../resources/rest-api-spec/test/ccr/follow_stats.yml | 10 ++++++++++ .../xpack/ccr/action/TransportFollowStatsAction.java | 11 ++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/ccr/qa/rest/src/test/resources/rest-api-spec/test/ccr/follow_stats.yml b/x-pack/plugin/ccr/qa/rest/src/test/resources/rest-api-spec/test/ccr/follow_stats.yml index aa63c804aba21..5b3e6c18ef29b 100644 --- a/x-pack/plugin/ccr/qa/rest/src/test/resources/rest-api-spec/test/ccr/follow_stats.yml +++ b/x-pack/plugin/ccr/qa/rest/src/test/resources/rest-api-spec/test/ccr/follow_stats.yml @@ -43,6 +43,12 @@ - is_true: follow_index_shards_acked - is_true: index_following_started + - do: + ccr.follow_stats: + index: _all + - length: { indices: 1 } + - match: { indices.0.index: "bar" } + # we can not reliably wait for replication to occur so we test the endpoint without indexing any documents - do: ccr.follow_stats: @@ -77,3 +83,7 @@ index: bar - is_true: acknowledged + - do: + catch: missing + ccr.follow_stats: + index: unknown diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportFollowStatsAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportFollowStatsAction.java index 8ab66aec8e80b..8a3a16afb33a5 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportFollowStatsAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportFollowStatsAction.java @@ -10,8 +10,10 @@ import org.elasticsearch.action.FailedNodeException; import org.elasticsearch.action.TaskOperationFailure; import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.tasks.TransportTasksAction; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.license.LicenseUtils; @@ -37,13 +39,15 @@ public class TransportFollowStatsAction extends TransportTasksAction< FollowStatsAction.StatsResponses, FollowStatsAction.StatsResponse> { private final CcrLicenseChecker ccrLicenseChecker; + private final IndexNameExpressionResolver resolver; @Inject public TransportFollowStatsAction( final ClusterService clusterService, final TransportService transportService, final ActionFilters actionFilters, - final CcrLicenseChecker ccrLicenseChecker) { + final CcrLicenseChecker ccrLicenseChecker, + final IndexNameExpressionResolver resolver) { super( FollowStatsAction.NAME, clusterService, @@ -54,6 +58,7 @@ public TransportFollowStatsAction( FollowStatsAction.StatsResponse::new, Ccr.CCR_THREAD_POOL_NAME); this.ccrLicenseChecker = Objects.requireNonNull(ccrLicenseChecker); + this.resolver = resolver; } @Override @@ -65,6 +70,10 @@ protected void doExecute( listener.onFailure(LicenseUtils.newComplianceException("ccr")); return; } + + String[] concreteIndices = + resolver.concreteIndexNames(clusterService.state(), IndicesOptions.strictExpandOpenAndForbidClosed(), request.indices()); + request.setIndices(concreteIndices); super.doExecute(task, request, listener); }