Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

feat: add retry logging #1160

Merged
merged 5 commits into from Jul 31, 2020
Merged
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 @@ -41,6 +41,8 @@
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.RejectedExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* For internal use only.
Expand All @@ -65,6 +67,8 @@ class BasicRetryingFuture<ResponseT> extends AbstractFuture<ResponseT>
private volatile ApiFuture<ResponseT> latestCompletedAttemptResult;
private volatile ApiFuture<ResponseT> attemptResult;

private static final Logger LOG = Logger.getLogger(BasicRetryingFuture.class.getName());

BasicRetryingFuture(
Callable<ResponseT> callable,
RetryAlgorithm<ResponseT> retryAlgorithm,
Expand Down Expand Up @@ -166,6 +170,20 @@ void handleAttempt(Throwable throwable, ResponseT response) {
retryAlgorithm.createNextAttempt(throwable, response, attemptSettings);
boolean shouldRetry = retryAlgorithm.shouldRetry(throwable, response, nextAttemptSettings);
if (shouldRetry) {
// Log retry info
if (LOG.isLoggable(Level.FINEST)) {
LOG.log(
stephaniewang526 marked this conversation as resolved.
Show resolved Hide resolved
Level.FINEST,
"Retrying with:\n{0}\n{1}\n{2}\n{3}",
new Object[] {
"enclosingMethod: " + callable.getClass().getEnclosingMethod() != null
? callable.getClass().getEnclosingMethod().getName()
: "",
"attemptCount: " + attemptSettings.getAttemptCount(),
"delay: " + attemptSettings.getRetryDelay(),
"retriableException: " + throwable
});
}
tracer.attemptFailed(throwable, nextAttemptSettings.getRandomizedRetryDelay());
attemptSettings = nextAttemptSettings;
setAttemptResult(throwable, response, true);
Expand Down