Skip to content

Commit

Permalink
[CCR] Refactor stats APIs
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
martijnvg committed Oct 26, 2018
1 parent 306f1d7 commit 29abea0
Show file tree
Hide file tree
Showing 25 changed files with 379 additions and 570 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ public void testAutoFollowPatterns() throws Exception {
}

assertBusy(() -> {
Request statsRequest = new Request("GET", "/_ccr/auto_follow/stats");
Map<String, ?> 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");
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
Original file line number Diff line number Diff line change
@@ -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 }

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -164,7 +164,7 @@ public List<PersistentTasksExecutor<?>> 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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,37 +25,40 @@
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<AutoFollowStatsAction.Request, AutoFollowStatsAction.Response> {
public class TransportStatsAction extends TransportMasterNodeAction<StatsAction.Request, StatsAction.Response> {

private final Client client;
private final CcrLicenseChecker ccrLicenseChecker;
private final AutoFollowCoordinator autoFollowCoordinator;

@Inject
public TransportAutoFollowStatsAction(
public TransportStatsAction(
Settings settings,
TransportService transportService,
ClusterService clusterService,
ThreadPool threadPool,
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);
}
Expand All @@ -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<AutoFollowStatsAction.Response> listener) {
protected void doExecute(Task task, StatsAction.Request request, ActionListener<StatsAction.Response> listener) {
if (ccrLicenseChecker.isCcrAllowed() == false) {
listener.onFailure(LicenseUtils.newComplianceException("ccr"));
return;
Expand All @@ -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<AutoFollowStatsAction.Response> listener
ActionListener<StatsAction.Response> listener
) throws Exception {
AutoFollowStats stats = autoFollowCoordinator.getStats();
listener.onResponse(new AutoFollowStatsAction.Response(stats));
CheckedConsumer<FollowStatsAction.StatsResponses, Exception> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
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;

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
Expand All @@ -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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AutoFollowStatsAction.Response> {
public class AutoFollowStatsResponseTests extends AbstractStreamableTestCase<StatsAction.Response> {

@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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<FollowStatsAction.StatsResponse> responses = new ArrayList<>(numResponses);
for (int i = 0; i < numResponses; i++) {
Expand Down

This file was deleted.

Loading

0 comments on commit 29abea0

Please sign in to comment.