Skip to content

Commit

Permalink
#2897: WIP Fix exponential backoff
Browse files Browse the repository at this point in the history
  • Loading branch information
ulischulte committed Nov 17, 2023
1 parent c8681eb commit 9cc7702
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public StatusUpdateTrigger statusUpdateTrigger(StatusUpdater statusUpdater, Publ
StatusUpdateTrigger trigger = new StatusUpdateTrigger(statusUpdater, events);
trigger.setInterval(this.adminServerProperties.getMonitor().getStatusInterval());
trigger.setLifetime(this.adminServerProperties.getMonitor().getStatusLifetime());
trigger.setMaxBackoff(this.adminServerProperties.getMonitor().getStatusMaxBackoff());
return trigger;
}

Expand Down Expand Up @@ -132,6 +133,7 @@ public InfoUpdateTrigger infoUpdateTrigger(InfoUpdater infoUpdater, Publisher<In
InfoUpdateTrigger trigger = new InfoUpdateTrigger(infoUpdater, events);
trigger.setInterval(this.adminServerProperties.getMonitor().getInfoInterval());
trigger.setLifetime(this.adminServerProperties.getMonitor().getInfoLifetime());
trigger.setMaxBackoff(this.adminServerProperties.getMonitor().getInfoMaxBackoff());
return trigger;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,24 @@ public static class MonitorProperties {
@DurationUnit(ChronoUnit.MILLIS)
private Duration statusLifetime = Duration.ofMillis(10_000L);

/**
* Time interval representing the maximal backoff for status check retries.
*/
@DurationUnit(ChronoUnit.MILLIS)
private Duration statusMaxBackoff = Duration.ofMillis(10_000L);

/**
* Time interval to check the info of instances,
*/
@DurationUnit(ChronoUnit.MILLIS)
private Duration infoInterval = Duration.ofMinutes(1L);

/**
* Time interval representing the maximal backoff for info check retries.
*/
@DurationUnit(ChronoUnit.MILLIS)
private Duration infoMaxBackoff = Duration.ofMinutes(1L);

/**
* Lifetime of info. The info won't be updated as long the last info isn't
* expired.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class InfoUpdateTrigger extends AbstractEventHandler<InstanceEvent> {
public InfoUpdateTrigger(InfoUpdater infoUpdater, Publisher<InstanceEvent> publisher) {
super(publisher, InstanceEvent.class);
this.infoUpdater = infoUpdater;
this.intervalCheck = new IntervalCheck("info", this::updateInfo, Duration.ofMinutes(5), Duration.ofMinutes(1));
this.intervalCheck = new IntervalCheck("info", this::updateInfo, Duration.ofMinutes(5), Duration.ofMinutes(1), Duration.ofMinutes(10));
}

@Override
Expand Down Expand Up @@ -79,4 +79,7 @@ public void setLifetime(Duration infoLifetime) {
this.intervalCheck.setMinRetention(infoLifetime);
}

public void setMaxBackoff(Duration maxBackoff) {
this.intervalCheck.setMaxBackoff(maxBackoff);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class IntervalCheck {

private final Function<InstanceId, Mono<Void>> checkFn;

@Setter
private Duration maxBackoff;

@Getter
@Setter
private Duration interval;
Expand All @@ -66,15 +69,16 @@ public class IntervalCheck {
private Scheduler scheduler;

public IntervalCheck(String name, Function<InstanceId, Mono<Void>> checkFn) {
this(name, checkFn, Duration.ofSeconds(10), Duration.ofSeconds(10));
this(name, checkFn, Duration.ofSeconds(10), Duration.ofSeconds(10), Duration.ofSeconds(60));
}

public IntervalCheck(String name, Function<InstanceId, Mono<Void>> checkFn, Duration interval,
Duration minRetention) {
Duration minRetention, Duration maxBackoff) {
this.name = name;
this.checkFn = checkFn;
this.interval = interval;
this.minRetention = minRetention;
this.maxBackoff = maxBackoff;
}

public void start() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,8 @@ public void setLifetime(Duration statusLifetime) {
this.intervalCheck.setMinRetention(statusLifetime);
}

public void setMaxBackoff(Duration maxBackoff) {
this.intervalCheck.setMaxBackoff(maxBackoff);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class IntervalCheckTest {
private final Function<InstanceId, Mono<Void>> checkFn = mock(Function.class, (i) -> Mono.empty());

private final IntervalCheck intervalCheck = new IntervalCheck("test", this.checkFn, Duration.ofMillis(10),
Duration.ofMillis(10));
Duration.ofMillis(10), Duration.ofMinutes(60));

@Test
public void should_check_after_being_started() throws InterruptedException {
Expand Down

0 comments on commit 9cc7702

Please sign in to comment.