From f2d5f4a9196e0b26f3fb4db9e5eb0ca169c31e7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Maltoni?= Date: Wed, 13 Nov 2024 16:30:18 +0100 Subject: [PATCH] feat: add tolerance configuration --- .../carapaceproxy/core/RuntimeServerConfiguration.java | 4 ++++ .../server/backends/BackendHealthManager.java | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/carapace-server/src/main/java/org/carapaceproxy/core/RuntimeServerConfiguration.java b/carapace-server/src/main/java/org/carapaceproxy/core/RuntimeServerConfiguration.java index 96352f8a6..751060282 100644 --- a/carapace-server/src/main/java/org/carapaceproxy/core/RuntimeServerConfiguration.java +++ b/carapace-server/src/main/java/org/carapaceproxy/core/RuntimeServerConfiguration.java @@ -120,6 +120,7 @@ public class RuntimeServerConfiguration { private int healthProbePeriod = DEFAULT_PROBE_PERIOD; private int healthConnectTimeout = 5_000; private long warmupPeriod = DEFAULT_WARMUP_PERIOD; + private boolean tolerant = false; private int dynamicCertificatesManagerPeriod = 0; private int keyPairsSize = DEFAULT_KEYPAIRS_SIZE; private Set domainsCheckerIPAddresses; @@ -238,6 +239,9 @@ public void configure(ConfigurationStore properties) throws ConfigurationNotVali warmupPeriod = properties.getLong("healthmanager.warmupperiod", DEFAULT_WARMUP_PERIOD); LOG.log(Level.INFO, "healthmanager.warmupperiod={0}", warmupPeriod); + tolerant = properties.getBoolean("healthmanager.tolerant", false); + LOG.log(Level.INFO, "healthmanager.tolerant={0}", tolerant); + healthConnectTimeout = properties.getInt("healthmanager.connecttimeout", healthConnectTimeout); LOG.log(Level.INFO, "healthmanager.connecttimeout={0}", healthConnectTimeout); if (healthConnectTimeout < 0) { diff --git a/carapace-server/src/main/java/org/carapaceproxy/server/backends/BackendHealthManager.java b/carapace-server/src/main/java/org/carapaceproxy/server/backends/BackendHealthManager.java index b8d72fd17..1cfbb5539 100644 --- a/carapace-server/src/main/java/org/carapaceproxy/server/backends/BackendHealthManager.java +++ b/carapace-server/src/main/java/org/carapaceproxy/server/backends/BackendHealthManager.java @@ -62,11 +62,13 @@ public class BackendHealthManager implements Runnable { // keep track of start() calling private volatile boolean started; private volatile long warmupPeriod; + private volatile boolean tolerant; public BackendHealthManager(final RuntimeServerConfiguration conf, final EndpointMapper mapper) { this.mapper = mapper; this.connectTimeout = conf.getHealthConnectTimeout(); this.warmupPeriod = conf.getWarmupPeriod(); + this.tolerant = conf.isTolerant(); // will be overridden before start this.period = DEFAULT_PERIOD; @@ -131,6 +133,11 @@ public synchronized void reloadConfiguration(RuntimeServerConfiguration newConfi LOG.info("Applying new warmup period of {} ms", this.warmupPeriod); } + if (this.tolerant != newConfiguration.isTolerant()) { + this.tolerant = newConfiguration.isTolerant(); + LOG.info("Applying new health tolerance configuration {}; cold backends now {} exceed safe capacity", this.tolerant, this.tolerant ? "may" : "may not"); + } + this.mapper = mapper; if (restart || started) { @@ -210,7 +217,7 @@ public boolean exceedsCapacity(final String backendId) { return false; } final BackendHealthStatus backendStatus = getBackendStatus(backendConfiguration.hostPort()); - return backendConfiguration.safeCapacity() > backendStatus.getConnections(); + return backendConfiguration.safeCapacity() > backendStatus.getConnections() && !this.tolerant; } @VisibleForTesting