Skip to content

Commit 98c9a70

Browse files
authored
[TestFix] ExplainLifecycleIT testStepInfoPreservedOnAutoRetry failing (#114294)
* 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
1 parent 4676341 commit 98c9a70

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.HashMap;
3535
import java.util.Locale;
3636
import java.util.Map;
37+
import java.util.concurrent.TimeUnit;
3738

3839
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
3940
import static org.elasticsearch.xpack.TimeSeriesRestDriver.createFullPolicy;
@@ -307,14 +308,16 @@ public void testStepInfoPreservedOnAutoRetry() throws Exception {
307308

308309
assertBusy(() -> {
309310
Map<String, Object> explainIndex = explainIndex(client(), indexName);
310-
assertThat(explainIndex.get("failed_step_retry_count"), notNullValue());
311-
assertThat(explainIndex.get("previous_step_info"), notNullValue());
312-
assertThat((int) explainIndex.get("failed_step_retry_count"), greaterThan(0));
311+
var assertionMessage = "Assertion failed for the following response: " + explainIndex;
312+
assertThat(assertionMessage, explainIndex.get("failed_step_retry_count"), notNullValue());
313+
assertThat(assertionMessage, explainIndex.get("previous_step_info"), notNullValue());
314+
assertThat(assertionMessage, (int) explainIndex.get("failed_step_retry_count"), greaterThan(0));
313315
assertThat(
316+
assertionMessage,
314317
explainIndex.get("previous_step_info").toString(),
315318
containsString("rollover_alias [" + aliasName + "] does not point to index [" + indexName + "]")
316319
);
317-
});
320+
}, 30, TimeUnit.SECONDS);
318321
}
319322

320323
private void assertUnmanagedIndex(Map<String, Object> explainIndexMap) {

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ static ClusterState moveClusterStateToStep(
137137
lifecycleState,
138138
newStepKey,
139139
nowSupplier,
140-
forcePhaseDefinitionRefresh
140+
forcePhaseDefinitionRefresh,
141+
true
141142
);
142143

143144
return LifecycleExecutionStateUtils.newClusterStateWithLifecycleState(state, idxMeta.getIndex(), newLifecycleState);
@@ -175,6 +176,7 @@ static ClusterState moveClusterStateToErrorStep(
175176
currentState,
176177
new Step.StepKey(currentStep.phase(), currentStep.action(), ErrorStep.NAME),
177178
nowSupplier,
179+
false,
178180
false
179181
);
180182

@@ -243,7 +245,8 @@ static ClusterState moveClusterStateToPreviouslyFailedStep(
243245
lifecycleState,
244246
nextStepKey,
245247
nowSupplier,
246-
forcePhaseDefinitionRefresh
248+
forcePhaseDefinitionRefresh,
249+
false
247250
);
248251

249252
LifecycleExecutionState.Builder retryStepState = LifecycleExecutionState.builder(nextStepState);
@@ -277,7 +280,8 @@ private static LifecycleExecutionState updateExecutionStateToStep(
277280
LifecycleExecutionState existingState,
278281
Step.StepKey newStep,
279282
LongSupplier nowSupplier,
280-
boolean forcePhaseDefinitionRefresh
283+
boolean forcePhaseDefinitionRefresh,
284+
boolean allowNullPreviousStepInfo
281285
) {
282286
Step.StepKey currentStep = Step.getCurrentStepKey(existingState);
283287
long nowAsMillis = nowSupplier.getAsLong();
@@ -289,7 +293,9 @@ private static LifecycleExecutionState updateExecutionStateToStep(
289293

290294
// clear any step info or error-related settings from the current step
291295
updatedState.setFailedStep(null);
292-
updatedState.setPreviousStepInfo(existingState.stepInfo());
296+
if (allowNullPreviousStepInfo || existingState.stepInfo() != null) {
297+
updatedState.setPreviousStepInfo(existingState.stepInfo());
298+
}
293299
updatedState.setStepInfo(null);
294300
updatedState.setIsAutoRetryableError(null);
295301
updatedState.setFailedStepRetryCount(null);
@@ -390,7 +396,7 @@ public static LifecycleExecutionState moveStateToNextActionAndUpdateCachedPhase(
390396
updatedState.setStep(nextStep.name());
391397
updatedState.setStepTime(nowAsMillis);
392398
updatedState.setFailedStep(null);
393-
updatedState.setPreviousStepInfo(existingState.stepInfo());
399+
updatedState.setPreviousStepInfo(null);
394400
updatedState.setStepInfo(null);
395401
updatedState.setIsAutoRetryableError(null);
396402
updatedState.setFailedStepRetryCount(null);

0 commit comments

Comments
 (0)