Skip to content

Commit 44fff55

Browse files
authored
Add additional ILM history store logging (#52539)
This commit adds additional logging as well as applies some test fixes in an attempt to address #50353.
1 parent 16af047 commit 44fff55

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.elasticsearch.common.xcontent.XContentType;
2626
import org.elasticsearch.common.xcontent.json.JsonXContent;
2727
import org.elasticsearch.index.IndexSettings;
28+
import org.elasticsearch.test.junit.annotations.TestIssueLogging;
2829
import org.elasticsearch.test.rest.ESRestTestCase;
2930
import org.elasticsearch.xpack.core.ilm.AllocateAction;
3031
import org.elasticsearch.xpack.core.ilm.DeleteAction;
@@ -1403,7 +1404,7 @@ public void testHistoryIsWrittenWithSuccess() throws Exception {
14031404
assertBusy(() -> assertHistoryIsPresent(policy, index + "-000002", true, "check-rollover-ready"), 30, TimeUnit.SECONDS);
14041405
}
14051406

1406-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/50353")
1407+
@TestIssueLogging(value="org.elasticsearch.xpack.ilm.history:TRACE", issueUrl="https://github.com/elastic/elasticsearch/issues/50353")
14071408
public void testHistoryIsWrittenWithFailure() throws Exception {
14081409
String index = "failure-index";
14091410

@@ -1593,9 +1594,10 @@ private void assertHistoryIsPresent(String policyName, String indexName, boolean
15931594
// This method should be called inside an assertBusy, it has no retry logic of its own
15941595
private void assertHistoryIsPresent(String policyName, String indexName, boolean success,
15951596
@Nullable String phase, @Nullable String action, String stepName) throws IOException {
1597+
assertOK(client().performRequest(new Request("POST", indexName + "/_refresh")));
15961598
logger.info("--> checking for history item [{}], [{}], success: [{}], phase: [{}], action: [{}], step: [{}]",
15971599
policyName, indexName, success, phase, action, stepName);
1598-
final Request historySearchRequest = new Request("GET", "ilm-history*/_search");
1600+
final Request historySearchRequest = new Request("GET", "ilm-history*/_search?expand_wildcards=all");
15991601
historySearchRequest.setJsonEntity("{\n" +
16001602
" \"query\": {\n" +
16011603
" \"bool\": {\n" +
@@ -1662,7 +1664,7 @@ private void assertHistoryIsPresent(String policyName, String indexName, boolean
16621664
try (InputStream is = allResultsResp.getEntity().getContent()) {
16631665
allResultsMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true);
16641666
}
1665-
logger.info("--> expected at least 1 hit, got 0. All history for index [{}]: {}", index, allResultsMap);
1667+
logger.info("--> expected at least 1 hit, got 0. All history for index [{}]: {}", indexName, allResultsMap);
16661668
}
16671669
assertThat(hits, greaterThanOrEqualTo(1));
16681670
} catch (ResponseException e) {
@@ -1672,7 +1674,7 @@ private void assertHistoryIsPresent(String policyName, String indexName, boolean
16721674
}
16731675

16741676
// Finally, check that the history index is in a good state
1675-
Step.StepKey stepKey = getStepKeyForIndex("ilm-history-1-000001");
1677+
Step.StepKey stepKey = getStepKeyForIndex("ilm-history-2-000001");
16761678
assertEquals("hot", stepKey.getPhase());
16771679
assertEquals(RolloverAction.NAME, stepKey.getAction());
16781680
assertEquals(WaitForRolloverReadyStep.NAME, stepKey.getName());

x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/history/ILMHistoryStore.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.io.IOException;
3939
import java.util.Arrays;
4040
import java.util.Map;
41+
import java.util.Objects;
4142
import java.util.concurrent.CompletableFuture;
4243
import java.util.concurrent.TimeUnit;
4344
import java.util.stream.Collectors;
@@ -91,16 +92,27 @@ public void beforeBulk(long executionId, BulkRequest request) {
9192
.collect(Collectors.joining("\n"))), e);
9293
throw new ElasticsearchException(e);
9394
}
95+
if (logger.isTraceEnabled()) {
96+
logger.info("about to index: {}",
97+
request.requests().stream()
98+
.map(dwr -> ((IndexRequest) dwr).sourceAsMap())
99+
.map(Objects::toString)
100+
.collect(Collectors.joining(",")));
101+
}
94102
}
95103

96104
@Override
97105
public void afterBulk(long executionId, BulkRequest request, BulkResponse response) {
98106
long items = request.numberOfActions();
99107
if (logger.isTraceEnabled()) {
100-
logger.trace("indexed [{}] items into ILM history index [{}]", items,
108+
logger.trace("indexed [{}] items into ILM history index [{}], items: {}", items,
101109
Arrays.stream(response.getItems())
102110
.map(BulkItemResponse::getIndex)
103111
.distinct()
112+
.collect(Collectors.joining(",")),
113+
request.requests().stream()
114+
.map(dwr -> ((IndexRequest) dwr).sourceAsMap())
115+
.map(Objects::toString)
104116
.collect(Collectors.joining(",")));
105117
}
106118
if (response.hasFailures()) {

0 commit comments

Comments
 (0)