Skip to content

Commit 786697a

Browse files
authored
[HLRC] Added support for CCR Stats API (#36213)
This change also adds documentation for the CCR Stats API. Relates to #33824
1 parent 11935cd commit 786697a

File tree

11 files changed

+1146
-9
lines changed

11 files changed

+1146
-9
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/CcrClient.java

+46
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
package org.elasticsearch.client;
2121

2222
import org.elasticsearch.action.ActionListener;
23+
import org.elasticsearch.client.ccr.CcrStatsRequest;
24+
import org.elasticsearch.client.ccr.CcrStatsResponse;
2325
import org.elasticsearch.client.ccr.DeleteAutoFollowPatternRequest;
2426
import org.elasticsearch.client.ccr.GetAutoFollowPatternRequest;
2527
import org.elasticsearch.client.ccr.GetAutoFollowPatternResponse;
@@ -360,4 +362,48 @@ public void getAutoFollowPatternAsync(GetAutoFollowPatternRequest request,
360362
);
361363
}
362364

365+
/**
366+
* Gets all CCR stats.
367+
*
368+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-stats.html">
369+
* the docs</a> for more.
370+
*
371+
* @param request the request
372+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
373+
* @return the response
374+
* @throws IOException in case there is a problem sending the request or parsing back the response
375+
*/
376+
public CcrStatsResponse getCcrStats(CcrStatsRequest request,
377+
RequestOptions options) throws IOException {
378+
return restHighLevelClient.performRequestAndParseEntity(
379+
request,
380+
CcrRequestConverters::getCcrStats,
381+
options,
382+
CcrStatsResponse::fromXContent,
383+
Collections.emptySet()
384+
);
385+
}
386+
387+
/**
388+
* Gets all CCR stats.
389+
*
390+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-stats.html">
391+
* the docs</a> for more.
392+
*
393+
* @param request the request
394+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
395+
*/
396+
public void getCcrStatsAsync(CcrStatsRequest request,
397+
RequestOptions options,
398+
ActionListener<CcrStatsResponse> listener) {
399+
restHighLevelClient.performRequestAsyncAndParseEntity(
400+
request,
401+
CcrRequestConverters::getCcrStats,
402+
options,
403+
CcrStatsResponse::fromXContent,
404+
listener,
405+
Collections.emptySet()
406+
);
407+
}
408+
363409
}

client/rest-high-level/src/main/java/org/elasticsearch/client/CcrRequestConverters.java

+8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.http.client.methods.HttpGet;
2424
import org.apache.http.client.methods.HttpPost;
2525
import org.apache.http.client.methods.HttpPut;
26+
import org.elasticsearch.client.ccr.CcrStatsRequest;
2627
import org.elasticsearch.client.ccr.DeleteAutoFollowPatternRequest;
2728
import org.elasticsearch.client.ccr.GetAutoFollowPatternRequest;
2829
import org.elasticsearch.client.ccr.PauseFollowRequest;
@@ -100,4 +101,11 @@ static Request getAutoFollowPattern(GetAutoFollowPatternRequest getAutoFollowPat
100101
return new Request(HttpGet.METHOD_NAME, endpoint);
101102
}
102103

