Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit default backoff retries and change backoff factor to double #49

Merged
merged 4 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -31,7 +31,7 @@ private MockInsightsConfiguration(
Duration connectPeriod,
Duration updatePeriod,
long httpClientRetryInitialDelay,
long httpClientRetryBackoffFactor,
double httpClientRetryBackoffFactor,
int httpClientRetryMaxAttemps) {
this.identificationName = identificationName;
this.certFilePath = certFilePath;
Expand All @@ -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,
Expand Down Expand Up @@ -93,7 +93,7 @@ public static InsightsConfiguration of(
Duration connectPeriod,
Duration updatePeriod,
long httpClientRetryInitialDelay,
long httpClientRetryBackoffFactor,
double httpClientRetryBackoffFactor,
int httpClientRetryMaxAttempts) {
return new MockInsightsConfiguration(
name,
Expand Down Expand Up @@ -161,7 +161,7 @@ public long getHttpClientRetryInitialDelay() {
}

@Override
public long getHttpClientRetryBackoffFactor() {
public double getHttpClientRetryBackoffFactor() {
return httpClientRetryBackoffFactor;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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(
Expand Down