Include stack trace with ILM error in explain output (#35512)
This changes the stacktrace to be included with the ILM explain error when the index is an on ERROR step. Before: ```json { "indices" : { "foo" : { "index" : "foo", "managed" : true, "policy" : "bad", "lifecycle_date_millis" : 1542131670601, "phase" : "warm", "phase_time_millis" : 1542131676335, "action" : "shrink", "action_time_millis" : 1542131676335, "step" : "ERROR", "step_time_millis" : 1542131676451, "failed_step" : "shrink", "step_info" : { "type" : "illegal_argument_exception", "reason" : "the number of target shards [13] must be less that the number of source shards [2]" }, "phase_execution" : { "policy" : "bad", "phase_definition" : { "min_age" : "5s", "actions" : { "shrink" : { "number_of_shards" : 13 } } }, "version" : 1, "modified_date_in_millis" : 1542131669839 } } } } ``` After ``` { "indices" : { "foo" : { "index" : "foo", "managed" : true, "policy" : "bad", "lifecycle_date_millis" : 1542131670601, "phase" : "warm", "phase_time_millis" : 1542131676335, "action" : "shrink", "action_time_millis" : 1542131676335, "step" : "ERROR", "step_time_millis" : 1542131676451, "failed_step" : "shrink", "step_info" : { "type" : "illegal_argument_exception", "reason" : "the number of target shards [13] must be less that the number of source shards [2]", "stack_trace" : "java.lang.IllegalArgumentException: the number of target shards [13] must be less that the number of source shards [2]\n\tat org.elasticsearch.cluster.metadata.IndexMetaData.selectShrinkShards(IndexMetaData.java:1509)\n\tat org.elasticsearch.action.admin.indices.shrink.TransportResizeAction.prepareCreateIndexRequest(TransportResizeAction.java:146)\n\tat org.elasticsearch.action.admin.indices.shrink.TransportResizeAction$1.onResponse(TransportResizeAction.java:104)\n\tat org.elasticsearch.action.admin.indices.shrink.TransportResizeAction$1.onResponse(TransportResizeAction.java:101)\n\tat org.elasticsearch.action.support.TransportAction$1.onResponse(TransportAction.java:64)\n\tat org.elasticsearch.action.support.TransportAction$1.onResponse(TransportAction.java:60)\n\tat org.elasticsearch.action.support.broadcast.node.TransportBroadcastByNodeAction$AsyncAction.onCompletion(TransportBroadcastByNodeAction.java:383)\n\tat org.elasticsearch.action.support.broadcast.node.TransportBroadcastByNodeAction$AsyncAction.onNodeResponse(TransportBroadcastByNodeAction.java:352)\n\tat org.elasticsearch.action.support.broadcast.node.TransportBroadcastByNodeAction$AsyncAction$1.handleResponse(TransportBroadcastByNodeAction.java:324)\n\tat org.elasticsearch.action.support.broadcast.node.TransportBroadcastByNodeAction$AsyncAction$1.handleResponse(TransportBroadcastByNodeAction.java:314)\n\tat org.elasticsearch.transport.TransportService$ContextRestoreResponseHandler.handleResponse(TransportService.java:1117)\n\tat org.elasticsearch.transport.TransportService$DirectResponseChannel.processResponse(TransportService.java:1198)\n\tat org.elasticsearch.transport.TransportService$DirectResponseChannel.sendResponse(TransportService.java:1178)\n\tat org.elasticsearch.transport.TaskTransportChannel.sendResponse(TaskTransportChannel.java:54)\n\tat org.elasticsearch.action.support.broadcast.node.TransportBroadcastByNodeAction$BroadcastByNodeTransportRequestHandler.messageReceived(TransportBroadcastByNodeAction.java:417)\n\tat org.elasticsearch.action.support.broadcast.node.TransportBroadcastByNodeAction$BroadcastByNodeTransportRequestHandler.messageReceived(TransportBroadcastByNodeAction.java:391)\n\tat org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler$1.doRun(SecurityServerTransportInterceptor.java:251)\n\tat org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)\n\tat org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler.messageReceived(SecurityServerTransportInterceptor.java:309)\n\tat org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:63)\n\tat org.elasticsearch.transport.TransportService$7.doRun(TransportService.java:714)\n\tat org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:726)\n\tat org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\n\tat java.base/java.lang.Thread.run(Thread.java:834)\n" }, "phase_execution" : { "policy" : "bad", "phase_definition" : { "min_age" : "5s", "actions" : { "shrink" : { "number_of_shards" : 13 } } }, "version" : 1, "modified_date_in_millis" : 1542131669839 } } } } ``` Resolves #35498
This commit is contained in:
parent
fc774a3776
commit
8ea999e489
|
@ -42,13 +42,17 @@ import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey;
|
||||||
import org.elasticsearch.xpack.core.indexlifecycle.TerminalPolicyStep;
|
import org.elasticsearch.xpack.core.indexlifecycle.TerminalPolicyStep;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.LongSupplier;
|
import java.util.function.LongSupplier;
|
||||||
|
|
||||||
|
import static org.elasticsearch.ElasticsearchException.REST_EXCEPTION_SKIP_STACK_TRACE;
|
||||||
import static org.elasticsearch.xpack.core.indexlifecycle.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY;
|
import static org.elasticsearch.xpack.core.indexlifecycle.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY;
|
||||||
|
|
||||||
public class IndexLifecycleRunner {
|
public class IndexLifecycleRunner {
|
||||||
private static final Logger logger = LogManager.getLogger(IndexLifecycleRunner.class);
|
private static final Logger logger = LogManager.getLogger(IndexLifecycleRunner.class);
|
||||||
|
private static final ToXContent.Params STACKTRACE_PARAMS =
|
||||||
|
new ToXContent.MapParams(Collections.singletonMap(REST_EXCEPTION_SKIP_STACK_TRACE, "false"));
|
||||||
private PolicyStepsRegistry stepRegistry;
|
private PolicyStepsRegistry stepRegistry;
|
||||||
private ClusterService clusterService;
|
private ClusterService clusterService;
|
||||||
private LongSupplier nowSupplier;
|
private LongSupplier nowSupplier;
|
||||||
|
@ -323,7 +327,7 @@ public class IndexLifecycleRunner {
|
||||||
.get(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(idxMeta.getSettings()));
|
.get(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(idxMeta.getSettings()));
|
||||||
XContentBuilder causeXContentBuilder = JsonXContent.contentBuilder();
|
XContentBuilder causeXContentBuilder = JsonXContent.contentBuilder();
|
||||||
causeXContentBuilder.startObject();
|
causeXContentBuilder.startObject();
|
||||||
ElasticsearchException.generateThrowableXContent(causeXContentBuilder, ToXContent.EMPTY_PARAMS, cause);
|
ElasticsearchException.generateThrowableXContent(causeXContentBuilder, STACKTRACE_PARAMS, cause);
|
||||||
causeXContentBuilder.endObject();
|
causeXContentBuilder.endObject();
|
||||||
LifecycleExecutionState nextStepState = moveExecutionStateToNextStep(policyMetadata,
|
LifecycleExecutionState nextStepState = moveExecutionStateToNextStep(policyMetadata,
|
||||||
LifecycleExecutionState.fromIndexMetadata(idxMeta), currentStep, new StepKey(currentStep.getPhase(),
|
LifecycleExecutionState.fromIndexMetadata(idxMeta), currentStep, new StepKey(currentStep.getPhase(),
|
||||||
|
|
|
@ -48,6 +48,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import static org.elasticsearch.xpack.core.indexlifecycle.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY;
|
import static org.elasticsearch.xpack.core.indexlifecycle.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY;
|
||||||
import static org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyTestsUtils.newTestLifecyclePolicy;
|
import static org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyTestsUtils.newTestLifecyclePolicy;
|
||||||
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.nullValue;
|
import static org.hamcrest.Matchers.nullValue;
|
||||||
import static org.hamcrest.Matchers.sameInstance;
|
import static org.hamcrest.Matchers.sameInstance;
|
||||||
|
@ -270,7 +271,8 @@ public class ExecuteStepsUpdateTaskTests extends ESTestCase {
|
||||||
assertThat(task.getNextStepKey(), equalTo(secondStep.getKey()));
|
assertThat(task.getNextStepKey(), equalTo(secondStep.getKey()));
|
||||||
assertThat(lifecycleState.getPhaseTime(), nullValue());
|
assertThat(lifecycleState.getPhaseTime(), nullValue());
|
||||||
assertThat(lifecycleState.getActionTime(), nullValue());
|
assertThat(lifecycleState.getActionTime(), nullValue());
|
||||||
assertThat(lifecycleState.getStepInfo(), equalTo("{\"type\":\"runtime_exception\",\"reason\":\"error\"}"));
|
assertThat(lifecycleState.getStepInfo(),
|
||||||
|
containsString("{\"type\":\"runtime_exception\",\"reason\":\"error\",\"stack_trace\":\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClusterWaitStepThrowsException() throws IOException {
|
public void testClusterWaitStepThrowsException() throws IOException {
|
||||||
|
@ -289,7 +291,8 @@ public class ExecuteStepsUpdateTaskTests extends ESTestCase {
|
||||||
assertThat(task.getNextStepKey(), equalTo(thirdStepKey));
|
assertThat(task.getNextStepKey(), equalTo(thirdStepKey));
|
||||||
assertThat(lifecycleState.getPhaseTime(), nullValue());
|
assertThat(lifecycleState.getPhaseTime(), nullValue());
|
||||||
assertThat(lifecycleState.getActionTime(), nullValue());
|
assertThat(lifecycleState.getActionTime(), nullValue());
|
||||||
assertThat(lifecycleState.getStepInfo(), equalTo("{\"type\":\"runtime_exception\",\"reason\":\"error\"}"));
|
assertThat(lifecycleState.getStepInfo(),
|
||||||
|
containsString("{\"type\":\"runtime_exception\",\"reason\":\"error\",\"stack_trace\":\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setStateToKey(StepKey stepKey) throws IOException {
|
private void setStateToKey(StepKey stepKey) throws IOException {
|
||||||
|
|
|
@ -73,6 +73,7 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.elasticsearch.xpack.core.indexlifecycle.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY;
|
import static org.elasticsearch.xpack.core.indexlifecycle.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY;
|
||||||
import static org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyTestsUtils.newTestLifecyclePolicy;
|
import static org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyTestsUtils.newTestLifecyclePolicy;
|
||||||
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
@ -853,12 +854,12 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
||||||
|
|
||||||
ClusterState newClusterState = IndexLifecycleRunner.moveClusterStateToErrorStep(index, clusterState, currentStep, cause, () -> now);
|
ClusterState newClusterState = IndexLifecycleRunner.moveClusterStateToErrorStep(index, clusterState, currentStep, cause, () -> now);
|
||||||
assertClusterStateOnErrorStep(clusterState, index, currentStep, newClusterState, now,
|
assertClusterStateOnErrorStep(clusterState, index, currentStep, newClusterState, now,
|
||||||
"{\"type\":\"exception\",\"reason\":\"THIS IS AN EXPECTED CAUSE\"}");
|
"{\"type\":\"exception\",\"reason\":\"THIS IS AN EXPECTED CAUSE\"");
|
||||||
|
|
||||||
cause = new IllegalArgumentException("non elasticsearch-exception");
|
cause = new IllegalArgumentException("non elasticsearch-exception");
|
||||||
newClusterState = IndexLifecycleRunner.moveClusterStateToErrorStep(index, clusterState, currentStep, cause, () -> now);
|
newClusterState = IndexLifecycleRunner.moveClusterStateToErrorStep(index, clusterState, currentStep, cause, () -> now);
|
||||||
assertClusterStateOnErrorStep(clusterState, index, currentStep, newClusterState, now,
|
assertClusterStateOnErrorStep(clusterState, index, currentStep, newClusterState, now,
|
||||||
"{\"type\":\"illegal_argument_exception\",\"reason\":\"non elasticsearch-exception\"}");
|
"{\"type\":\"illegal_argument_exception\",\"reason\":\"non elasticsearch-exception\",\"stack_trace\":\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMoveClusterStateToFailedStep() {
|
public void testMoveClusterStateToFailedStep() {
|
||||||
|
@ -1267,7 +1268,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
||||||
assertEquals(currentStep.getAction(), newLifecycleState.getAction());
|
assertEquals(currentStep.getAction(), newLifecycleState.getAction());
|
||||||
assertEquals(ErrorStep.NAME, newLifecycleState.getStep());
|
assertEquals(ErrorStep.NAME, newLifecycleState.getStep());
|
||||||
assertEquals(currentStep.getName(), newLifecycleState.getFailedStep());
|
assertEquals(currentStep.getName(), newLifecycleState.getFailedStep());
|
||||||
assertEquals(expectedCauseValue, newLifecycleState.getStepInfo());
|
assertThat(newLifecycleState.getStepInfo(), containsString(expectedCauseValue));
|
||||||
assertEquals(oldLifecycleState.getPhaseTime(), newLifecycleState.getPhaseTime());
|
assertEquals(oldLifecycleState.getPhaseTime(), newLifecycleState.getPhaseTime());
|
||||||
assertEquals(oldLifecycleState.getActionTime(), newLifecycleState.getActionTime());
|
assertEquals(oldLifecycleState.getActionTime(), newLifecycleState.getActionTime());
|
||||||
assertEquals(now, newLifecycleState.getStepTime().longValue());
|
assertEquals(now, newLifecycleState.getStepTime().longValue());
|
||||||
|
|
|
@ -33,6 +33,7 @@ import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import static org.elasticsearch.xpack.core.indexlifecycle.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY;
|
import static org.elasticsearch.xpack.core.indexlifecycle.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY;
|
||||||
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.nullValue;
|
import static org.hamcrest.Matchers.nullValue;
|
||||||
import static org.hamcrest.Matchers.sameInstance;
|
import static org.hamcrest.Matchers.sameInstance;
|
||||||
|
@ -86,7 +87,8 @@ public class MoveToErrorStepUpdateTaskTests extends ESTestCase {
|
||||||
ElasticsearchException.generateThrowableXContent(causeXContentBuilder, ToXContent.EMPTY_PARAMS, cause);
|
ElasticsearchException.generateThrowableXContent(causeXContentBuilder, ToXContent.EMPTY_PARAMS, cause);
|
||||||
causeXContentBuilder.endObject();
|
causeXContentBuilder.endObject();
|
||||||
String expectedCauseValue = BytesReference.bytes(causeXContentBuilder).utf8ToString();
|
String expectedCauseValue = BytesReference.bytes(causeXContentBuilder).utf8ToString();
|
||||||
assertThat(lifecycleState.getStepInfo(), equalTo(expectedCauseValue));
|
assertThat(lifecycleState.getStepInfo(),
|
||||||
|
containsString("{\"type\":\"exception\",\"reason\":\"THIS IS AN EXPECTED CAUSE\",\"stack_trace\":\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExecuteNoopDifferentStep() throws IOException {
|
public void testExecuteNoopDifferentStep() throws IOException {
|
||||||
|
|
Loading…
Reference in New Issue