浏览代码

[TestFix] ExplainLifecycleIT testStepInfoPreservedOnAutoRetry failing (#114294) (#114802)

* Extend timeout of test and add logging on fail

* Unmute unstable test

* Switch to using logger for output

Keeps the forbiddenApis check happy

* Switch to using assertion messages to display

To display debug info

* Adjust logic of previous step info preservation

Add additional checks to ensure previous step info can't be cleared
when auto retrying, only updated with new info.

Also added logic to ensure previous step info is cleared when
transitioning to a new action

* Undo accidentally added lines from merge
Luke Whiting 1 年之前
父节点
当前提交
22deacb412

+ 7 - 4
x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/ExplainLifecycleIT.java

@@ -34,6 +34,7 @@ import java.util.Formatter;
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
 import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
 import static org.elasticsearch.xpack.TimeSeriesRestDriver.createFullPolicy;
@@ -307,14 +308,16 @@ public class ExplainLifecycleIT extends ESRestTestCase {
 
         assertBusy(() -> {
             Map<String, Object> explainIndex = explainIndex(client(), indexName);
-            assertThat(explainIndex.get("failed_step_retry_count"), notNullValue());
-            assertThat(explainIndex.get("previous_step_info"), notNullValue());
-            assertThat((int) explainIndex.get("failed_step_retry_count"), greaterThan(0));
+            var assertionMessage = "Assertion failed for the following response: " + explainIndex;
+            assertThat(assertionMessage, explainIndex.get("failed_step_retry_count"), notNullValue());
+            assertThat(assertionMessage, explainIndex.get("previous_step_info"), notNullValue());
+            assertThat(assertionMessage, (int) explainIndex.get("failed_step_retry_count"), greaterThan(0));
             assertThat(
+                assertionMessage,
                 explainIndex.get("previous_step_info").toString(),
                 containsString("rollover_alias [" + aliasName + "] does not point to index [" + indexName + "]")
             );
-        });
+        }, 30, TimeUnit.SECONDS);
     }
 
     private void assertUnmanagedIndex(Map<String, Object> explainIndexMap) {

+ 11 - 5
x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleTransition.java

@@ -137,7 +137,8 @@ public final class IndexLifecycleTransition {
             lifecycleState,
             newStepKey,
             nowSupplier,
-            forcePhaseDefinitionRefresh
+            forcePhaseDefinitionRefresh,
+            true
         );
 
         return LifecycleExecutionStateUtils.newClusterStateWithLifecycleState(state, idxMeta.getIndex(), newLifecycleState);
@@ -175,6 +176,7 @@ public final class IndexLifecycleTransition {
             currentState,
             new Step.StepKey(currentStep.phase(), currentStep.action(), ErrorStep.NAME),
             nowSupplier,
+            false,
             false
         );
 
@@ -243,7 +245,8 @@ public final class IndexLifecycleTransition {
                 lifecycleState,
                 nextStepKey,
                 nowSupplier,
-                forcePhaseDefinitionRefresh
+                forcePhaseDefinitionRefresh,
+                false
             );
 
             LifecycleExecutionState.Builder retryStepState = LifecycleExecutionState.builder(nextStepState);
@@ -277,7 +280,8 @@ public final class IndexLifecycleTransition {
         LifecycleExecutionState existingState,
         Step.StepKey newStep,
         LongSupplier nowSupplier,
-        boolean forcePhaseDefinitionRefresh
+        boolean forcePhaseDefinitionRefresh,
+        boolean allowNullPreviousStepInfo
     ) {
         Step.StepKey currentStep = Step.getCurrentStepKey(existingState);
         long nowAsMillis = nowSupplier.getAsLong();
@@ -289,7 +293,9 @@ public final class IndexLifecycleTransition {
 
         // clear any step info or error-related settings from the current step
         updatedState.setFailedStep(null);
-        updatedState.setPreviousStepInfo(existingState.stepInfo());
+        if (allowNullPreviousStepInfo || existingState.stepInfo() != null) {
+            updatedState.setPreviousStepInfo(existingState.stepInfo());
+        }
         updatedState.setStepInfo(null);
         updatedState.setIsAutoRetryableError(null);
         updatedState.setFailedStepRetryCount(null);
@@ -390,7 +396,7 @@ public final class IndexLifecycleTransition {
         updatedState.setStep(nextStep.name());
         updatedState.setStepTime(nowAsMillis);
         updatedState.setFailedStep(null);
-        updatedState.setPreviousStepInfo(existingState.stepInfo());
+        updatedState.setPreviousStepInfo(null);
         updatedState.setStepInfo(null);
         updatedState.setIsAutoRetryableError(null);
         updatedState.setFailedStepRetryCount(null);