Skip to content

Commit 4cf476e

Browse files
authored
Fix ESCCRRestTestCase.verifyAutoFollowMonitoring (elastic#97054) (elastic#97104)
The method `verifyAutoFollowMonitoring` searches for `ccr_auto_follow_stats` documents in `monitoring-es-*` indices to see if one document has the field `number_of_successful_follow_indices` greater than 0. If such document is found, it means that x-pack monitoring successfully indexed documents about CCR stats and that CCR at that time had at least 1 following index successfully running. But the current `verifyAutoFollowMonitoring` method only check the first 10 docs returned by the search requests. Recent failures of `AutoFollowIT.testAutoFollowPatterns` on 7.17 branch indicates that more than 10 docs were found, so I suspect one of them has `number_of_successful_follow_indices` > 0 but is not returned in the first 10 top docs. This pull request changes the method to only count documents with `number_of_successful_follow_indices` > 0. Closes elastic#91984
1 parent 4b72136 commit 4cf476e

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

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

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,23 @@ protected static void verifyCcrMonitoring(final String expectedLeaderIndex, fina
217217
}
218218

219219
protected static void verifyAutoFollowMonitoring() throws IOException {
220-
Request request = new Request("GET", "/.monitoring-*/_search");
220+
Request request = new Request("GET", "/.monitoring-*/_count");
221221
request.setJsonEntity("""
222-
{"query": {"term": {"type": "ccr_auto_follow_stats"}}}""");
222+
{
223+
"query": {
224+
"bool" : {
225+
"filter": {
226+
"term" : { "type" : "ccr_auto_follow_stats" }
227+
},
228+
"must" : {
229+
"range" : {
230+
"ccr_auto_follow_stats.number_of_successful_follow_indices" : { "gt" : 0 }
231+
}
232+
}
233+
}
234+
}
235+
}
236+
""");
223237
String responseEntity;
224238
Map<String, ?> response;
225239
try {
@@ -229,25 +243,12 @@ protected static void verifyAutoFollowMonitoring() throws IOException {
229243
throw new AssertionError("error while searching", e);
230244
}
231245
assertNotNull(responseEntity);
232-
int numberOfSuccessfulFollowIndices = 0;
233-
234-
List<?> hits = (List<?>) XContentMapValues.extractValue("hits.hits", response);
235-
assertThat(hits.size(), greaterThanOrEqualTo(1));
236-
237-
for (int i = 0; i < hits.size(); i++) {
238-
Map<?, ?> hit = (Map<?, ?>) hits.get(i);
239-
240-
int foundNumberOfOperationsReceived = (int) XContentMapValues.extractValue(
241-
"_source.ccr_auto_follow_stats.number_of_successful_follow_indices",
242-
hit
243-
);
244-
numberOfSuccessfulFollowIndices = Math.max(numberOfSuccessfulFollowIndices, foundNumberOfOperationsReceived);
245-
}
246246

247+
final Number count = (Number) XContentMapValues.extractValue("count", response);
247248
assertThat(
248-
"Unexpected number of followed indices [" + responseEntity + ']',
249-
numberOfSuccessfulFollowIndices,
250-
greaterThanOrEqualTo(1)
249+
"Expected at least 1 successfully followed index but found none, count returned [" + responseEntity + ']',
250+
count.longValue(),
251+
greaterThanOrEqualTo(1L)
251252
);
252253
}
253254

0 commit comments

Comments
 (0)