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
This commit is contained in:
parent
01939794fe
commit
aa6944a719
|
@ -196,7 +196,7 @@ public class IndexLifecycleRunner {
|
||||||
IndexMetaData idxMeta = clusterState.getMetaData().index(index);
|
IndexMetaData idxMeta = clusterState.getMetaData().index(index);
|
||||||
XContentBuilder causeXContentBuilder = JsonXContent.contentBuilder();
|
XContentBuilder causeXContentBuilder = JsonXContent.contentBuilder();
|
||||||
causeXContentBuilder.startObject();
|
causeXContentBuilder.startObject();
|
||||||
ElasticsearchException.generateFailureXContent(causeXContentBuilder, ToXContent.EMPTY_PARAMS, cause, false);
|
ElasticsearchException.generateThrowableXContent(causeXContentBuilder, ToXContent.EMPTY_PARAMS, cause);
|
||||||
causeXContentBuilder.endObject();
|
causeXContentBuilder.endObject();
|
||||||
Settings.Builder indexSettings = moveIndexSettingsToNextStep(idxMeta.getSettings(), currentStep,
|
Settings.Builder indexSettings = moveIndexSettingsToNextStep(idxMeta.getSettings(), currentStep,
|
||||||
new StepKey(currentStep.getPhase(), currentStep.getAction(), ErrorStep.NAME), nowSupplier)
|
new StepKey(currentStep.getPhase(), currentStep.getAction(), ErrorStep.NAME), nowSupplier)
|
||||||
|
|
|
@ -693,8 +693,15 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
||||||
.put(LifecycleSettings.LIFECYCLE_ACTION, currentStep.getAction())
|
.put(LifecycleSettings.LIFECYCLE_ACTION, currentStep.getAction())
|
||||||
.put(LifecycleSettings.LIFECYCLE_STEP, currentStep.getName()));
|
.put(LifecycleSettings.LIFECYCLE_STEP, currentStep.getName()));
|
||||||
Index index = clusterState.metaData().index(indexName).getIndex();
|
Index index = clusterState.metaData().index(indexName).getIndex();
|
||||||
|
|
||||||
ClusterState newClusterState = IndexLifecycleRunner.moveClusterStateToErrorStep(index, clusterState, currentStep, cause, () -> now);
|
ClusterState newClusterState = IndexLifecycleRunner.moveClusterStateToErrorStep(index, clusterState, currentStep, cause, () -> now);
|
||||||
assertClusterStateOnErrorStep(clusterState, index, currentStep, newClusterState, cause, now);
|
assertClusterStateOnErrorStep(clusterState, index, currentStep, newClusterState, now,
|
||||||
|
"{\"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\"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMoveClusterStateToFailedStep() {
|
public void testMoveClusterStateToFailedStep() {
|
||||||
|
@ -966,13 +973,8 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
||||||
assertEquals("", LifecycleSettings.LIFECYCLE_STEP_INFO_SETTING.get(newIndexSettings));
|
assertEquals("", LifecycleSettings.LIFECYCLE_STEP_INFO_SETTING.get(newIndexSettings));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertClusterStateOnErrorStep(ClusterState oldClusterState, Index index, StepKey currentStep, ClusterState newClusterState,
|
private void assertClusterStateOnErrorStep(ClusterState oldClusterState, Index index, StepKey currentStep,
|
||||||
Exception cause, long now) throws IOException {
|
ClusterState newClusterState, long now, String expectedCauseValue) throws IOException {
|
||||||
XContentBuilder causeXContentBuilder = JsonXContent.contentBuilder();
|
|
||||||
causeXContentBuilder.startObject();
|
|
||||||
ElasticsearchException.generateFailureXContent(causeXContentBuilder, ToXContent.EMPTY_PARAMS, cause, false);
|
|
||||||
causeXContentBuilder.endObject();
|
|
||||||
String expectedCauseValue = BytesReference.bytes(causeXContentBuilder).utf8ToString();
|
|
||||||
assertNotSame(oldClusterState, newClusterState);
|
assertNotSame(oldClusterState, newClusterState);
|
||||||
MetaData newMetadata = newClusterState.metaData();
|
MetaData newMetadata = newClusterState.metaData();
|
||||||
assertNotSame(oldClusterState.metaData(), newMetadata);
|
assertNotSame(oldClusterState.metaData(), newMetadata);
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class MoveToErrorStepUpdateTaskTests extends ESTestCase {
|
||||||
|
|
||||||
XContentBuilder causeXContentBuilder = JsonXContent.contentBuilder();
|
XContentBuilder causeXContentBuilder = JsonXContent.contentBuilder();
|
||||||
causeXContentBuilder.startObject();
|
causeXContentBuilder.startObject();
|
||||||
ElasticsearchException.generateFailureXContent(causeXContentBuilder, ToXContent.EMPTY_PARAMS, cause, false);
|
ElasticsearchException.generateThrowableXContent(causeXContentBuilder, ToXContent.EMPTY_PARAMS, cause);
|
||||||
causeXContentBuilder.endObject();
|
causeXContentBuilder.endObject();
|
||||||
String expectedCauseValue = BytesReference.bytes(causeXContentBuilder).utf8ToString();
|
String expectedCauseValue = BytesReference.bytes(causeXContentBuilder).utf8ToString();
|
||||||
assertThat(LifecycleSettings.LIFECYCLE_STEP_INFO_SETTING.get(newState.metaData().index(index).getSettings()),
|
assertThat(LifecycleSettings.LIFECYCLE_STEP_INFO_SETTING.get(newState.metaData().index(index).getSettings()),
|
||||||
|
|
Loading…
Reference in New Issue