diff --git a/README.md b/README.md index 7a0e0c3..ddc2cd3 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ The following environment variables are available to be overriden when using `En | `RHT_INSIGHTS_JAVA_CONNECT_PERIOD` | 1 day (`P1D`) | Connect period, see `java.time.Duration::parse` for the syntax | | `RHT_INSIGHTS_JAVA_UPDATE_PERIOD` | 5 minutes (`PT5M`) | Update period, see `java.time.Duration::parse` for the syntax | | `RHT_INSIGHTS_JAVA_HTTP_CLIENT_RETRY_INITIAL_DELAY` | 2000 (milliseconds as `long`) | HTTP client exponential backoff: initial retry delay in milliseconds | -| `RHT_INSIGHTS_JAVA_HTTP_CLIENT_RETRY_BACKOFF_FACTOR` | 2 (`long`) | HTTP client exponential backoff: factor | +| `RHT_INSIGHTS_JAVA_HTTP_CLIENT_RETRY_BACKOFF_FACTOR` | 2.0 (`double`) | HTTP client exponential backoff: factor | | `RHT_INSIGHTS_JAVA_HTTP_CLIENT_RETRY_MAX_ATTEMPTS` | 10 (`int`) | HTTP client exponential backoff: maximum number of retry attempts | | `RHT_INSIGHTS_JAVA_ARCHIVE_UPLOAD_DIR` | `/var/tmp/insights-runtimes/uploads` | Filesystem location to place archives if HTTP upload fails | diff --git a/api/src/main/java/com/redhat/insights/config/EnvAndSysPropsInsightsConfiguration.java b/api/src/main/java/com/redhat/insights/config/EnvAndSysPropsInsightsConfiguration.java index 1dfacc1..cf31112 100644 --- a/api/src/main/java/com/redhat/insights/config/EnvAndSysPropsInsightsConfiguration.java +++ b/api/src/main/java/com/redhat/insights/config/EnvAndSysPropsInsightsConfiguration.java @@ -157,10 +157,10 @@ public long getHttpClientRetryInitialDelay() { } @Override - public long getHttpClientRetryBackoffFactor() { + public double getHttpClientRetryBackoffFactor() { String value = lookup(ENV_HTTP_CLIENT_RETRY_BACKOFF_FACTOR); if (value != null) { - return Long.parseLong(value); + return Double.parseDouble(value); } return super.getHttpClientRetryBackoffFactor(); } diff --git a/api/src/main/java/com/redhat/insights/config/InsightsConfiguration.java b/api/src/main/java/com/redhat/insights/config/InsightsConfiguration.java index f01b286..1458483 100644 --- a/api/src/main/java/com/redhat/insights/config/InsightsConfiguration.java +++ b/api/src/main/java/com/redhat/insights/config/InsightsConfiguration.java @@ -21,8 +21,8 @@ public interface InsightsConfiguration { String DEFAULT_CERT_HELPER_BINARY = "/opt/jboss-cert-helper"; long DEFAULT_HTTP_CLIENT_RETRY_INITIAL_DELAY = 2000L; - long DEFAULT_HTTP_CLIENT_RETRY_BACKOFF_FACTOR = 2L; - int DEFAULT_HTTP_CLIENT_RETRY_MAX_ATTEMPTS = 10; + double DEFAULT_HTTP_CLIENT_RETRY_BACKOFF_FACTOR = 2.0; + int DEFAULT_HTTP_CLIENT_RETRY_MAX_ATTEMPTS = 5; /** * The insights client identification name, to be adjusted to allow each runtime to define what an @@ -80,7 +80,7 @@ default long getHttpClientRetryInitialDelay() { return DEFAULT_HTTP_CLIENT_RETRY_INITIAL_DELAY; } - default long getHttpClientRetryBackoffFactor() { + default double getHttpClientRetryBackoffFactor() { return DEFAULT_HTTP_CLIENT_RETRY_BACKOFF_FACTOR; } diff --git a/api/src/test/java/com/redhat/insights/doubles/MockInsightsConfiguration.java b/api/src/test/java/com/redhat/insights/doubles/MockInsightsConfiguration.java index a4b7c5a..81c0cf9 100644 --- a/api/src/test/java/com/redhat/insights/doubles/MockInsightsConfiguration.java +++ b/api/src/test/java/com/redhat/insights/doubles/MockInsightsConfiguration.java @@ -17,7 +17,7 @@ public final class MockInsightsConfiguration extends DefaultInsightsConfiguratio private final Duration connectPeriod; private final Duration updatePeriod; private final long httpClientRetryInitialDelay; - private final long httpClientRetryBackoffFactor; + private final double httpClientRetryBackoffFactor; private final int httpClientRetryMaxAttemps; private MockInsightsConfiguration( @@ -31,7 +31,7 @@ private MockInsightsConfiguration( Duration connectPeriod, Duration updatePeriod, long httpClientRetryInitialDelay, - long httpClientRetryBackoffFactor, + double httpClientRetryBackoffFactor, int httpClientRetryMaxAttemps) { this.identificationName = identificationName; this.certFilePath = certFilePath; @@ -58,7 +58,7 @@ public static InsightsConfiguration of(String name, boolean optedOut) { public static InsightsConfiguration ofRetries( String name, long httpClientRetryInitialDelay, - long httpClientRetryBackoffFactor, + double httpClientRetryBackoffFactor, int httpClientRetryMaxAttempts) { return of( name, @@ -93,7 +93,7 @@ public static InsightsConfiguration of( Duration connectPeriod, Duration updatePeriod, long httpClientRetryInitialDelay, - long httpClientRetryBackoffFactor, + double httpClientRetryBackoffFactor, int httpClientRetryMaxAttempts) { return new MockInsightsConfiguration( name, @@ -161,7 +161,7 @@ public long getHttpClientRetryInitialDelay() { } @Override - public long getHttpClientRetryBackoffFactor() { + public double getHttpClientRetryBackoffFactor() { return httpClientRetryBackoffFactor; } diff --git a/runtime/src/main/java/com/redhat/insights/core/httpclient/BackoffWrapper.java b/runtime/src/main/java/com/redhat/insights/core/httpclient/BackoffWrapper.java index 630d62a..95a2bc5 100644 --- a/runtime/src/main/java/com/redhat/insights/core/httpclient/BackoffWrapper.java +++ b/runtime/src/main/java/com/redhat/insights/core/httpclient/BackoffWrapper.java @@ -23,11 +23,11 @@ public interface Action { private final InsightsLogger logger; private final long initialDelay; - private final long factor; + private final double factor; private final int max; private final Action action; - BackoffWrapper(InsightsLogger logger, long initialDelay, long factor, int max, Action action) { + BackoffWrapper(InsightsLogger logger, long initialDelay, double factor, int max, Action action) { this.logger = logger; this.initialDelay = initialDelay; this.factor = factor; @@ -45,7 +45,7 @@ public BackoffWrapper(InsightsLogger logger, InsightsConfiguration configuration } public int run() { - long delay = initialDelay; + double delay = initialDelay; int count = 0; InsightsException retryFailure = null; while (true) { @@ -61,7 +61,7 @@ public int run() { retryFailure.addSuppressed(err); logger.debug("Backoff #" + (count + 1) + "/" + max + ", sleeping " + delay + "ms", err); try { - Thread.sleep(delay); + Thread.sleep((long) delay); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new InsightsException(