Skip to content

Commit 4e3cc9b

Browse files
authored
[7.17] Fix ESCCRRestTestCase.verifyAutoFollowMonitoring (#97054) (#97105)
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 #91984
1 parent eeedb98 commit 4e3cc9b

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,21 @@ protected static void verifyCcrMonitoring(final String expectedLeaderIndex, fina
218218
}
219219

220220
protected static void verifyAutoFollowMonitoring() throws IOException {
221-
Request request = new Request("GET", "/.monitoring-*/_search");
222-
request.setJsonEntity("{\"query\": {\"term\": {\"type\": \"ccr_auto_follow_stats\"}}}");
221+
Request request = new Request("GET", "/.monitoring-*/_count");
222+
request.setJsonEntity(
223+
"{"
224+
+ " \"query\": {"
225+
+ " \"bool\" : {"
226+
+ " \"filter\": {"
227+
+ " \"term\" : { \"type\" : \"ccr_auto_follow_stats\" }"
228+
+ " },"
229+
+ " \"must\" : {"
230+
+ " \"range\" : {\"ccr_auto_follow_stats.number_of_successful_follow_indices\" : { \"gt\" : 0 }}"
231+
+ " }"
232+
+ " }"
233+
+ " }"
234+
+ "}"
235+
);
223236
String responseEntity;
224237
Map<String, ?> response;
225238
try {
@@ -229,25 +242,12 @@ protected static void verifyAutoFollowMonitoring() throws IOException {
229242
throw new AssertionError("error while searching", e);
230243
}
231244
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-
}
246245

246+
final Number count = (Number) XContentMapValues.extractValue("count", response);
247247
assertThat(
248-
"Unexpected number of followed indices [" + responseEntity + ']',
249-
numberOfSuccessfulFollowIndices,
250-
greaterThanOrEqualTo(1)
248+
"Expected at least 1 successfully followed index but found none, count returned [" + responseEntity + ']',
249+
count.longValue(),
250+
greaterThanOrEqualTo(1L)
251251
);
252252
}
253253

0 commit comments

Comments
 (0)