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

Commit

Permalink
feat: add retry logging (#1160)
Browse files Browse the repository at this point in the history
* feat: add retry logging

* formatting

* change level to FINEST

* update based on comments

* nit
  • Loading branch information
stephaniewang526 committed Jul 31, 2020
1 parent b7646a3 commit 1575715
Showing 1 changed file with 18 additions and 0 deletions.
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(
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

0 comments on commit 1575715

Please sign in to comment.