Skip to content

Add additional ILM history store logging #52539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.test.junit.annotations.TestIssueLogging;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.xpack.core.ilm.AllocateAction;
import org.elasticsearch.xpack.core.ilm.DeleteAction;
Expand Down Expand Up @@ -1383,7 +1384,7 @@ public void testHistoryIsWrittenWithSuccess() throws Exception {
assertBusy(() -> assertHistoryIsPresent(policy, index + "-000002", true, "check-rollover-ready"), 30, TimeUnit.SECONDS);
}

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

Expand Down Expand Up @@ -1573,9 +1574,10 @@ private void assertHistoryIsPresent(String policyName, String indexName, boolean
// This method should be called inside an assertBusy, it has no retry logic of its own
private void assertHistoryIsPresent(String policyName, String indexName, boolean success,
@Nullable String phase, @Nullable String action, String stepName) throws IOException {
assertOK(client().performRequest(new Request("POST", indexName + "/_refresh")));
logger.info("--> checking for history item [{}], [{}], success: [{}], phase: [{}], action: [{}], step: [{}]",
policyName, indexName, success, phase, action, stepName);
final Request historySearchRequest = new Request("GET", "ilm-history*/_search");
final Request historySearchRequest = new Request("GET", "ilm-history*/_search?expand_wildcards=all");
historySearchRequest.setJsonEntity("{\n" +
" \"query\": {\n" +
" \"bool\": {\n" +
Expand Down Expand Up @@ -1642,7 +1644,7 @@ private void assertHistoryIsPresent(String policyName, String indexName, boolean
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);
logger.info("--> expected at least 1 hit, got 0. All history for index [{}]: {}", indexName, allResultsMap);
}
assertThat(hits, greaterThanOrEqualTo(1));
} catch (ResponseException e) {
Expand All @@ -1652,7 +1654,7 @@ private void assertHistoryIsPresent(String policyName, String indexName, boolean
}

// Finally, check that the history index is in a good state
Step.StepKey stepKey = getStepKeyForIndex("ilm-history-1-000001");
Step.StepKey stepKey = getStepKeyForIndex("ilm-history-2-000001");
assertEquals("hot", stepKey.getPhase());
assertEquals(RolloverAction.NAME, stepKey.getAction());
assertEquals(WaitForRolloverReadyStep.NAME, stepKey.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -91,16 +92,27 @@ public void beforeBulk(long executionId, BulkRequest request) {
.collect(Collectors.joining("\n"))), e);
throw new ElasticsearchException(e);
}
if (logger.isTraceEnabled()) {
logger.info("about to index: {}",
request.requests().stream()
.map(dwr -> ((IndexRequest) dwr).sourceAsMap())
.map(Objects::toString)
.collect(Collectors.joining(",")));
}
}

@Override
public void afterBulk(long executionId, BulkRequest request, BulkResponse response) {
long items = request.numberOfActions();
if (logger.isTraceEnabled()) {
logger.trace("indexed [{}] items into ILM history index [{}]", items,
logger.trace("indexed [{}] items into ILM history index [{}], items: {}", items,
Arrays.stream(response.getItems())
.map(BulkItemResponse::getIndex)
.distinct()
.collect(Collectors.joining(",")),
request.requests().stream()
.map(dwr -> ((IndexRequest) dwr).sourceAsMap())
.map(Objects::toString)
.collect(Collectors.joining(",")));
}
if (response.hasFailures()) {
Expand Down