-
Notifications
You must be signed in to change notification settings - Fork 24.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CCR] Add auto follow stats api (#33801)
GET /_ccr/auto_follow/stats Returns: ``` { "number_of_successful_follow_indices": ... "number_of_failed_follow_indices": ... "number_of_failed_remote_cluster_state_requests": ... "recent_auto_follow_errors": [ ... ] } ``` Relates to #33007
- Loading branch information
Showing
11 changed files
with
311 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
x-pack/plugin/ccr/qa/rest/src/test/resources/rest-api-spec/test/ccr/auto_follow_stats.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
"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 } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
.../ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportAutoFollowStatsAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* 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.ccr.action; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.support.ActionFilters; | ||
import org.elasticsearch.action.support.master.TransportMasterNodeAction; | ||
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.inject.Inject; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.license.LicenseUtils; | ||
import org.elasticsearch.tasks.Task; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.TransportService; | ||
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 java.util.Objects; | ||
|
||
public class TransportAutoFollowStatsAction | ||
extends TransportMasterNodeAction<AutoFollowStatsAction.Request, AutoFollowStatsAction.Response> { | ||
|
||
private final CcrLicenseChecker ccrLicenseChecker; | ||
private final AutoFollowCoordinator autoFollowCoordinator; | ||
|
||
@Inject | ||
public TransportAutoFollowStatsAction( | ||
Settings settings, | ||
TransportService transportService, | ||
ClusterService clusterService, | ||
ThreadPool threadPool, | ||
ActionFilters actionFilters, | ||
IndexNameExpressionResolver indexNameExpressionResolver, | ||
AutoFollowCoordinator autoFollowCoordinator, | ||
CcrLicenseChecker ccrLicenseChecker | ||
) { | ||
super( | ||
settings, | ||
AutoFollowStatsAction.NAME, | ||
transportService, | ||
clusterService, | ||
threadPool, | ||
actionFilters, | ||
AutoFollowStatsAction.Request::new, | ||
indexNameExpressionResolver | ||
); | ||
this.ccrLicenseChecker = Objects.requireNonNull(ccrLicenseChecker); | ||
this.autoFollowCoordinator = Objects.requireNonNull(autoFollowCoordinator); | ||
} | ||
|
||
@Override | ||
protected String executor() { | ||
return Ccr.CCR_THREAD_POOL_NAME; | ||
} | ||
|
||
@Override | ||
protected AutoFollowStatsAction.Response newResponse() { | ||
return new AutoFollowStatsAction.Response(); | ||
} | ||
|
||
@Override | ||
protected void doExecute(Task task, AutoFollowStatsAction.Request request, ActionListener<AutoFollowStatsAction.Response> listener) { | ||
if (ccrLicenseChecker.isCcrAllowed() == false) { | ||
listener.onFailure(LicenseUtils.newComplianceException("ccr")); | ||
return; | ||
} | ||
super.doExecute(task, request, listener); | ||
} | ||
|
||
@Override | ||
protected void masterOperation( | ||
AutoFollowStatsAction.Request request, | ||
ClusterState state, | ||
ActionListener<AutoFollowStatsAction.Response> listener | ||
) throws Exception { | ||
AutoFollowStats stats = autoFollowCoordinator.getStats(); | ||
listener.onResponse(new AutoFollowStatsAction.Response(stats)); | ||
} | ||
|
||
@Override | ||
protected ClusterBlockException checkBlock(AutoFollowStatsAction.Request request, ClusterState state) { | ||
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
.../plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestAutoFollowStatsAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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.ccr.rest; | ||
|
||
import org.elasticsearch.client.node.NodeClient; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.rest.BaseRestHandler; | ||
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 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); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "ccr_auto_follow_stats"; | ||
} | ||
|
||
@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)); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...in/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/AutoFollowStatsResponseTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* 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.ccr.action; | ||
|
||
import org.elasticsearch.test.AbstractStreamableTestCase; | ||
import org.elasticsearch.xpack.core.ccr.AutoFollowStats; | ||
import org.elasticsearch.xpack.core.ccr.action.AutoFollowStatsAction; | ||
|
||
import static org.elasticsearch.xpack.ccr.action.AutoFollowStatsTests.randomReadExceptions; | ||
|
||
public class AutoFollowStatsResponseTests extends AbstractStreamableTestCase<AutoFollowStatsAction.Response> { | ||
|
||
@Override | ||
protected AutoFollowStatsAction.Response createBlankInstance() { | ||
return new AutoFollowStatsAction.Response(); | ||
} | ||
|
||
@Override | ||
protected AutoFollowStatsAction.Response createTestInstance() { | ||
AutoFollowStats autoFollowStats = new AutoFollowStats( | ||
randomNonNegativeLong(), | ||
randomNonNegativeLong(), | ||
randomNonNegativeLong(), | ||
randomReadExceptions() | ||
); | ||
return new AutoFollowStatsAction.Response(autoFollowStats); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...gin/core/src/main/java/org/elasticsearch/xpack/core/ccr/action/AutoFollowStatsAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* 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.core.ccr.action; | ||
|
||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.action.ActionResponse; | ||
import org.elasticsearch.action.support.master.MasterNodeRequest; | ||
import org.elasticsearch.action.Action; | ||
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.xpack.core.ccr.AutoFollowStats; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
public class AutoFollowStatsAction extends Action<AutoFollowStatsAction.Response> { | ||
|
||
public static final String NAME = "cluster:monitor/ccr/auto_follow_stats"; | ||
public static final AutoFollowStatsAction INSTANCE = new AutoFollowStatsAction(); | ||
|
||
private AutoFollowStatsAction() { | ||
super(NAME); | ||
} | ||
|
||
@Override | ||
public Response newResponse() { | ||
return new Response(); | ||
} | ||
|
||
public static class Request extends MasterNodeRequest<Request> { | ||
|
||
public Request(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
public Request() { | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
} | ||
} | ||
|
||
public static class Response extends ActionResponse implements ToXContentObject { | ||
|
||
private AutoFollowStats stats; | ||
|
||
public Response(AutoFollowStats stats) { | ||
this.stats = stats; | ||
} | ||
|
||
public Response() { | ||
} | ||
|
||
public AutoFollowStats getStats() { | ||
return stats; | ||
} | ||
|
||
@Override | ||
public void readFrom(StreamInput in) throws IOException { | ||
super.readFrom(in); | ||
stats = new AutoFollowStats(in); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
stats.writeTo(out); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
stats.toXContent(builder, params); | ||
return builder; | ||
} | ||
|
||
@Override | ||
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); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(stats); | ||
} | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
x-pack/plugin/src/test/resources/rest-api-spec/api/ccr.auto_follow_stats.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"ccr.auto_follow_stats": { | ||
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/current", | ||
"methods": [ "GET" ], | ||
"url": { | ||
"path": "/_ccr/auto_follow/stats", | ||
"paths": [ "/_ccr/auto_follow/stats" ], | ||
"parts": {}, | ||
"body": null | ||
} | ||
} | ||
} |