Skip to content

Commit

Permalink
feat: add tolerance configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
NiccoMlt committed Nov 13, 2024
1 parent bbdb299 commit f2d5f4a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> domainsCheckerIPAddresses;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f2d5f4a

Please sign in to comment.