Skip to content
Permalink
Browse files
feat: add retry logging (#1160)
* 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 15757151d4965276bd01e6772c10288959bb17ec
Showing with 18 additions and 0 deletions.
  1. +18 −0 gax/src/main/java/com/google/api/gax/retrying/BasicRetryingFuture.java
@@ -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.
@@ -65,6 +67,8 @@
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,
@@ -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);

0 comments on commit 1575715

Please sign in to comment.