diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java index 2f7947bb517..ef22d2c8401 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java @@ -42,13 +42,17 @@ import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey; import org.elasticsearch.xpack.core.indexlifecycle.TerminalPolicyStep; import java.io.IOException; +import java.util.Collections; import java.util.List; 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; public class IndexLifecycleRunner { 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 ClusterService clusterService; private LongSupplier nowSupplier; @@ -323,7 +327,7 @@ public class IndexLifecycleRunner { .get(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(idxMeta.getSettings())); XContentBuilder causeXContentBuilder = JsonXContent.contentBuilder(); causeXContentBuilder.startObject(); - ElasticsearchException.generateThrowableXContent(causeXContentBuilder, ToXContent.EMPTY_PARAMS, cause); + ElasticsearchException.generateThrowableXContent(causeXContentBuilder, STACKTRACE_PARAMS, cause); causeXContentBuilder.endObject(); LifecycleExecutionState nextStepState = moveExecutionStateToNextStep(policyMetadata, LifecycleExecutionState.fromIndexMetadata(idxMeta), currentStep, new StepKey(currentStep.getPhase(), diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/ExecuteStepsUpdateTaskTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/ExecuteStepsUpdateTaskTests.java index 21f2b0e7093..4611618b2cd 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/ExecuteStepsUpdateTaskTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/ExecuteStepsUpdateTaskTests.java @@ -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.LifecyclePolicyTestsUtils.newTestLifecyclePolicy; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.sameInstance; @@ -270,7 +271,8 @@ public class ExecuteStepsUpdateTaskTests extends ESTestCase { assertThat(task.getNextStepKey(), equalTo(secondStep.getKey())); assertThat(lifecycleState.getPhaseTime(), 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 { @@ -289,7 +291,8 @@ public class ExecuteStepsUpdateTaskTests extends ESTestCase { assertThat(task.getNextStepKey(), equalTo(thirdStepKey)); assertThat(lifecycleState.getPhaseTime(), 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 { diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java index 8117207f2be..63ee9349043 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java @@ -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.LifecyclePolicyTestsUtils.newTestLifecyclePolicy; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.mockito.Mockito.mock; @@ -853,12 +854,12 @@ public class IndexLifecycleRunnerTests extends ESTestCase { ClusterState newClusterState = IndexLifecycleRunner.moveClusterStateToErrorStep(index, clusterState, currentStep, cause, () -> 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"); newClusterState = IndexLifecycleRunner.moveClusterStateToErrorStep(index, clusterState, currentStep, cause, () -> 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() { @@ -1267,7 +1268,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase { assertEquals(currentStep.getAction(), newLifecycleState.getAction()); assertEquals(ErrorStep.NAME, newLifecycleState.getStep()); assertEquals(currentStep.getName(), newLifecycleState.getFailedStep()); - assertEquals(expectedCauseValue, newLifecycleState.getStepInfo()); + assertThat(newLifecycleState.getStepInfo(), containsString(expectedCauseValue)); assertEquals(oldLifecycleState.getPhaseTime(), newLifecycleState.getPhaseTime()); assertEquals(oldLifecycleState.getActionTime(), newLifecycleState.getActionTime()); assertEquals(now, newLifecycleState.getStepTime().longValue()); diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/MoveToErrorStepUpdateTaskTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/MoveToErrorStepUpdateTaskTests.java index dc3a6602f39..3ad3f27ebdf 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/MoveToErrorStepUpdateTaskTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/MoveToErrorStepUpdateTaskTests.java @@ -33,6 +33,7 @@ import java.io.IOException; import java.util.Collections; 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.nullValue; import static org.hamcrest.Matchers.sameInstance; @@ -86,7 +87,8 @@ public class MoveToErrorStepUpdateTaskTests extends ESTestCase { ElasticsearchException.generateThrowableXContent(causeXContentBuilder, ToXContent.EMPTY_PARAMS, cause); causeXContentBuilder.endObject(); 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 {