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

Conversation

@igorbernstein2
Copy link
Contributor

@igorbernstein2 igorbernstein2 commented Oct 5, 2018

This partially addresses #561.
Currently the concepts of an RPC timeout and a deadline are a bit mixed up. When a user calls ApiContext.setTimeout(Duration) their duration gets converted into an an absolute deadline. Which is then interpreted as a relative timeout by the retry logic. This results in the issues described in #561.

This PR tries to fix the situation by consistently treating ApiContext.setTimeout(Duration) as a relative RPC timeout. This timeout will be converted into a deadline right before it goes out to gRPC. The only remaining bug from #561 that this doesn't address is when the user sets an absolute deadline on grpc CallOptions and then wraps an ApiContext around it. That will be addressed in a future PR that will introduce absolute deadlines in addition to the relative timeouts introduced here.

This partially addresses googleapis#561.
Currently the concepts of an RPC timeout and a deadline are a bit mixed up. When a user calls `ApiContext.setTimeout(Duration)` their duration gets converted into an an absolute deadline. Which is then interpreted as a relative timeout by the retry logic. This results in the issues described in googleapis#561.

This PR tries to fix the situation by consistently treating `ApiContext.setTimeout(Duration)` as a relative RPC timeout. This timeout will be converted into a deadline right before it goes out to gRPC. The only remaining bug from googleapis#561 that this doesn't address is when the user sets an absolute deadline on grpc CallOptions and then wraps an ApiContext around it. That will be addressed in a future PR that will introduce absolute deadlines in addition to the relative timeouts introduced here.
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Oct 5, 2018
@igorbernstein2
Copy link
Contributor Author

@vam-google @garrettjonesgoogle Please take look when you have a moment

@codecov-io
Copy link

codecov-io commented Oct 5, 2018

Codecov Report

Merging #592 into master will increase coverage by 1.05%.
The diff coverage is 92.85%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #592      +/-   ##
============================================
+ Coverage     73.96%   75.01%   +1.05%     
- Complexity      906      933      +27     
============================================
  Files           176      176              
  Lines          4067     4074       +7     
  Branches        317      322       +5     
============================================
+ Hits           3008     3056      +48     
+ Misses          907      865      -42     
- Partials        152      153       +1
Impacted Files Coverage Δ Complexity Δ
...ava/com/google/api/gax/retrying/RetrySettings.java 31.25% <ø> (ø) 2 <0> (ø) ⬇️
.../java/com/google/api/gax/grpc/GrpcClientCalls.java 95.23% <100%> (+1.9%) 7 <0> (+3) ⬆️
...n/java/com/google/api/gax/rpc/AttemptCallable.java 73.68% <100%> (+1.46%) 3 <1> (ø) ⬇️
...oogle/api/gax/httpjson/HttpJsonDirectCallable.java 88.23% <83.33%> (+88.23%) 4 <0> (+4) ⬆️
.../java/com/google/api/gax/grpc/GrpcCallContext.java 84.07% <92.3%> (+2.01%) 42 <8> (+4) ⬆️
...m/google/api/gax/httpjson/HttpJsonCallContext.java 71.01% <93.33%> (+43.74%) 24 <12> (+16) ⬆️
...va/com/google/api/gax/retrying/RetryAlgorithm.java 85.71% <0%> (-7.15%) 7% <0%> (-1%)
...api/gax/grpc/InstantiatingGrpcChannelProvider.java 65.38% <0%> (-3.08%) 26% <0%> (ø)
...om/google/api/gax/httpjson/HttpJsonStatusCode.java 28.2% <0%> (-2.57%) 7% <0%> (-1%)
...oogle/api/gax/httpjson/ManagedHttpJsonChannel.java 2% <0%> (+2%) 1% <0%> (+1%) ⬆️
... and 5 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 25a19db...7ad7f59. Read the comment docs.

.setMaxRpcTimeout(Duration.ofHours(1))
.build())
.setIdleTimeout(Duration.ofSeconds(1))
.setTimeoutCheckInterval(Duration.ofSeconds(1))

This comment was marked as spam.

@igorbernstein2
Copy link
Contributor Author

Added a pile of tests. This PR is complete. Please review and if it looks good, please merge


@Nullable
@Override
public Duration getTimeout() {

This comment was marked as spam.

This comment was marked as spam.

CallOptions newOptions =
oldOptions.withDeadlineAfter(rpcTimeout.toMillis(), TimeUnit.MILLISECONDS);
GrpcCallContext nextContext = withCallOptions(newOptions);
public GrpcCallContext withTimeout(@Nullable Duration rpcTimeout) {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

Preconditions.checkNotNull(callOptions);

// Try to convert the timeout into a deadline and use it if it occurs before the actual deadline
if (grpcContext.getTimeout() != null) {

This comment was marked as spam.

This comment was marked as spam.

private GrpcCallContext(
Channel channel,
CallOptions callOptions,
@Nullable Duration rpcTimeout,

This comment was marked as spam.

This comment was marked as spam.

@igorbernstein2
Copy link
Contributor Author

@vam-google I've renamed references to rpcTimeout to timeout. 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 with few comments. Please address them before pushing (no need to ask for another LGTM)

@InternalExtensionOnly
public final class HttpJsonCallContext implements ApiCallContext {
private final HttpJsonChannel channel;
private final Duration rpcTimeout;

This comment was marked as spam.

This comment was marked as spam.

*
* <p>This timeout only applies to a single RPC call; if timeouts are configured, the overall time
* taken will be much higher.
* <p>This sets the maximum amount of time a single unary RPC attempt can take. If retries are

This comment was marked as spam.

This comment was marked as spam.

@igorbernstein2 igorbernstein2 merged commit ed11321 into googleapis:master Oct 9, 2018
@igorbernstein2 igorbernstein2 deleted the opencensus-1-retry-context branch October 9, 2018 20:31
igorbernstein2 added a commit to igorbernstein2/gax-java that referenced this pull request Oct 9, 2018
igorbernstein2 added a commit that referenced this pull request Oct 10, 2018
Raibaz pushed a commit to Raibaz/gax-java that referenced this pull request Oct 25, 2018
…#592)

This partially addresses googleapis#561.
Currently the concepts of an RPC timeout and a deadline are a bit mixed up. When a user calls `ApiContext.setTimeout(Duration)` their duration gets converted into an an absolute deadline. Which is then interpreted as a relative timeout by the retry logic. This results in the issues described in googleapis#561.

This PR tries to fix the situation by consistently treating `ApiContext.setTimeout(Duration)` as a relative RPC timeout. This timeout will be converted into a deadline right before it goes out to gRPC. The only remaining bug from googleapis#561 that this doesn't address is when the user sets an absolute deadline on grpc CallOptions and then wraps an ApiContext around it. That will be addressed in a future PR that will introduce absolute deadlines in addition to the relative timeouts introduced here.
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
…#592)

This partially addresses googleapis#561.
Currently the concepts of an RPC timeout and a deadline are a bit mixed up. When a user calls `ApiContext.setTimeout(Duration)` their duration gets converted into an an absolute deadline. Which is then interpreted as a relative timeout by the retry logic. This results in the issues described in googleapis#561.

This PR tries to fix the situation by consistently treating `ApiContext.setTimeout(Duration)` as a relative RPC timeout. This timeout will be converted into a deadline right before it goes out to gRPC. The only remaining bug from googleapis#561 that this doesn't address is when the user sets an absolute deadline on grpc CallOptions and then wraps an ApiContext around it. That will be addressed in a future PR that will introduce absolute deadlines in addition to the relative timeouts introduced here.
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.

4 participants