Skip to content

Commit 488d4ae

Browse files
talevyjasontedor
authored andcommitted
render non-ElasticsearchException in ILM (#31284)
ILM was rendering exceptions using the exception helper that basically ignores simply rendering non-elasticsearch exceptions when no details are desired. This commit updates the method used to still be a rather simple rendering of the exception. The rendering lacks all the causes, but does a sufficient job in rendering the top-level message for one of our most expected exceptions... IllegalArgumentException
1 parent 73614f2 commit 488d4ae

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ static ClusterState moveClusterStateToErrorStep(Index index, ClusterState cluste
196196
IndexMetaData idxMeta = clusterState.getMetaData().index(index);
197197
XContentBuilder causeXContentBuilder = JsonXContent.contentBuilder();
198198
causeXContentBuilder.startObject();
199-
ElasticsearchException.generateFailureXContent(causeXContentBuilder, ToXContent.EMPTY_PARAMS, cause, false);
199+
ElasticsearchException.generateThrowableXContent(causeXContentBuilder, ToXContent.EMPTY_PARAMS, cause);
200200
causeXContentBuilder.endObject();
201201
Settings.Builder indexSettings = moveIndexSettingsToNextStep(idxMeta.getSettings(), currentStep,
202202
new StepKey(currentStep.getPhase(), currentStep.getAction(), ErrorStep.NAME), nowSupplier)

x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,15 @@ public void testMoveClusterStateToErrorStep() throws IOException {
693693
.put(LifecycleSettings.LIFECYCLE_ACTION, currentStep.getAction())
694694
.put(LifecycleSettings.LIFECYCLE_STEP, currentStep.getName()));
695695
Index index = clusterState.metaData().index(indexName).getIndex();
696+
696697
ClusterState newClusterState = IndexLifecycleRunner.moveClusterStateToErrorStep(index, clusterState, currentStep, cause, () -> now);
697-
assertClusterStateOnErrorStep(clusterState, index, currentStep, newClusterState, cause, now);
698+
assertClusterStateOnErrorStep(clusterState, index, currentStep, newClusterState, now,
699+
"{\"type\":\"exception\",\"reason\":\"THIS IS AN EXPECTED CAUSE\"}");
700+
701+
cause = new IllegalArgumentException("non elasticsearch-exception");
702+
newClusterState = IndexLifecycleRunner.moveClusterStateToErrorStep(index, clusterState, currentStep, cause, () -> now);
703+
assertClusterStateOnErrorStep(clusterState, index, currentStep, newClusterState, now,
704+
"{\"type\":\"illegal_argument_exception\",\"reason\":\"non elasticsearch-exception\"}");
698705
}
699706

700707
public void testMoveClusterStateToFailedStep() {
@@ -966,13 +973,8 @@ public static void assertClusterStateOnNextStep(ClusterState oldClusterState, In
966973
assertEquals("", LifecycleSettings.LIFECYCLE_STEP_INFO_SETTING.get(newIndexSettings));
967974
}
968975

969-
private void assertClusterStateOnErrorStep(ClusterState oldClusterState, Index index, StepKey currentStep, ClusterState newClusterState,
970-
Exception cause, long now) throws IOException {
971-
XContentBuilder causeXContentBuilder = JsonXContent.contentBuilder();
972-
causeXContentBuilder.startObject();
973-
ElasticsearchException.generateFailureXContent(causeXContentBuilder, ToXContent.EMPTY_PARAMS, cause, false);
974-
causeXContentBuilder.endObject();
975-
String expectedCauseValue = BytesReference.bytes(causeXContentBuilder).utf8ToString();
976+
private void assertClusterStateOnErrorStep(ClusterState oldClusterState, Index index, StepKey currentStep,
977+
ClusterState newClusterState, long now, String expectedCauseValue) throws IOException {
976978
assertNotSame(oldClusterState, newClusterState);
977979
MetaData newMetadata = newClusterState.metaData();
978980
assertNotSame(oldClusterState.metaData(), newMetadata);

x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/MoveToErrorStepUpdateTaskTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void testExecuteSuccessfullyMoved() throws IOException {
6868

6969
XContentBuilder causeXContentBuilder = JsonXContent.contentBuilder();
7070
causeXContentBuilder.startObject();
71-
ElasticsearchException.generateFailureXContent(causeXContentBuilder, ToXContent.EMPTY_PARAMS, cause, false);
71+
ElasticsearchException.generateThrowableXContent(causeXContentBuilder, ToXContent.EMPTY_PARAMS, cause);
7272
causeXContentBuilder.endObject();
7373
String expectedCauseValue = BytesReference.bytes(causeXContentBuilder).utf8ToString();
7474
assertThat(LifecycleSettings.LIFECYCLE_STEP_INFO_SETTING.get(newState.metaData().index(index).getSettings()),

0 commit comments

Comments
 (0)