From 43fb7846df9b2dc2e2a73eddc8bb24745a21baaf Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Mon, 6 Jan 2020 09:58:24 -0700 Subject: [PATCH] Add aditional logging for ILM history store tests (#50624) 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 #50353 Co-authored-by: Elastic Machine --- .../ilm/TimeSeriesLifecycleActionsIT.java | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java b/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java index 09d65cc185122..43bdfe5974325 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java @@ -1077,9 +1077,8 @@ public void testRolloverStepRetriesUntilRolledOverIndexIsDeleted() throws Except assertBusy(() -> assertThat(getStepKeyForIndex(index), equalTo(TerminalPolicyStep.KEY))); } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/50353") public void testHistoryIsWrittenWithSuccess() throws Exception { - String index = "index"; + String index = "success-index"; createNewSingletonPolicy("hot", new RolloverAction(null, null, 1L)); Request createIndexTemplate = new Request("PUT", "_template/rolling_indexes"); @@ -1121,9 +1120,8 @@ public void testHistoryIsWrittenWithSuccess() throws Exception { } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/50353") public void testHistoryIsWrittenWithFailure() throws Exception { - String index = "index"; + String index = "failure-index"; createNewSingletonPolicy("hot", new RolloverAction(null, null, 1L)); Request createIndexTemplate = new Request("PUT", "_template/rolling_indexes"); @@ -1150,9 +1148,8 @@ public void testHistoryIsWrittenWithFailure() throws Exception { assertBusy(() -> assertHistoryIsPresent(policy, index + "-1", false, "ERROR"), 30, TimeUnit.SECONDS); } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/50353") public void testHistoryIsWrittenWithDeletion() throws Exception { - String index = "index"; + String index = "delete-index"; createNewSingletonPolicy("delete", new DeleteAction()); Request createIndexTemplate = new Request("PUT", "_template/delete_indexes"); @@ -1231,8 +1228,37 @@ private void assertHistoryIsPresent(String policyName, String indexName, boolean historyResponseMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true); } logger.info("--> history response: {}", historyResponseMap); - assertThat((int)((Map) ((Map) historyResponseMap.get("hits")).get("total")).get("value"), - greaterThanOrEqualTo(1)); + int hits = (int)((Map) ((Map) historyResponseMap.get("hits")).get("total")).get("value"); + + // For a failure, print out whatever history we *do* have for the index + if (hits == 0) { + final Request allResults = new Request("GET", "ilm-history*/_search"); + allResults.setJsonEntity("{\n" + + " \"query\": {\n" + + " \"bool\": {\n" + + " \"must\": [\n" + + " {\n" + + " \"term\": {\n" + + " \"policy\": \"" + policyName + "\"\n" + + " }\n" + + " },\n" + + " {\n" + + " \"term\": {\n" + + " \"index\": \"" + indexName + "\"\n" + + " }\n" + + " }\n" + + " ]\n" + + " }\n" + + " }\n" + + "}"); + final Response allResultsResp = client().performRequest(historySearchRequest); + Map allResultsMap; + try (InputStream is = allResultsResp.getEntity().getContent()) { + allResultsMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true); + } + logger.info("--> expected at least 1 hit, got 0. All history for index [{}]: {}", index, allResultsMap); + } + assertThat(hits, greaterThanOrEqualTo(1)); } catch (ResponseException e) { // Throw AssertionError instead of an exception if the search fails so that assertBusy works as expected logger.error(e);