104+
static Request getCcrStats(CcrStatsRequest ccrStatsRequest) {
105+
String endpoint = new RequestConverters.EndpointBuilder()
106+
.addPathPartAsIs("_ccr", "stats")
107+
.build();
108+
return new Request(HttpGet.METHOD_NAME, endpoint);
109+
}
110+
103111
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.client.ccr;
21+
22+
import org.elasticsearch.ElasticsearchException;
23+
import org.elasticsearch.common.ParseField;
24+
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
25+
26+
import java.util.AbstractMap;
27+
import java.util.List;
28+
import java.util.Map;
29+
import java.util.NavigableMap;
30+
import java.util.TreeMap;
31+
import java.util.stream.Collectors;
32+
33+
public final class AutoFollowStats {
34+
35+
static final ParseField NUMBER_OF_SUCCESSFUL_INDICES_AUTO_FOLLOWED = new ParseField("number_of_successful_follow_indices");
36+
static final ParseField NUMBER_OF_FAILED_INDICES_AUTO_FOLLOWED = new ParseField("number_of_failed_follow_indices");
37+
static final ParseField NUMBER_OF_FAILED_REMOTE_CLUSTER_STATE_REQUESTS =
38+
new ParseField("number_of_failed_remote_cluster_state_requests");
39+
static final ParseField RECENT_AUTO_FOLLOW_ERRORS = new ParseField("recent_auto_follow_errors");
40+
static final ParseField LEADER_INDEX = new ParseField("leader_index");
41+
static final ParseField AUTO_FOLLOW_EXCEPTION = new ParseField("auto_follow_exception");
42+
43+
@SuppressWarnings("unchecked")
44+
static final ConstructingObjectParser<AutoFollowStats, Void> STATS_PARSER = new ConstructingObjectParser<>("auto_follow_stats",
45+
args -> new AutoFollowStats(
46+
(Long) args[0],
47+
(Long) args[1],
48+
(Long) args[2],
49+
new TreeMap<>(
50+
((List<Map.Entry<String, ElasticsearchException>>) args[3])
51+
.stream()
52+
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))
53+
));
54+
55+
private static final ConstructingObjectParser<Map.Entry<String, ElasticsearchException>, Void> AUTO_FOLLOW_EXCEPTIONS_PARSER =
56+
new ConstructingObjectParser<>(
57+
"auto_follow_stats_errors",
58+
args -> new AbstractMap.SimpleEntry<>((String) args[0], (ElasticsearchException) args[1]));
59+
60+
static {
61+
AUTO_FOLLOW_EXCEPTIONS_PARSER.declareString(ConstructingObjectParser.constructorArg(), LEADER_INDEX);
62+
AUTO_FOLLOW_EXCEPTIONS_PARSER.declareObject(
63+
ConstructingObjectParser.constructorArg(),
64+
(p, c) -> ElasticsearchException.fromXContent(p),
65+
AUTO_FOLLOW_EXCEPTION);
66+
67+
STATS_PARSER.declareLong(ConstructingObjectParser.constructorArg(), NUMBER_OF_FAILED_INDICES_AUTO_FOLLOWED);
68+
STATS_PARSER.declareLong(ConstructingObjectParser.constructorArg(), NUMBER_OF_FAILED_REMOTE_CLUSTER_STATE_REQUESTS);
69+
STATS_PARSER.declareLong(ConstructingObjectParser.constructorArg(), NUMBER_OF_SUCCESSFUL_INDICES_AUTO_FOLLOWED);
70+
STATS_PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(), AUTO_FOLLOW_EXCEPTIONS_PARSER,
71+
RECENT_AUTO_FOLLOW_ERRORS);
72+
}
73+
74+
private final long numberOfFailedFollowIndices;
75+
private final long numberOfFailedRemoteClusterStateRequests;
76+
private final long numberOfSuccessfulFollowIndices;
77+
private final NavigableMap<String, ElasticsearchException> recentAutoFollowErrors;
78+
79+
AutoFollowStats(long numberOfFailedFollowIndices,
80+
long numberOfFailedRemoteClusterStateRequests,
81+
long numberOfSuccessfulFollowIndices,
82+
NavigableMap<String, ElasticsearchException> recentAutoFollowErrors) {
83+
this.numberOfFailedFollowIndices = numberOfFailedFollowIndices;
84+
this.numberOfFailedRemoteClusterStateRequests = numberOfFailedRemoteClusterStateRequests;
85+
this.numberOfSuccessfulFollowIndices = numberOfSuccessfulFollowIndices;
86+
this.recentAutoFollowErrors = recentAutoFollowErrors;
87+
}
88+
89+
public long getNumberOfFailedFollowIndices() {
90+
return numberOfFailedFollowIndices;
91+
}
92+
93+
public long getNumberOfFailedRemoteClusterStateRequests() {
94+
return numberOfFailedRemoteClusterStateRequests;
95+
}
96+
97+
public long getNumberOfSuccessfulFollowIndices() {
98+
return numberOfSuccessfulFollowIndices;
99+
}
100+
101+
public NavigableMap<String, ElasticsearchException> getRecentAutoFollowErrors() {
102+
return recentAutoFollowErrors;
103+
}
104+
105+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.client.ccr;
21+
22+
import org.elasticsearch.client.Validatable;
23+
24+
public final class CcrStatsRequest implements Validatable {
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.client.ccr;
21+
22+
import org.elasticsearch.common.ParseField;
23+
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
24+
import org.elasticsearch.common.xcontent.XContentParser;
25+
26+
public final class CcrStatsResponse {
27+
28+
static final ParseField AUTO_FOLLOW_STATS_FIELD = new ParseField("auto_follow_stats");
29+
static final ParseField FOLLOW_STATS_FIELD = new ParseField("follow_stats");
30+
31+
private static final ConstructingObjectParser<CcrStatsResponse, Void> PARSER = new ConstructingObjectParser<>("indices",
32+
args -> {
33+
AutoFollowStats autoFollowStats = (AutoFollowStats) args[0];
34+
IndicesFollowStats indicesFollowStats = (IndicesFollowStats) args[1];
35+
return new CcrStatsResponse(autoFollowStats, indicesFollowStats);
36+
});
37+
38+
static {
39+
PARSER.declareObject(ConstructingObjectParser.constructorArg(), AutoFollowStats.STATS_PARSER, AUTO_FOLLOW_STATS_FIELD);
40+
PARSER.declareObject(ConstructingObjectParser.constructorArg(), IndicesFollowStats.PARSER, FOLLOW_STATS_FIELD);
41+
}
42+
43+
public static CcrStatsResponse fromXContent(XContentParser parser) {
44+
return PARSER.apply(parser, null);
45+
}
46+
47+
private final AutoFollowStats autoFollowStats;
48+
private final IndicesFollowStats indicesFollowStats;
49+
50+
public CcrStatsResponse(AutoFollowStats autoFollowStats, IndicesFollowStats indicesFollowStats) {
51+
this.autoFollowStats = autoFollowStats;
52+
this.indicesFollowStats = indicesFollowStats;
53+
}
54+
55+
public AutoFollowStats getAutoFollowStats() {
56+
return autoFollowStats;
57+
}
58+
59+
public IndicesFollowStats getIndicesFollowStats() {
60+
return indicesFollowStats;
61+
}
62+
}

0 commit comments

Comments
 (0)