Skip to content

Commit 1cc4b23

Browse files
committed
Fix ILM history store tests
These tests use the same index name, making it hard to read logs when diagnosing the failures. Additionally more information about the current state of the index could be retrieved when failing. This changes these two things in the hope of capturing more data about why this fails on some CI nodes but not others. Relates to elastic#50353
1 parent a5ab7da commit 1cc4b23

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java

+34-8
Original file line numberDiff line numberDiff line change
@@ -1077,9 +1077,8 @@ public void testRolloverStepRetriesUntilRolledOverIndexIsDeleted() throws Except
10771077
assertBusy(() -> assertThat(getStepKeyForIndex(index), equalTo(TerminalPolicyStep.KEY)));
10781078
}
10791079

1080-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/50353")
10811080
public void testHistoryIsWrittenWithSuccess() throws Exception {
1082-
String index = "index";
1081+
String index = "success-index";
10831082

10841083
createNewSingletonPolicy("hot", new RolloverAction(null, null, 1L));
10851084
Request createIndexTemplate = new Request("PUT", "_template/rolling_indexes");
@@ -1121,9 +1120,8 @@ public void testHistoryIsWrittenWithSuccess() throws Exception {
11211120
}
11221121

11231122

1124-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/50353")
11251123
public void testHistoryIsWrittenWithFailure() throws Exception {
1126-
String index = "index";
1124+
String index = "failure-index";
11271125

11281126
createNewSingletonPolicy("hot", new RolloverAction(null, null, 1L));
11291127
Request createIndexTemplate = new Request("PUT", "_template/rolling_indexes");
@@ -1150,9 +1148,8 @@ public void testHistoryIsWrittenWithFailure() throws Exception {
11501148
assertBusy(() -> assertHistoryIsPresent(policy, index + "-1", false, "ERROR"), 30, TimeUnit.SECONDS);
11511149
}
11521150

1153-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/50353")
11541151
public void testHistoryIsWrittenWithDeletion() throws Exception {
1155-
String index = "index";
1152+
String index = "delete-index";
11561153

11571154
createNewSingletonPolicy("delete", new DeleteAction());
11581155
Request createIndexTemplate = new Request("PUT", "_template/delete_indexes");
@@ -1231,8 +1228,37 @@ private void assertHistoryIsPresent(String policyName, String indexName, boolean
12311228
historyResponseMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true);
12321229
}
12331230
logger.info("--> history response: {}", historyResponseMap);
1234-
assertThat((int)((Map<String, Object>) ((Map<String, Object>) historyResponseMap.get("hits")).get("total")).get("value"),
1235-
greaterThanOrEqualTo(1));
1231+
int hits = (int)((Map<String, Object>) ((Map<String, Object>) historyResponseMap.get("hits")).get("total")).get("value");
1232+
1233+
// For a failure, print out whatever history we *do* have for the index
1234+
if (hits == 0) {
1235+
final Request allResults = new Request("GET", "ilm-history*/_search");
1236+
allResults.setJsonEntity("{\n" +
1237+
" \"query\": {\n" +
1238+
" \"bool\": {\n" +
1239+
" \"must\": [\n" +
1240+
" {\n" +
1241+
" \"term\": {\n" +
1242+
" \"policy\": \"" + policyName + "\"\n" +
1243+
" }\n" +
1244+
" },\n" +
1245+
" {\n" +
1246+
" \"term\": {\n" +
1247+
" \"index\": \"" + indexName + "\"\n" +
1248+
" }\n" +
1249+
" }\n" +
1250+
" ]\n" +
1251+
" }\n" +
1252+
" }\n" +
1253+
"}");
1254+
final Response allResultsResp = client().performRequest(historySearchRequest);
1255+
Map<String, Object> allResultsMap;
1256+
try (InputStream is = allResultsResp.getEntity().getContent()) {
1257+
allResultsMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true);
1258+
}
1259+
logger.info("--> expected at least 1 hit, got 0. All history for index [{}]: {}", index, allResultsMap);
1260+
}
1261+
assertThat(hits, greaterThanOrEqualTo(1));
12361262
} catch (ResponseException e) {
12371263
// Throw AssertionError instead of an exception if the search fails so that assertBusy works as expected
12381264
logger.error(e);

0 commit comments

Comments
 (0)