-
Notifications
You must be signed in to change notification settings - Fork 104
Add RetryingContext #590
Add RetryingContext #590
Conversation
This is the first step in implementing opencensus integration. It allows me to inject operation scoped state into the retrying logic
Codecov Report
@@ Coverage Diff @@
## master #590 +/- ##
============================================
- Coverage 75.09% 75.03% -0.07%
Complexity 935 935
============================================
Files 176 177 +1
Lines 4084 4090 +6
Branches 323 323
============================================
+ Hits 3067 3069 +2
- Misses 865 869 +4
Partials 152 152
Continue to review full report at Codecov.
|
|
@vam-google, @garrettjonesgoogle please take a look when you have some time |
| @BetaApi | ||
| @InternalExtensionOnly | ||
| @AutoValue | ||
| public abstract class RetryingContext { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| */ | ||
| class CallbackChainRetryingFuture<ResponseT> extends BasicRetryingFuture<ResponseT> { | ||
| private final RetryingExecutor<ResponseT> retryingExecutor; | ||
| private final ScheduledRetryingExecutor<ResponseT> retryingExecutor; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| @BetaApi("The surface for passing per operation state is not yet stable") | ||
| @Override | ||
| public RetryingFuture<ResponseT> createFuture( | ||
| @Nonnull Callable<ResponseT> callable, @Nonnull RetryingContext retryingContext) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * <p>It provides state to individual {@link RetryingFuture}s via the {@link RetryingExecutor}. | ||
| */ | ||
| @BetaApi | ||
| @InternalExtensionOnly |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| return newBuilder().build(); | ||
| } | ||
|
|
||
| public static RetryingContext fromCallContext(@Nullable ApiCallContext callContext) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| } | ||
|
|
||
| @BetaApi | ||
| @InternalExtensionOnly |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| /** | ||
| * A retrying executor is responsible for the following operations: | ||
| * | ||
| * <ol> |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| } | ||
|
|
||
| @Test | ||
| public void testFutureContainsRetryContext() { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| BasicRetryingFuture<String> future = | ||
| (BasicRetryingFuture<String>) executor.createFuture(noopCallable, ctx); | ||
|
|
||
| Truth.assertThat(future.getRetryingContext()).isSameAs(ctx); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
I've responded to all feedback. PTAL |
|
All feedback should be addressed. PTAL |
vam-google
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only one comment, but I believe it is essential.
| @Override | ||
| public RetryingContext getRetryContext() { | ||
| // TODO: transfer relevant state from the ApiCallContext | ||
| return RetryingContext.newBuilder().build(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
Thinking about this further, both of the attributes (tracer and overallTimeout) that are needed by
Duplicating these attributes in the RetryContext was done to avoid having the |
benchmark/build.gradle
Outdated
| @@ -1,6 +1,5 @@ | |||
| buildscript { | |||
| repositories { | |||
| jcenter() | |||
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
As discussed offline, |
vam-google
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but please consider renaming retryingContext (as parameter) to just context, since "retrying" prefix is redundant here.
|
Thanks for the review. I dropped the prefix |
This is the next iteration of #583.
This is the first step of opencensus integration. To enable tracing I need to inject state into
BasicRetryingFuture#handleAttempt, unfortunately as it standsRetryingExecutorand thusRetryingFuturesdon't have access to per-operation state. This prevents retrying logic from annotating the current operation span. This PR remedies the situation by injecting state via aRetryingContextthat is passed toRetryingExecutor#createFuture.Unfortunately
RetryingExecutorinterface is part of the public surface that has been finalized. To sidestep this issue, a new interfaceRetryingExecutorWithContextis introduced that inherits fromRetryingExecutor.RetryingExecutorWithContextis meant to be a temporary solution. Once gax drops support for java 7, the new method can be pulled up to theRetryingExecutorinterface with a a default implementation.