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

Conversation

@igorbernstein2
Copy link
Contributor

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 stands RetryingExecutor and thus RetryingFutures don'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 a RetryingContext that is passed toRetryingExecutor#createFuture.
Unfortunately RetryingExecutor interface is part of the public surface that has been finalized. To sidestep this issue, a new interface RetryingExecutorWithContext is introduced that inherits from RetryingExecutor.
RetryingExecutorWithContext is meant to be a temporary solution. Once gax drops support for java 7, the new method can be pulled up to the RetryingExecutor interface with a a default implementation.

This is the first step in implementing opencensus integration. It allows me to inject operation scoped state into the retrying logic
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Oct 5, 2018
@codecov-io
Copy link

codecov-io commented Oct 5, 2018

Codecov Report

Merging #590 into master will decrease coverage by 0.06%.
The diff coverage is 68.75%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ Complexity Δ
.../com/google/api/gax/rpc/OperationCallableImpl.java 100% <ø> (ø) 5 <0> (ø) ⬇️
...e/api/gax/rpc/RetryingServerStreamingCallable.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...m/google/api/gax/retrying/NoopRetryingContext.java 0% <0%> (ø) 0 <0> (?)
...rc/main/java/com/google/api/gax/rpc/Callables.java 68.18% <100%> (ø) 7 <0> (ø) ⬇️
.../api/gax/retrying/CallbackChainRetryingFuture.java 88.37% <100%> (ø) 6 <1> (ø) ⬇️
...ava/com/google/api/gax/rpc/RecheckingCallable.java 90.9% <100%> (+0.9%) 2 <1> (ø) ⬇️
...m/google/api/gax/retrying/BasicRetryingFuture.java 92.85% <100%> (+0.08%) 22 <0> (ø) ⬇️
.../java/com/google/api/gax/rpc/RetryingCallable.java 91.66% <100%> (ø) 2 <1> (ø) ⬇️
...oogle/api/gax/retrying/DirectRetryingExecutor.java 78.94% <50%> (-4.39%) 6 <1> (ø)
...le/api/gax/retrying/ScheduledRetryingExecutor.java 92.3% <50%> (-7.7%) 3 <1> (ø)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7b19a10...af756a2. Read the comment docs.

@igorbernstein2
Copy link
Contributor Author

@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.

This comment was marked as spam.

This comment was marked as spam.

@igorbernstein2 igorbernstein2 changed the title WIP: Add RetryingContext Add RetryingContext Oct 5, 2018
*/
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.

@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.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

* <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.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

return newBuilder().build();
}

public static RetryingContext fromCallContext(@Nullable ApiCallContext callContext) {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

}

@BetaApi
@InternalExtensionOnly

This comment was marked as spam.

This comment was marked as spam.

/**
* A retrying executor is responsible for the following operations:
*
* <ol>

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

}

@Test
public void testFutureContainsRetryContext() {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

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.

This comment was marked as spam.

@igorbernstein2
Copy link
Contributor Author

I've responded to all feedback. PTAL

@googleapis googleapis deleted a comment from igorbernstein2 Oct 9, 2018
@igorbernstein2
Copy link
Contributor Author

All feedback should be addressed. PTAL

Copy link
Contributor

@vam-google vam-google left a 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.

This comment was marked as spam.

@igorbernstein
Copy link

igorbernstein commented Oct 11, 2018

Thinking about this further, both of the attributes (tracer and overallTimeout) that are needed by RetryContext belong on the ApiCallContext itself:

  • the tracer will need to be accessible to other parts of the codebase to annotate connections, annotate stream progress, start actual operation spans, etc
  • the overallTimeout is not only about retries and will take effect on non-retryable rpcs (it will be the minimum of the rpc timeout and the overall timeout). This allows the caller to state their intention at the callsite ("I have to respond to the ad auction within 10 ms, so I need to make sure the bigtable rpc doesn't take longer than 5 ms") without digging into the client implementation to see if retries are enabled for that rpc.

Duplicating these attributes in the RetryContext was done to avoid having the retrying package import classes from the rpc package.

@@ -1,6 +1,5 @@
buildscript {
repositories {
jcenter()

This comment was marked as spam.

@igorbernstein2
Copy link
Contributor Author

As discussed offline, RetryingContext is now an interface that ApiCallContext extends. PTAL

Copy link
Contributor

@vam-google vam-google left a 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.

@igorbernstein2
Copy link
Contributor Author

Thanks for the review. I dropped the prefix

@igorbernstein2 igorbernstein2 merged commit 90957ff into googleapis:master Oct 15, 2018
@igorbernstein2 igorbernstein2 deleted the opencensus-0-retrycontext branch October 15, 2018 18:52
Raibaz pushed a commit to Raibaz/gax-java that referenced this pull request Oct 25, 2018
Raibaz pushed a commit to Raibaz/gax-java that referenced this pull request Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants