diff --git a/docs/reference/ccr/apis/auto-follow/get-auto-follow-stats.asciidoc b/docs/reference/ccr/apis/auto-follow/get-auto-follow-stats.asciidoc
deleted file mode 100644
index 85c6775af1cab..0000000000000
--- a/docs/reference/ccr/apis/auto-follow/get-auto-follow-stats.asciidoc
+++ /dev/null
@@ -1,46 +0,0 @@
-[role="xpack"]
-[testenv="platinum"]
-[[ccr-get-auto-follow-stats]]
-=== Get Auto-Follow Stats API
-++++
-Get Auto-Follow Stats
-++++
-
-Get auto-follow stats.
-
-==== Description
-
-This API gets stats about auto-follow patterns.
-
-==== Request
-
-[source,js]
---------------------------------------------------
-GET /_ccr/auto_follow/stats
---------------------------------------------------
-// CONSOLE
-// TEST
-
-==== Example
-
-This example retrieves stats about auto-follow patterns:
-
-[source,js]
---------------------------------------------------
-GET /_ccr/auto_follow/stats
---------------------------------------------------
-// CONSOLE
-// TEST
-
-The API returns the following result:
-
-[source,js]
---------------------------------------------------
-{
- "number_of_successful_follow_indices" : 16,
- "number_of_failed_follow_indices" : 0,
- "number_of_failed_remote_cluster_state_requests" : 0,
- "recent_auto_follow_errors" : [ ]
-}
---------------------------------------------------
-// TESTRESPONSE[s/"number_of_successful_follow_indices" : 16/"number_of_successful_follow_indices" : $body.number_of_successful_follow_indices/]
diff --git a/docs/reference/ccr/apis/follow/get-follow-stats.asciidoc b/docs/reference/ccr/apis/follow/get-follow-stats.asciidoc
index efbaeecb712d5..0efa156b95a49 100644
--- a/docs/reference/ccr/apis/follow/get-follow-stats.asciidoc
+++ b/docs/reference/ccr/apis/follow/get-follow-stats.asciidoc
@@ -38,12 +38,6 @@ POST /follower_index/_ccr/pause_follow
//////////////////////////
-[source,js]
---------------------------------------------------
-GET /_ccr/stats
---------------------------------------------------
-// CONSOLE
-
[source,js]
--------------------------------------------------
GET //_ccr/stats
@@ -186,7 +180,7 @@ This example retrieves follower stats:
[source,js]
--------------------------------------------------
-GET /_ccr/stats
+GET /follower_index/_ccr/stats
--------------------------------------------------
// CONSOLE
diff --git a/x-pack/plugin/ccr/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java b/x-pack/plugin/ccr/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java
index ed3a03f0b17f5..8b1ed236c566b 100644
--- a/x-pack/plugin/ccr/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java
+++ b/x-pack/plugin/ccr/qa/multi-cluster/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java
@@ -102,8 +102,9 @@ public void testAutoFollowPatterns() throws Exception {
}
assertBusy(() -> {
- Request statsRequest = new Request("GET", "/_ccr/auto_follow/stats");
- Map response = toMap(client().performRequest(statsRequest));
+ Request statsRequest = new Request("GET", "/_ccr/stats");
+ Map, ?> response = toMap(client().performRequest(statsRequest));
+ response = (Map, ?>) response.get("auto_follow_stats");
assertThat(response.get("number_of_successful_follow_indices"), equalTo(1));
ensureYellow("logs-20190101");
diff --git a/x-pack/plugin/ccr/qa/rest/src/test/resources/rest-api-spec/test/ccr/auto_follow_stats.yml b/x-pack/plugin/ccr/qa/rest/src/test/resources/rest-api-spec/test/ccr/auto_follow_stats.yml
deleted file mode 100644
index 4d26eb1ff2460..0000000000000
--- a/x-pack/plugin/ccr/qa/rest/src/test/resources/rest-api-spec/test/ccr/auto_follow_stats.yml
+++ /dev/null
@@ -1,10 +0,0 @@
----
-"Test autofollow stats":
- - do:
- ccr.auto_follow_stats: {}
-
- - match: { number_of_successful_follow_indices: 0 }
- - match: { number_of_failed_follow_indices: 0 }
- - match: { number_of_failed_remote_cluster_state_requests: 0 }
- - length: { recent_auto_follow_errors: 0 }
-
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 97c538b60bc4e..aa63c804aba21 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
@@ -45,7 +45,7 @@
# we can not reliably wait for replication to occur so we test the endpoint without indexing any documents
- do:
- ccr.stats:
+ ccr.follow_stats:
index: bar
- match: { indices.0.index: "bar" }
- match: { indices.0.shards.0.leader_index: "foo" }
diff --git a/x-pack/plugin/ccr/qa/rest/src/test/resources/rest-api-spec/test/ccr/stats.yml b/x-pack/plugin/ccr/qa/rest/src/test/resources/rest-api-spec/test/ccr/stats.yml
new file mode 100644
index 0000000000000..e9f5c0306df54
--- /dev/null
+++ b/x-pack/plugin/ccr/qa/rest/src/test/resources/rest-api-spec/test/ccr/stats.yml
@@ -0,0 +1,11 @@
+---
+"Test stats":
+ - do:
+ ccr.stats: {}
+
+ - match: { auto_follow_stats.number_of_successful_follow_indices: 0 }
+ - match: { auto_follow_stats.number_of_failed_follow_indices: 0 }
+ - match: { auto_follow_stats.number_of_failed_remote_cluster_state_requests: 0 }
+ - length: { auto_follow_stats.recent_auto_follow_errors: 0 }
+ - length: { follow_stats.indices: 0 }
+
diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/Ccr.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/Ccr.java
index 68a6310dcaa97..4ff363b7d1e11 100644
--- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/Ccr.java
+++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/Ccr.java
@@ -43,10 +43,10 @@
import org.elasticsearch.xpack.ccr.action.TransportGetAutoFollowPatternAction;
import org.elasticsearch.xpack.ccr.action.TransportUnfollowAction;
import org.elasticsearch.xpack.ccr.rest.RestGetAutoFollowPatternAction;
-import org.elasticsearch.xpack.ccr.action.TransportAutoFollowStatsAction;
+import org.elasticsearch.xpack.ccr.action.TransportStatsAction;
import org.elasticsearch.xpack.ccr.rest.RestAutoFollowStatsAction;
import org.elasticsearch.xpack.ccr.rest.RestUnfollowAction;
-import org.elasticsearch.xpack.core.ccr.action.AutoFollowStatsAction;
+import org.elasticsearch.xpack.core.ccr.action.StatsAction;
import org.elasticsearch.xpack.core.ccr.action.DeleteAutoFollowPatternAction;
import org.elasticsearch.xpack.core.ccr.action.GetAutoFollowPatternAction;
import org.elasticsearch.xpack.core.ccr.action.PutAutoFollowPatternAction;
@@ -164,7 +164,7 @@ public List> getPersistentTasksExecutor(ClusterServic
new ActionHandler<>(ShardChangesAction.INSTANCE, ShardChangesAction.TransportAction.class),
// stats action
new ActionHandler<>(FollowStatsAction.INSTANCE, TransportFollowStatsAction.class),
- new ActionHandler<>(AutoFollowStatsAction.INSTANCE, TransportAutoFollowStatsAction.class),
+ new ActionHandler<>(StatsAction.INSTANCE, TransportStatsAction.class),
// follow actions
new ActionHandler<>(PutFollowAction.INSTANCE, TransportPutFollowAction.class),
new ActionHandler<>(ResumeFollowAction.INSTANCE, TransportResumeFollowAction.class),
diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportAutoFollowStatsAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportStatsAction.java
similarity index 64%
rename from x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportAutoFollowStatsAction.java
rename to x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportStatsAction.java
index b08cbe85fe795..9723415804272 100644
--- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportAutoFollowStatsAction.java
+++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportStatsAction.java
@@ -9,11 +9,13 @@
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.master.TransportMasterNodeAction;
+import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.service.ClusterService;
+import org.elasticsearch.common.CheckedConsumer;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.LicenseUtils;
@@ -23,18 +25,19 @@
import org.elasticsearch.xpack.ccr.Ccr;
import org.elasticsearch.xpack.ccr.CcrLicenseChecker;
import org.elasticsearch.xpack.core.ccr.AutoFollowStats;
-import org.elasticsearch.xpack.core.ccr.action.AutoFollowStatsAction;
+import org.elasticsearch.xpack.core.ccr.action.FollowStatsAction;
+import org.elasticsearch.xpack.core.ccr.action.StatsAction;
import java.util.Objects;
-public class TransportAutoFollowStatsAction
- extends TransportMasterNodeAction {
+public class TransportStatsAction extends TransportMasterNodeAction {
+ private final Client client;
private final CcrLicenseChecker ccrLicenseChecker;
private final AutoFollowCoordinator autoFollowCoordinator;
@Inject
- public TransportAutoFollowStatsAction(
+ public TransportStatsAction(
Settings settings,
TransportService transportService,
ClusterService clusterService,
@@ -42,18 +45,20 @@ public TransportAutoFollowStatsAction(
ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver,
AutoFollowCoordinator autoFollowCoordinator,
- CcrLicenseChecker ccrLicenseChecker
+ CcrLicenseChecker ccrLicenseChecker,
+ Client client
) {
super(
settings,
- AutoFollowStatsAction.NAME,
+ StatsAction.NAME,
transportService,
clusterService,
threadPool,
actionFilters,
- AutoFollowStatsAction.Request::new,
+ StatsAction.Request::new,
indexNameExpressionResolver
);
+ this.client = client;
this.ccrLicenseChecker = Objects.requireNonNull(ccrLicenseChecker);
this.autoFollowCoordinator = Objects.requireNonNull(autoFollowCoordinator);
}
@@ -64,12 +69,12 @@ protected String executor() {
}
@Override
- protected AutoFollowStatsAction.Response newResponse() {
- return new AutoFollowStatsAction.Response();
+ protected StatsAction.Response newResponse() {
+ return new StatsAction.Response();
}
@Override
- protected void doExecute(Task task, AutoFollowStatsAction.Request request, ActionListener listener) {
+ protected void doExecute(Task task, StatsAction.Request request, ActionListener listener) {
if (ccrLicenseChecker.isCcrAllowed() == false) {
listener.onFailure(LicenseUtils.newComplianceException("ccr"));
return;
@@ -79,16 +84,20 @@ protected void doExecute(Task task, AutoFollowStatsAction.Request request, Actio
@Override
protected void masterOperation(
- AutoFollowStatsAction.Request request,
+ StatsAction.Request request,
ClusterState state,
- ActionListener listener
+ ActionListener listener
) throws Exception {
- AutoFollowStats stats = autoFollowCoordinator.getStats();
- listener.onResponse(new AutoFollowStatsAction.Response(stats));
+ CheckedConsumer handler = statsResponse -> {
+ AutoFollowStats stats = autoFollowCoordinator.getStats();
+ listener.onResponse(new StatsAction.Response(stats, statsResponse));
+ };
+ FollowStatsAction.StatsRequest statsRequest = new FollowStatsAction.StatsRequest();
+ client.execute(FollowStatsAction.INSTANCE, statsRequest, ActionListener.wrap(handler, listener::onFailure));
}
@Override
- protected ClusterBlockException checkBlock(AutoFollowStatsAction.Request request, ClusterState state) {
+ protected ClusterBlockException checkBlock(StatsAction.Request request, ClusterState state) {
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ);
}
}
diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestAutoFollowStatsAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestAutoFollowStatsAction.java
index 924bc2f831d23..434343e7cc0c8 100644
--- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestAutoFollowStatsAction.java
+++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestAutoFollowStatsAction.java
@@ -12,7 +12,7 @@
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
-import org.elasticsearch.xpack.core.ccr.action.AutoFollowStatsAction;
+import org.elasticsearch.xpack.core.ccr.action.StatsAction;
import java.io.IOException;
@@ -20,7 +20,7 @@ public class RestAutoFollowStatsAction extends BaseRestHandler {
public RestAutoFollowStatsAction(final Settings settings, final RestController controller) {
super(settings);
- controller.registerHandler(RestRequest.Method.GET, "/_ccr/auto_follow/stats", this);
+ controller.registerHandler(RestRequest.Method.GET, "/_ccr/stats", this);
}
@Override
@@ -30,8 +30,8 @@ public String getName() {
@Override
protected RestChannelConsumer prepareRequest(final RestRequest restRequest, final NodeClient client) throws IOException {
- final AutoFollowStatsAction.Request request = new AutoFollowStatsAction.Request();
- return channel -> client.execute(AutoFollowStatsAction.INSTANCE, request, new RestToXContentListener<>(channel));
+ final StatsAction.Request request = new StatsAction.Request();
+ return channel -> client.execute(StatsAction.INSTANCE, request, new RestToXContentListener<>(channel));
}
}
diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowStatsAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowStatsAction.java
index 25572894af3e9..15b7329297644 100644
--- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowStatsAction.java
+++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowStatsAction.java
@@ -21,7 +21,6 @@ public class RestFollowStatsAction extends BaseRestHandler {
public RestFollowStatsAction(final Settings settings, final RestController controller) {
super(settings);
- controller.registerHandler(RestRequest.Method.GET, "/_ccr/stats", this);
controller.registerHandler(RestRequest.Method.GET, "/{index}/_ccr/stats", this);
}
diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java
index 305daa34d3010..e35150a88600e 100644
--- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java
+++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java
@@ -19,7 +19,7 @@
import org.elasticsearch.xpack.CcrIntegTestCase;
import org.elasticsearch.xpack.ccr.action.ShardFollowTask;
import org.elasticsearch.xpack.core.ccr.AutoFollowStats;
-import org.elasticsearch.xpack.core.ccr.action.AutoFollowStatsAction;
+import org.elasticsearch.xpack.core.ccr.action.StatsAction;
import org.elasticsearch.xpack.core.ccr.action.DeleteAutoFollowPatternAction;
import org.elasticsearch.xpack.core.ccr.action.PutAutoFollowPatternAction;
@@ -260,8 +260,8 @@ private void deleteAutoFollowPatternSetting() {
}
private AutoFollowStats getAutoFollowStats() {
- AutoFollowStatsAction.Request request = new AutoFollowStatsAction.Request();
- return followerClient().execute(AutoFollowStatsAction.INSTANCE, request).actionGet().getStats();
+ StatsAction.Request request = new StatsAction.Request();
+ return followerClient().execute(StatsAction.INSTANCE, request).actionGet().getAutoFollowStats();
}
private void createLeaderIndex(String index, Settings settings) {
diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowStatsResponseTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowStatsResponseTests.java
index 742eb761005e8..7e377f7abcd7c 100644
--- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowStatsResponseTests.java
+++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowStatsResponseTests.java
@@ -7,25 +7,28 @@
import org.elasticsearch.test.AbstractStreamableTestCase;
import org.elasticsearch.xpack.core.ccr.AutoFollowStats;
-import org.elasticsearch.xpack.core.ccr.action.AutoFollowStatsAction;
+import org.elasticsearch.xpack.core.ccr.action.FollowStatsAction;
+import org.elasticsearch.xpack.core.ccr.action.StatsAction;
import static org.elasticsearch.xpack.ccr.action.AutoFollowStatsTests.randomReadExceptions;
+import static org.elasticsearch.xpack.ccr.action.StatsResponsesTests.createStatsResponse;
-public class AutoFollowStatsResponseTests extends AbstractStreamableTestCase {
+public class AutoFollowStatsResponseTests extends AbstractStreamableTestCase {
@Override
- protected AutoFollowStatsAction.Response createBlankInstance() {
- return new AutoFollowStatsAction.Response();
+ protected StatsAction.Response createBlankInstance() {
+ return new StatsAction.Response();
}
@Override
- protected AutoFollowStatsAction.Response createTestInstance() {
+ protected StatsAction.Response createTestInstance() {
AutoFollowStats autoFollowStats = new AutoFollowStats(
randomNonNegativeLong(),
randomNonNegativeLong(),
randomNonNegativeLong(),
randomReadExceptions()
);
- return new AutoFollowStatsAction.Response(autoFollowStats);
+ FollowStatsAction.StatsResponses statsResponse = createStatsResponse();
+ return new StatsAction.Response(autoFollowStats, statsResponse);
}
}
diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/StatsResponsesTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/StatsResponsesTests.java
index e4830413dff3b..86851d98ffed2 100644
--- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/StatsResponsesTests.java
+++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/StatsResponsesTests.java
@@ -23,6 +23,10 @@ protected FollowStatsAction.StatsResponses createBlankInstance() {
@Override
protected FollowStatsAction.StatsResponses createTestInstance() {
+ return createStatsResponse();
+ }
+
+ static FollowStatsAction.StatsResponses createStatsResponse() {
int numResponses = randomIntBetween(0, 8);
List responses = new ArrayList<>(numResponses);
for (int i = 0; i < numResponses; i++) {
diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/AbstractCcrCollectorTestCase.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/AbstractCcrCollectorTestCase.java
deleted file mode 100644
index f98e541a9d907..0000000000000
--- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/AbstractCcrCollectorTestCase.java
+++ /dev/null
@@ -1,118 +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.monitoring.collector.ccr;
-
-import org.elasticsearch.client.Client;
-import org.elasticsearch.cluster.service.ClusterService;
-import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.license.XPackLicenseState;
-import org.elasticsearch.xpack.core.XPackSettings;
-import org.elasticsearch.xpack.monitoring.BaseCollectorTestCase;
-
-import static org.hamcrest.Matchers.is;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public abstract class AbstractCcrCollectorTestCase extends BaseCollectorTestCase {
-
- public void testShouldCollectReturnsFalseIfMonitoringNotAllowed() {
- final Settings settings = randomFrom(ccrEnabledSettings(), ccrDisabledSettings());
- final boolean ccrAllowed = randomBoolean();
- final boolean isElectedMaster = randomBoolean();
- whenLocalNodeElectedMaster(isElectedMaster);
-
- // this controls the blockage
- when(licenseState.isMonitoringAllowed()).thenReturn(false);
- when(licenseState.isCcrAllowed()).thenReturn(ccrAllowed);
-
- final AbstractCcrCollector collector = createCollector(settings, clusterService, licenseState, client);
-
- assertThat(collector.shouldCollect(isElectedMaster), is(false));
- if (isElectedMaster) {
- verify(licenseState).isMonitoringAllowed();
- }
- }
-
- public void testShouldCollectReturnsFalseIfNotMaster() {
- // regardless of CCR being enabled
- final Settings settings = randomFrom(ccrEnabledSettings(), ccrDisabledSettings());
-
- when(licenseState.isMonitoringAllowed()).thenReturn(randomBoolean());
- when(licenseState.isCcrAllowed()).thenReturn(randomBoolean());
- // this controls the blockage
- final boolean isElectedMaster = false;
-
- final AbstractCcrCollector collector = createCollector(settings, clusterService, licenseState, client);
-
- assertThat(collector.shouldCollect(isElectedMaster), is(false));
- }
-
- public void testShouldCollectReturnsFalseIfCCRIsDisabled() {
- // this is controls the blockage
- final Settings settings = ccrDisabledSettings();
-
- when(licenseState.isMonitoringAllowed()).thenReturn(randomBoolean());
- when(licenseState.isCcrAllowed()).thenReturn(randomBoolean());
-
- final boolean isElectedMaster = randomBoolean();
- whenLocalNodeElectedMaster(isElectedMaster);
-
- final AbstractCcrCollector collector = createCollector(settings, clusterService, licenseState, client);
-
- assertThat(collector.shouldCollect(isElectedMaster), is(false));
-
- if (isElectedMaster) {
- verify(licenseState).isMonitoringAllowed();
- }
- }
-
- public void testShouldCollectReturnsFalseIfCCRIsNotAllowed() {
- final Settings settings = randomFrom(ccrEnabledSettings(), ccrDisabledSettings());
-
- when(licenseState.isMonitoringAllowed()).thenReturn(randomBoolean());
- // this is controls the blockage
- when(licenseState.isCcrAllowed()).thenReturn(false);
- final boolean isElectedMaster = randomBoolean();
- whenLocalNodeElectedMaster(isElectedMaster);
-
- final AbstractCcrCollector collector = createCollector(settings, clusterService, licenseState, client);
-
- assertThat(collector.shouldCollect(isElectedMaster), is(false));
-
- if (isElectedMaster) {
- verify(licenseState).isMonitoringAllowed();
- }
- }
-
- public void testShouldCollectReturnsTrue() {
- final Settings settings = ccrEnabledSettings();
-
- when(licenseState.isMonitoringAllowed()).thenReturn(true);
- when(licenseState.isCcrAllowed()).thenReturn(true);
- final boolean isElectedMaster = true;
-
- final AbstractCcrCollector collector = createCollector(settings, clusterService, licenseState, client);
-
- assertThat(collector.shouldCollect(isElectedMaster), is(true));
-
- verify(licenseState).isMonitoringAllowed();
- }
-
- abstract AbstractCcrCollector createCollector(Settings settings,
- ClusterService clusterService,
- XPackLicenseState licenseState,
- Client client);
-
- private Settings ccrEnabledSettings() {
- // since it's the default, we want to ensure we test both with/without it
- return randomBoolean() ? Settings.EMPTY : Settings.builder().put(XPackSettings.CCR_ENABLED_SETTING.getKey(), true).build();
- }
-
- private Settings ccrDisabledSettings() {
- return Settings.builder().put(XPackSettings.CCR_ENABLED_SETTING.getKey(), false).build();
- }
-
-}
diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/CcrAutoFollowStatsCollectorTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/CcrAutoFollowStatsCollectorTests.java
deleted file mode 100644
index 7a302503d2db4..0000000000000
--- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/CcrAutoFollowStatsCollectorTests.java
+++ /dev/null
@@ -1,85 +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.monitoring.collector.ccr;
-
-import org.elasticsearch.action.ActionFuture;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.cluster.service.ClusterService;
-import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.common.unit.TimeValue;
-import org.elasticsearch.common.util.concurrent.ThreadContext;
-import org.elasticsearch.license.XPackLicenseState;
-import org.elasticsearch.xpack.core.ccr.AutoFollowStats;
-import org.elasticsearch.xpack.core.ccr.action.AutoFollowStatsAction;
-import org.elasticsearch.xpack.core.ccr.client.CcrClient;
-import org.elasticsearch.xpack.core.monitoring.MonitoredSystem;
-import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringDoc;
-
-import java.util.Collection;
-
-import static org.elasticsearch.xpack.monitoring.MonitoringTestUtils.randomMonitoringNode;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.greaterThan;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class CcrAutoFollowStatsCollectorTests extends AbstractCcrCollectorTestCase {
-
- @Override
- AbstractCcrCollector createCollector(Settings settings, ClusterService clusterService, XPackLicenseState licenseState, Client client) {
- return new CcrAutoFollowStatsCollector(settings, clusterService, licenseState, client);
- }
-
- public void testDoCollect() throws Exception {
- final String clusterUuid = randomAlphaOfLength(5);
- whenClusterStateWithUUID(clusterUuid);
-
- final MonitoringDoc.Node node = randomMonitoringNode(random());
- final CcrClient client = mock(CcrClient.class);
- final ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
-
- final TimeValue timeout = TimeValue.timeValueSeconds(randomIntBetween(1, 120));
- withCollectionTimeout(CcrAutoFollowStatsCollector.CCR_AUTO_FOLLOW_STATS_TIMEOUT, timeout);
-
- final CcrAutoFollowStatsCollector collector =
- new CcrAutoFollowStatsCollector(Settings.EMPTY, clusterService, licenseState, client, threadContext);
- assertEquals(timeout, collector.getCollectionTimeout());
-
- final AutoFollowStats autoFollowStats = mock(AutoFollowStats.class);
-
- @SuppressWarnings("unchecked")
- final ActionFuture future = (ActionFuture)mock(ActionFuture.class);
- final AutoFollowStatsAction.Response response = new AutoFollowStatsAction.Response(autoFollowStats);
-
- when(client.autoFollowStats(any())).thenReturn(future);
- when(future.actionGet(timeout)).thenReturn(response);
-
- final long interval = randomNonNegativeLong();
-
- final Collection documents = collector.doCollect(node, interval, clusterState);
- verify(clusterState).metaData();
- verify(metaData).clusterUUID();
-
- assertThat(documents, hasSize(1));
- final AutoFollowStatsMonitoringDoc document = (AutoFollowStatsMonitoringDoc) documents.iterator().next();
-
- assertThat(document.getCluster(), is(clusterUuid));
- assertThat(document.getTimestamp(), greaterThan(0L));
- assertThat(document.getIntervalMillis(), equalTo(interval));
- assertThat(document.getNode(), equalTo(node));
- assertThat(document.getSystem(), is(MonitoredSystem.ES));
- assertThat(document.getType(), is(AutoFollowStatsMonitoringDoc.TYPE));
- assertThat(document.getId(), nullValue());
- assertThat(document.stats(), is(autoFollowStats));
- }
-
-}
diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/FollowStatsCollectorTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/FollowStatsCollectorTests.java
deleted file mode 100644
index 904735ffedf25..0000000000000
--- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/FollowStatsCollectorTests.java
+++ /dev/null
@@ -1,133 +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.monitoring.collector.ccr;
-
-import org.elasticsearch.action.ActionFuture;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.cluster.service.ClusterService;
-import org.elasticsearch.common.Strings;
-import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.common.unit.TimeValue;
-import org.elasticsearch.common.util.concurrent.ThreadContext;
-import org.elasticsearch.license.XPackLicenseState;
-import org.elasticsearch.xpack.core.ccr.ShardFollowNodeTaskStatus;
-import org.elasticsearch.xpack.core.ccr.action.FollowStatsAction;
-import org.elasticsearch.xpack.core.ccr.client.CcrClient;
-import org.elasticsearch.xpack.core.monitoring.MonitoredSystem;
-import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringDoc;
-import org.mockito.ArgumentMatcher;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import static java.util.Collections.emptyList;
-import static org.elasticsearch.xpack.monitoring.MonitoringTestUtils.randomMonitoringNode;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.greaterThan;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class FollowStatsCollectorTests extends AbstractCcrCollectorTestCase {
-
- @Override
- AbstractCcrCollector createCollector(Settings settings, ClusterService clusterService, XPackLicenseState licenseState, Client client) {
- return new FollowStatsCollector(settings, clusterService, licenseState, client);
- }
-
- public void testDoCollect() throws Exception {
- final String clusterUuid = randomAlphaOfLength(5);
- whenClusterStateWithUUID(clusterUuid);
-
- final MonitoringDoc.Node node = randomMonitoringNode(random());
- final CcrClient client = mock(CcrClient.class);
- final ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
-
- final TimeValue timeout = TimeValue.timeValueSeconds(randomIntBetween(1, 120));
- withCollectionTimeout(FollowStatsCollector.CCR_STATS_TIMEOUT, timeout);
-
- final FollowStatsCollector collector =
- new FollowStatsCollector(Settings.EMPTY, clusterService, licenseState, client, threadContext);
- assertEquals(timeout, collector.getCollectionTimeout());
-
- final List statuses = mockStatuses();
-
- @SuppressWarnings("unchecked")
- final ActionFuture future =
- (ActionFuture)mock(ActionFuture.class);
- final FollowStatsAction.StatsResponses responses = new FollowStatsAction.StatsResponses(emptyList(), emptyList(), statuses);
-
- final FollowStatsAction.StatsRequest request = new FollowStatsAction.StatsRequest();
- request.setIndices(Strings.EMPTY_ARRAY);
- when(client.stats(statsRequestEq(request))).thenReturn(future);
- when(future.actionGet(timeout)).thenReturn(responses);
-
- final long interval = randomNonNegativeLong();
-
- final Collection documents = collector.doCollect(node, interval, clusterState);
- verify(clusterState).metaData();
- verify(metaData).clusterUUID();
-
- assertThat(documents, hasSize(statuses.size()));
-
- int index = 0;
- for (final Iterator it = documents.iterator(); it.hasNext(); index++) {
- final FollowStatsMonitoringDoc document = (FollowStatsMonitoringDoc)it.next();
- final FollowStatsAction.StatsResponse status = statuses.get(index);
-
- assertThat(document.getCluster(), is(clusterUuid));
- assertThat(document.getTimestamp(), greaterThan(0L));
- assertThat(document.getIntervalMillis(), equalTo(interval));
- assertThat(document.getNode(), equalTo(node));
- assertThat(document.getSystem(), is(MonitoredSystem.ES));
- assertThat(document.getType(), is(FollowStatsMonitoringDoc.TYPE));
- assertThat(document.getId(), nullValue());
- assertThat(document.status(), is(status.status()));
- }
- }
-
- private List mockStatuses() {
- final int count = randomIntBetween(1, 8);
- final List statuses = new ArrayList<>(count);
-
- for (int i = 0; i < count; ++i) {
- FollowStatsAction.StatsResponse statsResponse = mock(FollowStatsAction.StatsResponse.class);
- ShardFollowNodeTaskStatus status = mock(ShardFollowNodeTaskStatus.class);
- when(statsResponse.status()).thenReturn(status);
- statuses.add(statsResponse);
- }
-
- return statuses;
- }
-
- private static FollowStatsAction.StatsRequest statsRequestEq(FollowStatsAction.StatsRequest expected) {
- return argThat(new FollowStatsRequest(expected));
- }
-
- private static class FollowStatsRequest extends ArgumentMatcher {
-
- private final FollowStatsAction.StatsRequest expected;
-
- private FollowStatsRequest(FollowStatsAction.StatsRequest expected) {
- this.expected = expected;
- }
-
- @Override
- public boolean matches(Object o) {
- FollowStatsAction.StatsRequest actual = (FollowStatsAction.StatsRequest) o;
- return Arrays.equals(expected.indices(), actual.indices());
- }
- }
-
-}
diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/StatsCollectorTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/StatsCollectorTests.java
new file mode 100644
index 0000000000000..e23ba7800fb79
--- /dev/null
+++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/StatsCollectorTests.java
@@ -0,0 +1,215 @@
+/*
+ * 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.monitoring.collector.ccr;
+
+import org.elasticsearch.action.ActionFuture;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.cluster.service.ClusterService;
+import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.unit.TimeValue;
+import org.elasticsearch.common.util.concurrent.ThreadContext;
+import org.elasticsearch.license.XPackLicenseState;
+import org.elasticsearch.xpack.core.XPackSettings;
+import org.elasticsearch.xpack.core.ccr.AutoFollowStats;
+import org.elasticsearch.xpack.core.ccr.ShardFollowNodeTaskStatus;
+import org.elasticsearch.xpack.core.ccr.action.FollowStatsAction;
+import org.elasticsearch.xpack.core.ccr.action.StatsAction;
+import org.elasticsearch.xpack.core.ccr.client.CcrClient;
+import org.elasticsearch.xpack.core.monitoring.MonitoredSystem;
+import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringDoc;
+import org.elasticsearch.xpack.monitoring.BaseCollectorTestCase;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.elasticsearch.xpack.monitoring.MonitoringTestUtils.randomMonitoringNode;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class StatsCollectorTests extends BaseCollectorTestCase {
+
+ public void testShouldCollectReturnsFalseIfMonitoringNotAllowed() {
+ final Settings settings = randomFrom(ccrEnabledSettings(), ccrDisabledSettings());
+ final boolean ccrAllowed = randomBoolean();
+ final boolean isElectedMaster = randomBoolean();
+ whenLocalNodeElectedMaster(isElectedMaster);
+
+ // this controls the blockage
+ when(licenseState.isMonitoringAllowed()).thenReturn(false);
+ when(licenseState.isCcrAllowed()).thenReturn(ccrAllowed);
+
+ final StatsCollector collector = createCollector(settings, clusterService, licenseState, client);
+
+ assertThat(collector.shouldCollect(isElectedMaster), is(false));
+ if (isElectedMaster) {
+ verify(licenseState).isMonitoringAllowed();
+ }
+ }
+
+ public void testShouldCollectReturnsFalseIfNotMaster() {
+ // regardless of CCR being enabled
+ final Settings settings = randomFrom(ccrEnabledSettings(), ccrDisabledSettings());
+
+ when(licenseState.isMonitoringAllowed()).thenReturn(randomBoolean());
+ when(licenseState.isCcrAllowed()).thenReturn(randomBoolean());
+ // this controls the blockage
+ final boolean isElectedMaster = false;
+
+ final StatsCollector collector = createCollector(settings, clusterService, licenseState, client);
+
+ assertThat(collector.shouldCollect(isElectedMaster), is(false));
+ }
+
+ public void testShouldCollectReturnsFalseIfCCRIsDisabled() {
+ // this is controls the blockage
+ final Settings settings = ccrDisabledSettings();
+
+ when(licenseState.isMonitoringAllowed()).thenReturn(randomBoolean());
+ when(licenseState.isCcrAllowed()).thenReturn(randomBoolean());
+
+ final boolean isElectedMaster = randomBoolean();
+ whenLocalNodeElectedMaster(isElectedMaster);
+
+ final StatsCollector collector = createCollector(settings, clusterService, licenseState, client);
+
+ assertThat(collector.shouldCollect(isElectedMaster), is(false));
+
+ if (isElectedMaster) {
+ verify(licenseState).isMonitoringAllowed();
+ }
+ }
+
+ public void testShouldCollectReturnsFalseIfCCRIsNotAllowed() {
+ final Settings settings = randomFrom(ccrEnabledSettings(), ccrDisabledSettings());
+
+ when(licenseState.isMonitoringAllowed()).thenReturn(randomBoolean());
+ // this is controls the blockage
+ when(licenseState.isCcrAllowed()).thenReturn(false);
+ final boolean isElectedMaster = randomBoolean();
+ whenLocalNodeElectedMaster(isElectedMaster);
+
+ final StatsCollector collector = createCollector(settings, clusterService, licenseState, client);
+
+ assertThat(collector.shouldCollect(isElectedMaster), is(false));
+
+ if (isElectedMaster) {
+ verify(licenseState).isMonitoringAllowed();
+ }
+ }
+
+ public void testShouldCollectReturnsTrue() {
+ final Settings settings = ccrEnabledSettings();
+
+ when(licenseState.isMonitoringAllowed()).thenReturn(true);
+ when(licenseState.isCcrAllowed()).thenReturn(true);
+ final boolean isElectedMaster = true;
+
+ final StatsCollector collector = createCollector(settings, clusterService, licenseState, client);
+
+ assertThat(collector.shouldCollect(isElectedMaster), is(true));
+
+ verify(licenseState).isMonitoringAllowed();
+ }
+
+ public void testDoCollect() throws Exception {
+ final String clusterUuid = randomAlphaOfLength(5);
+ whenClusterStateWithUUID(clusterUuid);
+
+ final MonitoringDoc.Node node = randomMonitoringNode(random());
+ final CcrClient client = mock(CcrClient.class);
+ final ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
+ final List statuses = mockStatuses();
+
+ final TimeValue timeout = TimeValue.timeValueSeconds(randomIntBetween(1, 120));
+ withCollectionTimeout(StatsCollector.CCR_STATS_TIMEOUT, timeout);
+
+ final AutoFollowStats autoFollowStats = mock(AutoFollowStats.class);
+ final FollowStatsAction.StatsResponses statsResponse = mock(FollowStatsAction.StatsResponses.class);
+ when(statsResponse.getStatsResponses()).thenReturn(statuses);
+
+ @SuppressWarnings("unchecked")
+ final ActionFuture future = (ActionFuture) mock(ActionFuture.class);
+ final StatsAction.Response response = new StatsAction.Response(autoFollowStats, statsResponse);
+
+ when(client.stats(any())).thenReturn(future);
+ when(future.actionGet(timeout)).thenReturn(response);
+
+ final StatsCollector collector = new StatsCollector(settings, clusterService, licenseState, client, threadContext);
+ assertEquals(timeout, collector.getCollectionTimeout());
+
+ final long interval = randomNonNegativeLong();
+ final List documents = new ArrayList<>(collector.doCollect(node, interval, clusterState));
+ verify(clusterState).metaData();
+ verify(metaData).clusterUUID();
+
+ assertThat(documents, hasSize(statuses.size() + 1));
+
+ for (int i = 0; i < documents.size() - 1; i++) {
+ final FollowStatsMonitoringDoc document = (FollowStatsMonitoringDoc) documents.get(i);
+ final FollowStatsAction.StatsResponse status = statuses.get(i);
+
+ assertThat(document.getCluster(), is(clusterUuid));
+ assertThat(document.getTimestamp(), greaterThan(0L));
+ assertThat(document.getIntervalMillis(), equalTo(interval));
+ assertThat(document.getNode(), equalTo(node));
+ assertThat(document.getSystem(), is(MonitoredSystem.ES));
+ assertThat(document.getType(), is(FollowStatsMonitoringDoc.TYPE));
+ assertThat(document.getId(), nullValue());
+ assertThat(document.status(), is(status.status()));
+ }
+
+ final AutoFollowStatsMonitoringDoc document = (AutoFollowStatsMonitoringDoc) documents.get(documents.size() - 1);
+ assertThat(document, notNullValue());
+ assertThat(document.getCluster(), is(clusterUuid));
+ assertThat(document.getTimestamp(), greaterThan(0L));
+ assertThat(document.getIntervalMillis(), equalTo(interval));
+ assertThat(document.getNode(), equalTo(node));
+ assertThat(document.getSystem(), is(MonitoredSystem.ES));
+ assertThat(document.getType(), is(AutoFollowStatsMonitoringDoc.TYPE));
+ assertThat(document.getId(), nullValue());
+ assertThat(document.stats(), is(autoFollowStats));
+ }
+
+ private List mockStatuses() {
+ final int count = randomIntBetween(1, 8);
+ final List statuses = new ArrayList<>(count);
+
+ for (int i = 0; i < count; ++i) {
+ FollowStatsAction.StatsResponse statsResponse = mock(FollowStatsAction.StatsResponse.class);
+ ShardFollowNodeTaskStatus status = mock(ShardFollowNodeTaskStatus.class);
+ when(status.followerIndex()).thenReturn("follow_index");
+ when(statsResponse.status()).thenReturn(status);
+ statuses.add(statsResponse);
+ }
+
+ return statuses;
+ }
+
+ private StatsCollector createCollector(Settings settings,
+ ClusterService clusterService,
+ XPackLicenseState licenseState,
+ Client client) {
+ return new StatsCollector(settings, clusterService, licenseState, client);
+ }
+
+ private Settings ccrEnabledSettings() {
+ // since it's the default, we want to ensure we test both with/without it
+ return randomBoolean() ? Settings.EMPTY : Settings.builder().put(XPackSettings.CCR_ENABLED_SETTING.getKey(), true).build();
+ }
+
+ private Settings ccrDisabledSettings() {
+ return Settings.builder().put(XPackSettings.CCR_ENABLED_SETTING.getKey(), false).build();
+ }
+
+}
diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowStatsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowStatsAction.java
index dba5f3b6f1f1f..ff47f6e105b92 100644
--- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowStatsAction.java
+++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/FollowStatsAction.java
@@ -32,7 +32,7 @@
public class FollowStatsAction extends Action {
- public static final String NAME = "cluster:monitor/ccr/stats";
+ public static final String NAME = "cluster:monitor/ccr/follow_stats";
public static final FollowStatsAction INSTANCE = new FollowStatsAction();
diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/AutoFollowStatsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/StatsAction.java
similarity index 60%
rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/AutoFollowStatsAction.java
rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/StatsAction.java
index 12cb1b4bf5935..e8cfe7f368206 100644
--- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/AutoFollowStatsAction.java
+++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/StatsAction.java
@@ -19,12 +19,12 @@
import java.io.IOException;
import java.util.Objects;
-public class AutoFollowStatsAction extends Action {
+public class StatsAction extends Action {
- public static final String NAME = "cluster:monitor/ccr/auto_follow_stats";
- public static final AutoFollowStatsAction INSTANCE = new AutoFollowStatsAction();
+ public static final String NAME = "cluster:monitor/ccr/stats";
+ public static final StatsAction INSTANCE = new StatsAction();
- private AutoFollowStatsAction() {
+ private StatsAction() {
super(NAME);
}
@@ -55,34 +55,48 @@ public void writeTo(StreamOutput out) throws IOException {
public static class Response extends ActionResponse implements ToXContentObject {
- private AutoFollowStats stats;
+ private AutoFollowStats autoFollowStats;
+ private FollowStatsAction.StatsResponses followStats;
- public Response(AutoFollowStats stats) {
- this.stats = stats;
+ public Response(AutoFollowStats autoFollowStats, FollowStatsAction.StatsResponses followStats) {
+ this.autoFollowStats = Objects.requireNonNull(autoFollowStats);
+ this.followStats = Objects.requireNonNull(followStats);
}
public Response() {
}
- public AutoFollowStats getStats() {
- return stats;
+ public AutoFollowStats getAutoFollowStats() {
+ return autoFollowStats;
+ }
+
+ public FollowStatsAction.StatsResponses getFollowStats() {
+ return followStats;
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
- stats = new AutoFollowStats(in);
+ autoFollowStats = new AutoFollowStats(in);
+ followStats = new FollowStatsAction.StatsResponses();
+ followStats.readFrom(in);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
- stats.writeTo(out);
+ autoFollowStats.writeTo(out);
+ followStats.writeTo(out);
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
- stats.toXContent(builder, params);
+ builder.startObject();
+ {
+ builder.field("auto_follow_stats", autoFollowStats, params);
+ builder.field("follow_stats", followStats, params);
+ }
+ builder.endObject();
return builder;
}
@@ -91,12 +105,13 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Response response = (Response) o;
- return Objects.equals(stats, response.stats);
+ return Objects.equals(autoFollowStats, response.autoFollowStats) &&
+ Objects.equals(followStats, response.followStats);
}
@Override
public int hashCode() {
- return Objects.hash(stats);
+ return Objects.hash(autoFollowStats, followStats);
}
}
diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/client/CcrClient.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/client/CcrClient.java
index 3d5be565c1e29..9cab375a42bb2 100644
--- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/client/CcrClient.java
+++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ccr/client/CcrClient.java
@@ -11,7 +11,7 @@
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.ElasticsearchClient;
-import org.elasticsearch.xpack.core.ccr.action.AutoFollowStatsAction;
+import org.elasticsearch.xpack.core.ccr.action.StatsAction;
import org.elasticsearch.xpack.core.ccr.action.FollowStatsAction;
import org.elasticsearch.xpack.core.ccr.action.PutFollowAction;
import org.elasticsearch.xpack.core.ccr.action.DeleteAutoFollowPatternAction;
@@ -53,26 +53,26 @@ public ActionFuture resumeFollow(final ResumeFollowAction.
return listener;
}
- public void stats(
+ public void followStats(
final FollowStatsAction.StatsRequest request,
final ActionListener listener) {
client.execute(FollowStatsAction.INSTANCE, request, listener);
}
- public ActionFuture stats(final FollowStatsAction.StatsRequest request) {
+ public ActionFuture followStats(final FollowStatsAction.StatsRequest request) {
final PlainActionFuture listener = PlainActionFuture.newFuture();
client.execute(FollowStatsAction.INSTANCE, request, listener);
return listener;
}
- public void autoFollowStats(final AutoFollowStatsAction.Request request,
- final ActionListener listener) {
- client.execute(AutoFollowStatsAction.INSTANCE, request, listener);
+ public void stats(final StatsAction.Request request,
+ final ActionListener listener) {
+ client.execute(StatsAction.INSTANCE, request, listener);
}
- public ActionFuture autoFollowStats(final AutoFollowStatsAction.Request request) {
- final PlainActionFuture listener = PlainActionFuture.newFuture();
- autoFollowStats(request, listener);
+ public ActionFuture stats(final StatsAction.Request request) {
+ final PlainActionFuture listener = PlainActionFuture.newFuture();
+ stats(request, listener);
return listener;
}
diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java
index 31f403918fab6..641e25eabf944 100644
--- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java
+++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java
@@ -39,8 +39,7 @@
import org.elasticsearch.xpack.monitoring.action.TransportMonitoringBulkAction;
import org.elasticsearch.xpack.monitoring.cleaner.CleanerService;
import org.elasticsearch.xpack.monitoring.collector.Collector;
-import org.elasticsearch.xpack.monitoring.collector.ccr.CcrAutoFollowStatsCollector;
-import org.elasticsearch.xpack.monitoring.collector.ccr.FollowStatsCollector;
+import org.elasticsearch.xpack.monitoring.collector.ccr.StatsCollector;
import org.elasticsearch.xpack.monitoring.collector.cluster.ClusterStatsCollector;
import org.elasticsearch.xpack.monitoring.collector.indices.IndexRecoveryCollector;
import org.elasticsearch.xpack.monitoring.collector.indices.IndexStatsCollector;
@@ -144,8 +143,7 @@ public Collection