Skip to content

Commit

Permalink
fix fabric8io#4365 correcting backoff interval
Browse files Browse the repository at this point in the history
also adding stacktraces for blocking request exceptions
  • Loading branch information
shawkins committed Oct 2, 2022
1 parent 3eb233f commit 748d97a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Expand Up @@ -83,6 +83,7 @@ public class OperationSupport {
protected String apiGroupVersion;
protected boolean dryRun;
private final int requestRetryBackoffLimit;
private final int requestRetryBackoffInterval;

public OperationSupport(Client client) {
this(new OperationContext().withClient(client));
Expand All @@ -106,8 +107,10 @@ public OperationSupport(OperationContext ctx) {
}

if (ctx.getConfig() != null) {
requestRetryBackoffInterval = ctx.getConfig().getRequestRetryBackoffInterval();
this.requestRetryBackoffLimit = ctx.getConfig().getRequestRetryBackoffLimit();
} else {
requestRetryBackoffInterval = Config.DEFAULT_REQUEST_RETRY_BACKOFFINTERVAL;
this.requestRetryBackoffLimit = Config.DEFAULT_REQUEST_RETRY_BACKOFFLIMIT;
}
}
Expand Down Expand Up @@ -508,15 +511,11 @@ protected <T> T waitForResult(CompletableFuture<T> future) throws IOException {
if (e.getCause() != null) {
t = e.getCause();
}
// throw a new exception to preserve the calling stack trace
if (t instanceof IOException) {
throw (IOException) t;
throw new IOException(t.getMessage(), t);
}
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
InterruptedIOException ie = new InterruptedIOException();
ie.initCause(e);
throw ie;
throw new KubernetesClientException(t.getMessage(), t);
}
}

Expand Down Expand Up @@ -568,7 +567,7 @@ protected <T> CompletableFuture<T> handleResponse(HttpClient client, HttpRequest
HttpRequest request = requestBuilder.build();
CompletableFuture<HttpResponse<byte[]>> futureResponse = new CompletableFuture<>();
retryWithExponentialBackoff(futureResponse,
new ExponentialBackoffIntervalCalculator(requestRetryBackoffLimit, MAX_RETRY_INTERVAL_EXPONENT),
new ExponentialBackoffIntervalCalculator(requestRetryBackoffInterval, MAX_RETRY_INTERVAL_EXPONENT),
Utils.getNonNullOrElse(client, httpClient), request);

return futureResponse.thenApply(response -> {
Expand Down
Expand Up @@ -296,6 +296,7 @@ void testNoHttpRetryWithDefaultConfig() {
void testHttpRetryWithMoreFailuresThanRetries() {
final AtomicInteger httpExecutionCounter = new AtomicInteger(0);
HttpClient mockClient = newHttpClientWithSomeFailures(httpExecutionCounter, 1000);
long start = System.currentTimeMillis();
BaseOperation<Pod, PodList, Resource<Pod>> baseOp = new BaseOperation(new OperationContext()
.withClient(mockClient(mockClient,
new ConfigBuilder().withMasterUrl("https://172.17.0.2:8443").withNamespace("default")
Expand All @@ -309,7 +310,10 @@ void testHttpRetryWithMoreFailuresThanRetries() {
Pod result = baseOp.get();
});

long stop = System.currentTimeMillis();

// Then
assertTrue(stop - start >= 700); //100+200+400
assertTrue(exception.getMessage().contains("Internal Server Error"),
"As the last failure, the 3rd one, is not an IOException the message expected to contain: 'Internal Server Error'!");
assertEquals(4, httpExecutionCounter.get(), "Expected 4 calls: one normal try and 3 backoff retries!");
Expand Down

0 comments on commit 748d97a

Please sign in to comment.