Skip to content

Commit 171955f

Browse files
committed
Add additional ILM history store logging
This commit adds additional logging as well as applies some test fixes in an attempt to address elastic#50353.
1 parent 18c98ea commit 171955f

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

+6-4
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;
@@ -1383,7 +1384,7 @@ public void testHistoryIsWrittenWithSuccess() throws Exception {
13831384
assertBusy(() -> assertHistoryIsPresent(policy, index + "-000002", true, "check-rollover-ready"), 30, TimeUnit.SECONDS);
13841385
}
13851386

1386-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/50353")
1387+
@TestIssueLogging(value="org.elasticsearch.xpack.ilm.history:TRACE", issueUrl="https://github.com/elastic/elasticsearch/issues/50353")
13871388
public void testHistoryIsWrittenWithFailure() throws Exception {
13881389
String index = "failure-index";
13891390

@@ -1573,9 +1574,10 @@ private void assertHistoryIsPresent(String policyName, String indexName, boolean
15731574
// This method should be called inside an assertBusy, it has no retry logic of its own
15741575
private void assertHistoryIsPresent(String policyName, String indexName, boolean success,
15751576
@Nullable String phase, @Nullable String action, String stepName) throws IOException {
1577+
assertOK(client().performRequest(new Request("POST", indexName + "/_refresh")));
15761578
logger.info("--> checking for history item [{}], [{}], success: [{}], phase: [{}], action: [{}], step: [{}]",
15771579
policyName, indexName, success, phase, action, stepName);
1578-
final Request historySearchRequest = new Request("GET", "ilm-history*/_search");
1580+
final Request historySearchRequest = new Request("GET", "ilm-history*/_search?expand_wildcards=all");
15791581
historySearchRequest.setJsonEntity("{\n" +
15801582
" \"query\": {\n" +
15811583
" \"bool\": {\n" +
@@ -1642,7 +1644,7 @@ private void assertHistoryIsPresent(String policyName, String indexName, boolean
16421644
try (InputStream is = allResultsResp.getEntity().getContent()) {
16431645
allResultsMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true);
16441646
}
1645-
logger.info("--> expected at least 1 hit, got 0. All history for index [{}]: {}", index, allResultsMap);
1647+
logger.info("--> expected at least 1 hit, got 0. All history for index [{}]: {}", indexName, allResultsMap);
16461648
}
16471649
assertThat(hits, greaterThanOrEqualTo(1));
16481650
} catch (ResponseException e) {
@@ -1652,7 +1654,7 @@ private void assertHistoryIsPresent(String policyName, String indexName, boolean
16521654
}
16531655

16541656
// Finally, check that the history index is in a good state
1655-
Step.StepKey stepKey = getStepKeyForIndex("ilm-history-1-000001");
1657+
Step.StepKey stepKey = getStepKeyForIndex("ilm-history-2-000001");
16561658
assertEquals("hot", stepKey.getPhase());
16571659
assertEquals(RolloverAction.NAME, stepKey.getAction());
16581660
assertEquals(WaitForRolloverReadyStep.NAME, stepKey.getName());

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

+13-1
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)