From 9cc7702b81d0b5436c343a2acda7147b37c7425f Mon Sep 17 00:00:00 2001 From: ulrichschulte Date: Fri, 17 Nov 2023 08:44:24 +0100 Subject: [PATCH] #2897: WIP Fix exponential backoff --- .../server/config/AdminServerAutoConfiguration.java | 2 ++ .../admin/server/config/AdminServerProperties.java | 12 ++++++++++++ .../admin/server/services/InfoUpdateTrigger.java | 5 ++++- .../boot/admin/server/services/IntervalCheck.java | 8 ++++++-- .../admin/server/services/StatusUpdateTrigger.java | 4 ++++ .../admin/server/services/IntervalCheckTest.java | 2 +- 6 files changed, 29 insertions(+), 4 deletions(-) diff --git a/spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/config/AdminServerAutoConfiguration.java b/spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/config/AdminServerAutoConfiguration.java index 849832ab315..34e24d95866 100644 --- a/spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/config/AdminServerAutoConfiguration.java +++ b/spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/config/AdminServerAutoConfiguration.java @@ -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; } @@ -132,6 +133,7 @@ public InfoUpdateTrigger infoUpdateTrigger(InfoUpdater infoUpdater, Publisher { public InfoUpdateTrigger(InfoUpdater infoUpdater, Publisher 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 @@ -79,4 +79,7 @@ public void setLifetime(Duration infoLifetime) { this.intervalCheck.setMinRetention(infoLifetime); } + public void setMaxBackoff(Duration maxBackoff) { + this.intervalCheck.setMaxBackoff(maxBackoff); + } } diff --git a/spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/services/IntervalCheck.java b/spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/services/IntervalCheck.java index 22bb803b52f..2343c0eac88 100644 --- a/spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/services/IntervalCheck.java +++ b/spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/services/IntervalCheck.java @@ -52,6 +52,9 @@ public class IntervalCheck { private final Function> checkFn; + @Setter + private Duration maxBackoff; + @Getter @Setter private Duration interval; @@ -66,15 +69,16 @@ public class IntervalCheck { private Scheduler scheduler; public IntervalCheck(String name, Function> 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> 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() { diff --git a/spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/services/StatusUpdateTrigger.java b/spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/services/StatusUpdateTrigger.java index 9d66bfeb0e2..446886c257d 100644 --- a/spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/services/StatusUpdateTrigger.java +++ b/spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/services/StatusUpdateTrigger.java @@ -81,4 +81,8 @@ public void setLifetime(Duration statusLifetime) { this.intervalCheck.setMinRetention(statusLifetime); } + public void setMaxBackoff(Duration maxBackoff) { + this.intervalCheck.setMaxBackoff(maxBackoff); + } + } diff --git a/spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/server/services/IntervalCheckTest.java b/spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/server/services/IntervalCheckTest.java index 4830c5aa9e0..810ff8a8528 100644 --- a/spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/server/services/IntervalCheckTest.java +++ b/spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/server/services/IntervalCheckTest.java @@ -41,7 +41,7 @@ public class IntervalCheckTest { private final Function> 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 {