Skip to content

Commit

Permalink
[TestFix] ExplainLifecycleIT testStepInfoPreservedOnAutoRetry failing (
Browse files Browse the repository at this point in the history
…elastic#114294) (elastic#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
  • Loading branch information
lukewhiting authored Oct 15, 2024
1 parent db9a125 commit 22deacb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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;
Expand Down Expand Up @@ -307,14 +308,16 @@ public void testStepInfoPreservedOnAutoRetry() throws Exception {

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ static ClusterState moveClusterStateToStep(
lifecycleState,
newStepKey,
nowSupplier,
forcePhaseDefinitionRefresh
forcePhaseDefinitionRefresh,
true
);

return LifecycleExecutionStateUtils.newClusterStateWithLifecycleState(state, idxMeta.getIndex(), newLifecycleState);
Expand Down Expand Up @@ -175,6 +176,7 @@ static ClusterState moveClusterStateToErrorStep(
currentState,
new Step.StepKey(currentStep.phase(), currentStep.action(), ErrorStep.NAME),
nowSupplier,
false,
false
);

Expand Down Expand Up @@ -243,7 +245,8 @@ static ClusterState moveClusterStateToPreviouslyFailedStep(
lifecycleState,
nextStepKey,
nowSupplier,
forcePhaseDefinitionRefresh
forcePhaseDefinitionRefresh,
false
);

LifecycleExecutionState.Builder retryStepState = LifecycleExecutionState.builder(nextStepState);
Expand Down Expand Up @@ -277,7 +280,8 @@ private static LifecycleExecutionState updateExecutionStateToStep(
LifecycleExecutionState existingState,
Step.StepKey newStep,
LongSupplier nowSupplier,
boolean forcePhaseDefinitionRefresh
boolean forcePhaseDefinitionRefresh,
boolean allowNullPreviousStepInfo
) {
Step.StepKey currentStep = Step.getCurrentStepKey(existingState);
long nowAsMillis = nowSupplier.getAsLong();
Expand All @@ -289,7 +293,9 @@ private static LifecycleExecutionState updateExecutionStateToStep(

// 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);
Expand Down Expand Up @@ -390,7 +396,7 @@ public static LifecycleExecutionState moveStateToNextActionAndUpdateCachedPhase(
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);
Expand Down

0 comments on commit 22deacb

Please sign in to comment.