Skip to content

Commit 77dea57

Browse files
committed
Handle duplicate errors (only report the first one)
1 parent a9e3593 commit 77dea57

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ static void validateAllSearchableSnapshotActionsUseSameRepository(Collection<Pha
370370
*/
371371
public static String validateMonotonicallyIncreasingPhaseTimings(Collection<Phase> phases) {
372372
List<String> errors = new ArrayList<>();
373+
Set<String> invalidPhases = new HashSet<>();
373374

374375
// Loop through all phases in order, for each phase with a min_age
375376
// configured, look at all the future phases to see if their ages are
@@ -385,6 +386,12 @@ public static String validateMonotonicallyIncreasingPhaseTimings(Collection<Phas
385386

386387
if (maybePhase.isPresent()) {
387388
Phase phase = maybePhase.get();
389+
// We only consider a phase bad once, otherwise we can duplicate
390+
// errors, so we keep track of the invalid phases we've seen and
391+
// ignore them if they come around again.
392+
if (invalidPhases.contains(phase.getName())) {
393+
continue;
394+
}
388395
TimeValue phaseMinAge = phase.getMinimumAge();
389396
Set<String> followingPhases = new HashSet<>(ORDERED_VALID_PHASES.subList(i + 1, ORDERED_VALID_PHASES.size()));
390397
Set<Phase> phasesWithBadAges = phases.stream()
@@ -393,6 +400,7 @@ public static String validateMonotonicallyIncreasingPhaseTimings(Collection<Phas
393400
.filter(p -> p.getMinimumAge().compareTo(phaseMinAge) < 0)
394401
.collect(Collectors.toSet());
395402
if (phasesWithBadAges.size() > 0) {
403+
phasesWithBadAges.forEach(p -> invalidPhases.add(p.getName()));
396404
errors.add("phases [" + phasesWithBadAges.stream().map(Phase::getName).collect(Collectors.joining(",")) +
397405
"] configure a [min_age] value less than the [min_age] of [" + phase.getMinimumAge() +
398406
"] for the [" + phaseName + "] phase, configuration: " +

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleTypeTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,21 @@ public void testValidatingIncreasingAges() {
771771
containsString("phases [frozen,delete] configure a [min_age] value less " +
772772
"than the [min_age] of [3d] for the [warm] phase, configuration: {frozen=1d, delete=2d}"));
773773
}
774+
775+
{
776+
Phase hotPhase = new Phase(HOT_PHASE, TimeValue.timeValueDays(1), Collections.emptyMap());
777+
Phase warmPhase = new Phase(WARM_PHASE, TimeValue.timeValueDays(3), Collections.emptyMap());
778+
Phase coldPhase = new Phase(COLD_PHASE, null, Collections.emptyMap());
779+
Phase frozenPhase = new Phase(FROZEN_PHASE, TimeValue.timeValueDays(2), Collections.emptyMap());
780+
Phase deletePhase = new Phase(DELETE_PHASE, TimeValue.timeValueDays(1), Collections.emptyMap());
781+
782+
String err =
783+
validateMonotonicallyIncreasingPhaseTimings(Arrays.asList(hotPhase, warmPhase, coldPhase, frozenPhase, deletePhase));
784+
785+
assertThat(err,
786+
containsString("phases [frozen,delete] configure a [min_age] value less than " +
787+
"the [min_age] of [3d] for the [warm] phase, configuration: {frozen=2d, delete=1d}"));
788+
}
774789
}
775790

776791
private void assertNextActionName(String phaseName, String currentAction, String expectedNextAction, String... availableActionNames) {

0 commit comments

Comments
 (0)