From 15757151d4965276bd01e6772c10288959bb17ec Mon Sep 17 00:00:00 2001 From: Stephanie Wang Date: Fri, 31 Jul 2020 15:41:42 -0400 Subject: [PATCH] feat: add retry logging (#1160) * feat: add retry logging * formatting * change level to FINEST * update based on comments * nit --- .../api/gax/retrying/BasicRetryingFuture.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/gax/src/main/java/com/google/api/gax/retrying/BasicRetryingFuture.java b/gax/src/main/java/com/google/api/gax/retrying/BasicRetryingFuture.java index 6e89a1f30..3e85937bf 100644 --- a/gax/src/main/java/com/google/api/gax/retrying/BasicRetryingFuture.java +++ b/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 @@ class BasicRetryingFuture extends AbstractFuture private volatile ApiFuture latestCompletedAttemptResult; private volatile ApiFuture attemptResult; + private static final Logger LOG = Logger.getLogger(BasicRetryingFuture.class.getName()); + BasicRetryingFuture( Callable callable, RetryAlgorithm 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);