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

fix #4365 correcting backoff interval #4473

Merged
merged 1 commit into from Oct 7, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -60,7 +60,7 @@ private KubernetesClientException(String message, Throwable t, int code, Status
super(message, t);
this.code = code;
this.status = status;
this.requestMetadata = requestMetadata;
this.requestMetadata = requestMetadata == null ? RequestMetadata.EMPTY : requestMetadata;
}

/**
Expand Down Expand Up @@ -230,4 +230,12 @@ static RequestMetadata from(URI request) {
}
}
}

/**
* Create a new {@link KubernetesClientException} with this exception as the cause
*/
public KubernetesClientException copyAsCause() {
return new KubernetesClientException(this.getMessage(), this, this.getCode(), this.getStatus(),
this.requestMetadata);
}
}
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,14 @@ 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;
if (t instanceof KubernetesClientException) {
throw ((KubernetesClientException) t).copyAsCause();
}
InterruptedIOException ie = new InterruptedIOException();
ie.initCause(e);
throw ie;
throw new KubernetesClientException(t.getMessage(), t);
}
}

Expand Down Expand Up @@ -568,7 +570,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