Skip to content

Commit 44de9cb

Browse files
martijnvgkcm
authored andcommitted
[CCR] Refactor stats APIs (#34912)
* Changed the auto follow stats to also include follow stats. * Renamed the auto follow stats api to stats api and changed its url path from `/_ccr/auto_follow/stats` `/_ccr/stats`. * Removed `/_ccr/stats` url path for the follow stats api, which makes the index parameter a required parameter. * Fixed docs.
1 parent 6362315 commit 44de9cb

File tree

27 files changed

+380
-623
lines changed

27 files changed

+380
-623
lines changed

docs/reference/ccr/apis/auto-follow/get-auto-follow-stats.asciidoc

-46
This file was deleted.

docs/reference/ccr/apis/follow/get-follow-stats.asciidoc

+1-7
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ POST /follower_index/_ccr/pause_follow
3838
3939
//////////////////////////
4040

41-
[source,js]
42-
--------------------------------------------------
43-
GET /_ccr/stats
44-
--------------------------------------------------
45-
// CONSOLE
46-
4741
[source,js]
4842
--------------------------------------------------
4943
GET /<index>/_ccr/stats
@@ -186,7 +180,7 @@ This example retrieves follower stats:
186180

187181
[source,js]
188182
--------------------------------------------------
189-
GET /_ccr/stats
183+
GET /follower_index/_ccr/stats
190184
--------------------------------------------------
191185
// CONSOLE
192186

x-pack/plugin/ccr/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ public void testAutoFollowPatterns() throws Exception {
102102
}
103103

104104
assertBusy(() -> {
105-
Request statsRequest = new Request("GET", "/_ccr/auto_follow/stats");
106-
Map<String, ?> response = toMap(client().performRequest(statsRequest));
105+
Request statsRequest = new Request("GET", "/_ccr/stats");
106+
Map<?, ?> response = toMap(client().performRequest(statsRequest));
107+
response = (Map<?, ?>) response.get("auto_follow_stats");
107108
assertThat(response.get("number_of_successful_follow_indices"), equalTo(1));
108109

109110
ensureYellow("logs-20190101");

x-pack/plugin/ccr/qa/rest/src/test/resources/rest-api-spec/test/ccr/auto_follow_stats.yml

-10
This file was deleted.

x-pack/plugin/ccr/qa/rest/src/test/resources/rest-api-spec/test/ccr/follow_stats.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
# we can not reliably wait for replication to occur so we test the endpoint without indexing any documents
4747
- do:
48-
ccr.stats:
48+
ccr.follow_stats:
4949
index: bar
5050
- match: { indices.0.index: "bar" }
5151
- match: { indices.0.shards.0.leader_index: "foo" }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"Test stats":
3+
- do:
4+
ccr.stats: {}
5+
6+
- match: { auto_follow_stats.number_of_successful_follow_indices: 0 }
7+
- match: { auto_follow_stats.number_of_failed_follow_indices: 0 }
8+
- match: { auto_follow_stats.number_of_failed_remote_cluster_state_requests: 0 }
9+
- length: { auto_follow_stats.recent_auto_follow_errors: 0 }
10+
- length: { follow_stats.indices: 0 }
11+

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/Ccr.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343
import org.elasticsearch.xpack.ccr.action.TransportGetAutoFollowPatternAction;
4444
import org.elasticsearch.xpack.ccr.action.TransportUnfollowAction;
4545
import org.elasticsearch.xpack.ccr.rest.RestGetAutoFollowPatternAction;
46-
import org.elasticsearch.xpack.ccr.action.TransportAutoFollowStatsAction;
46+
import org.elasticsearch.xpack.ccr.action.TransportStatsAction;
4747
import org.elasticsearch.xpack.ccr.rest.RestAutoFollowStatsAction;
4848
import org.elasticsearch.xpack.ccr.rest.RestUnfollowAction;
49-
import org.elasticsearch.xpack.core.ccr.action.AutoFollowStatsAction;
49+
import org.elasticsearch.xpack.core.ccr.action.StatsAction;
5050
import org.elasticsearch.xpack.core.ccr.action.DeleteAutoFollowPatternAction;
5151
import org.elasticsearch.xpack.core.ccr.action.GetAutoFollowPatternAction;
5252
import org.elasticsearch.xpack.core.ccr.action.PutAutoFollowPatternAction;
@@ -164,7 +164,7 @@ public List<PersistentTasksExecutor<?>> getPersistentTasksExecutor(ClusterServic
164164
new ActionHandler<>(ShardChangesAction.INSTANCE, ShardChangesAction.TransportAction.class),
165165
// stats action
166166
new ActionHandler<>(FollowStatsAction.INSTANCE, TransportFollowStatsAction.class),
167-
new ActionHandler<>(AutoFollowStatsAction.INSTANCE, TransportAutoFollowStatsAction.class),
167+
new ActionHandler<>(StatsAction.INSTANCE, TransportStatsAction.class),
168168
// follow actions
169169
new ActionHandler<>(PutFollowAction.INSTANCE, TransportPutFollowAction.class),
170170
new ActionHandler<>(ResumeFollowAction.INSTANCE, TransportResumeFollowAction.class),
+24-15
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
import org.elasticsearch.action.ActionListener;
1010
import org.elasticsearch.action.support.ActionFilters;
1111
import org.elasticsearch.action.support.master.TransportMasterNodeAction;
12+
import org.elasticsearch.client.Client;
1213
import org.elasticsearch.cluster.ClusterState;
1314
import org.elasticsearch.cluster.block.ClusterBlockException;
1415
import org.elasticsearch.cluster.block.ClusterBlockLevel;
1516
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
1617
import org.elasticsearch.cluster.service.ClusterService;
18+
import org.elasticsearch.common.CheckedConsumer;
1719
import org.elasticsearch.common.inject.Inject;
1820
import org.elasticsearch.common.settings.Settings;
1921
import org.elasticsearch.license.LicenseUtils;
@@ -23,37 +25,40 @@
2325
import org.elasticsearch.xpack.ccr.Ccr;
2426
import org.elasticsearch.xpack.ccr.CcrLicenseChecker;
2527
import org.elasticsearch.xpack.core.ccr.AutoFollowStats;
26-
import org.elasticsearch.xpack.core.ccr.action.AutoFollowStatsAction;
28+
import org.elasticsearch.xpack.core.ccr.action.FollowStatsAction;
29+
import org.elasticsearch.xpack.core.ccr.action.StatsAction;
2730

2831
import java.util.Objects;
2932

30-
public class TransportAutoFollowStatsAction
31-
extends TransportMasterNodeAction<AutoFollowStatsAction.Request, AutoFollowStatsAction.Response> {
33+
public class TransportStatsAction extends TransportMasterNodeAction<StatsAction.Request, StatsAction.Response> {
3234

35+
private final Client client;
3336
private final CcrLicenseChecker ccrLicenseChecker;
3437
private final AutoFollowCoordinator autoFollowCoordinator;
3538

3639
@Inject
37-
public TransportAutoFollowStatsAction(
40+
public TransportStatsAction(
3841
Settings settings,
3942
TransportService transportService,
4043
ClusterService clusterService,
4144
ThreadPool threadPool,
4245
ActionFilters actionFilters,
4346
IndexNameExpressionResolver indexNameExpressionResolver,
4447
AutoFollowCoordinator autoFollowCoordinator,
45-
CcrLicenseChecker ccrLicenseChecker
48+
CcrLicenseChecker ccrLicenseChecker,
49+
Client client
4650
) {
4751
super(
4852
settings,
49-
AutoFollowStatsAction.NAME,
53+
StatsAction.NAME,
5054
transportService,
5155
clusterService,
5256
threadPool,
5357
actionFilters,
54-
AutoFollowStatsAction.Request::new,
58+
StatsAction.Request::new,
5559
indexNameExpressionResolver
5660
);
61+
this.client = client;
5762
this.ccrLicenseChecker = Objects.requireNonNull(ccrLicenseChecker);
5863
this.autoFollowCoordinator = Objects.requireNonNull(autoFollowCoordinator);
5964
}
@@ -64,12 +69,12 @@ protected String executor() {
6469
}
6570

6671
@Override
67-
protected AutoFollowStatsAction.Response newResponse() {
68-
return new AutoFollowStatsAction.Response();
72+
protected StatsAction.Response newResponse() {
73+
return new StatsAction.Response();
6974
}
7075

7176
@Override
72-
protected void doExecute(Task task, AutoFollowStatsAction.Request request, ActionListener<AutoFollowStatsAction.Response> listener) {
77+
protected void doExecute(Task task, StatsAction.Request request, ActionListener<StatsAction.Response> listener) {
7378
if (ccrLicenseChecker.isCcrAllowed() == false) {
7479
listener.onFailure(LicenseUtils.newComplianceException("ccr"));
7580
return;
@@ -79,16 +84,20 @@ protected void doExecute(Task task, AutoFollowStatsAction.Request request, Actio
7984

8085
@Override
8186
protected void masterOperation(
82-
AutoFollowStatsAction.Request request,
87+
StatsAction.Request request,
8388
ClusterState state,
84-
ActionListener<AutoFollowStatsAction.Response> listener
89+
ActionListener<StatsAction.Response> listener
8590
) throws Exception {
86-
AutoFollowStats stats = autoFollowCoordinator.getStats();
87-
listener.onResponse(new AutoFollowStatsAction.Response(stats));
91+
CheckedConsumer<FollowStatsAction.StatsResponses, Exception> handler = statsResponse -> {
92+
AutoFollowStats stats = autoFollowCoordinator.getStats();
93+
listener.onResponse(new StatsAction.Response(stats, statsResponse));
94+
};
95+
FollowStatsAction.StatsRequest statsRequest = new FollowStatsAction.StatsRequest();
96+
client.execute(FollowStatsAction.INSTANCE, statsRequest, ActionListener.wrap(handler, listener::onFailure));
8897
}
8998

9099
@Override
91-
protected ClusterBlockException checkBlock(AutoFollowStatsAction.Request request, ClusterState state) {
100+
protected ClusterBlockException checkBlock(StatsAction.Request request, ClusterState state) {
92101
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ);
93102
}
94103
}

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestAutoFollowStatsAction.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
import org.elasticsearch.rest.RestController;
1313
import org.elasticsearch.rest.RestRequest;
1414
import org.elasticsearch.rest.action.RestToXContentListener;
15-
import org.elasticsearch.xpack.core.ccr.action.AutoFollowStatsAction;
15+
import org.elasticsearch.xpack.core.ccr.action.StatsAction;
1616

1717
import java.io.IOException;
1818

1919
public class RestAutoFollowStatsAction extends BaseRestHandler {
2020

2121
public RestAutoFollowStatsAction(final Settings settings, final RestController controller) {
2222
super(settings);
23-
controller.registerHandler(RestRequest.Method.GET, "/_ccr/auto_follow/stats", this);
23+
controller.registerHandler(RestRequest.Method.GET, "/_ccr/stats", this);
2424
}
2525

2626
@Override
@@ -30,8 +30,8 @@ public String getName() {
3030

3131
@Override
3232
protected RestChannelConsumer prepareRequest(final RestRequest restRequest, final NodeClient client) throws IOException {
33-
final AutoFollowStatsAction.Request request = new AutoFollowStatsAction.Request();
34-
return channel -> client.execute(AutoFollowStatsAction.INSTANCE, request, new RestToXContentListener<>(channel));
33+
final StatsAction.Request request = new StatsAction.Request();
34+
return channel -> client.execute(StatsAction.INSTANCE, request, new RestToXContentListener<>(channel));
3535
}
3636

3737
}

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowStatsAction.java

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public class RestFollowStatsAction extends BaseRestHandler {
2121

2222
public RestFollowStatsAction(final Settings settings, final RestController controller) {
2323
super(settings);
24-
controller.registerHandler(RestRequest.Method.GET, "/_ccr/stats", this);
2524
controller.registerHandler(RestRequest.Method.GET, "/{index}/_ccr/stats", this);
2625
}
2726

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import org.elasticsearch.xpack.CcrIntegTestCase;
2020
import org.elasticsearch.xpack.ccr.action.ShardFollowTask;
2121
import org.elasticsearch.xpack.core.ccr.AutoFollowStats;
22-
import org.elasticsearch.xpack.core.ccr.action.AutoFollowStatsAction;
22+
import org.elasticsearch.xpack.core.ccr.action.StatsAction;
2323
import org.elasticsearch.xpack.core.ccr.action.DeleteAutoFollowPatternAction;
2424
import org.elasticsearch.xpack.core.ccr.action.PutAutoFollowPatternAction;
2525

@@ -260,8 +260,8 @@ private void deleteAutoFollowPatternSetting() {
260260
}
261261

262262
private AutoFollowStats getAutoFollowStats() {
263-
AutoFollowStatsAction.Request request = new AutoFollowStatsAction.Request();
264-
return followerClient().execute(AutoFollowStatsAction.INSTANCE, request).actionGet().getStats();
263+
StatsAction.Request request = new StatsAction.Request();
264+
return followerClient().execute(StatsAction.INSTANCE, request).actionGet().getAutoFollowStats();
265265
}
266266

267267
private void createLeaderIndex(String index, Settings settings) {

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowStatsResponseTests.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,28 @@
77

88
import org.elasticsearch.test.AbstractStreamableTestCase;
99
import org.elasticsearch.xpack.core.ccr.AutoFollowStats;
10-
import org.elasticsearch.xpack.core.ccr.action.AutoFollowStatsAction;
10+
import org.elasticsearch.xpack.core.ccr.action.FollowStatsAction;
11+
import org.elasticsearch.xpack.core.ccr.action.StatsAction;
1112

1213
import static org.elasticsearch.xpack.ccr.action.AutoFollowStatsTests.randomReadExceptions;
14+
import static org.elasticsearch.xpack.ccr.action.StatsResponsesTests.createStatsResponse;
1315

14-
public class AutoFollowStatsResponseTests extends AbstractStreamableTestCase<AutoFollowStatsAction.Response> {
16+
public class AutoFollowStatsResponseTests extends AbstractStreamableTestCase<StatsAction.Response> {
1517

1618
@Override
17-
protected AutoFollowStatsAction.Response createBlankInstance() {
18-
return new AutoFollowStatsAction.Response();
19+
protected StatsAction.Response createBlankInstance() {
20+
return new StatsAction.Response();
1921
}
2022

2123
@Override
22-
protected AutoFollowStatsAction.Response createTestInstance() {
24+
protected StatsAction.Response createTestInstance() {
2325
AutoFollowStats autoFollowStats = new AutoFollowStats(
2426
randomNonNegativeLong(),
2527
randomNonNegativeLong(),
2628
randomNonNegativeLong(),
2729
randomReadExceptions()
2830
);
29-
return new AutoFollowStatsAction.Response(autoFollowStats);
31+
FollowStatsAction.StatsResponses statsResponse = createStatsResponse();
32+
return new StatsAction.Response(autoFollowStats, statsResponse);
3033
}
3134
}

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/StatsResponsesTests.java

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ protected FollowStatsAction.StatsResponses createBlankInstance() {
2323

2424
@Override
2525
protected FollowStatsAction.StatsResponses createTestInstance() {
26+
return createStatsResponse();
27+
}
28+
29+
static FollowStatsAction.StatsResponses createStatsResponse() {
2630
int numResponses = randomIntBetween(0, 8);
2731
List<FollowStatsAction.StatsResponse> responses = new ArrayList<>(numResponses);
2832
for (int i = 0; i < numResponses; i++) {

0 commit comments

Comments
 (0)