-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xds: parse timeout from RDS responses #7257
Merged
voidzcy
merged 5 commits into
grpc:master
from
voidzcy:impl/parse_timeout_from_rds_response
Jul 31, 2020
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4e2acd8
Parse timeout from RDS responses.
voidzcy 138f6b4
Set timeout to infinite if maxGrpcTimeout is set to 0
voidzcy 0cfc73b
Delete comment
voidzcy 4c416aa
Add case for timeout disabled.
voidzcy 910790d
Use max value instead of null.
voidzcy File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
import com.google.protobuf.NullValue; | ||
import com.google.protobuf.Struct; | ||
import com.google.protobuf.Value; | ||
import com.google.protobuf.util.Durations; | ||
import com.google.re2j.Pattern; | ||
import com.google.re2j.PatternSyntaxException; | ||
import io.envoyproxy.envoy.type.v3.FractionalPercent; | ||
|
@@ -40,6 +41,7 @@ | |
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.concurrent.TimeUnit; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
|
@@ -1067,18 +1069,30 @@ static StructOrError<HeaderMatcher> convertEnvoyProtoHeaderMatcher( | |
|
||
/** See corresponding Envoy proto message {@link io.envoyproxy.envoy.api.v2.route.RouteAction}. */ | ||
static final class RouteAction { | ||
// Specifies the upstream timeout for the route, which spans between the point at which | ||
// the entire downstream request (i.e., end-of-stream) has been processed and when the | ||
// upstream response has been completely processed. | ||
private final long timeoutNano; | ||
// Exactly one of the following fields is non-null. | ||
@Nullable | ||
private final String cluster; | ||
@Nullable | ||
private final List<ClusterWeight> weightedClusters; | ||
|
||
@VisibleForTesting | ||
RouteAction(@Nullable String cluster, @Nullable List<ClusterWeight> weightedClusters) { | ||
RouteAction( | ||
long timeoutNano, | ||
@Nullable String cluster, | ||
@Nullable List<ClusterWeight> weightedClusters) { | ||
this.timeoutNano = timeoutNano; | ||
this.cluster = cluster; | ||
this.weightedClusters = weightedClusters; | ||
} | ||
|
||
long getTimeoutNano() { | ||
return timeoutNano; | ||
} | ||
|
||
@Nullable | ||
String getCluster() { | ||
return cluster; | ||
|
@@ -1098,18 +1112,20 @@ public boolean equals(Object o) { | |
return false; | ||
} | ||
RouteAction that = (RouteAction) o; | ||
return Objects.equals(cluster, that.cluster) | ||
return Objects.equals(timeoutNano, that.timeoutNano) | ||
&& Objects.equals(cluster, that.cluster) | ||
&& Objects.equals(weightedClusters, that.weightedClusters); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(cluster, weightedClusters); | ||
return Objects.hash(timeoutNano, cluster, weightedClusters); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
ToStringHelper toStringHelper = MoreObjects.toStringHelper(this); | ||
toStringHelper.add("timeout", timeoutNano + "ns"); | ||
if (cluster != null) { | ||
toStringHelper.add("cluster", cluster); | ||
} | ||
|
@@ -1146,7 +1162,13 @@ static StructOrError<RouteAction> fromEnvoyProtoRouteAction( | |
return StructOrError.fromError( | ||
"Unknown cluster specifier: " + proto.getClusterSpecifierCase()); | ||
} | ||
return StructOrError.fromStruct(new RouteAction(cluster, weightedClusters)); | ||
long timeoutNano = TimeUnit.SECONDS.toNanos(15L); // default 15s | ||
if (proto.hasMaxGrpcTimeout()) { | ||
timeoutNano = Durations.toNanos(proto.getMaxGrpcTimeout()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If configured as 0, the maximum allowed timeout for gRPC requests is infinity. |
||
} else if (proto.hasTimeout()) { | ||
timeoutNano = Durations.toNanos(proto.getTimeout()); | ||
} | ||
return StructOrError.fromStruct(new RouteAction(timeoutNano, cluster, weightedClusters)); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The "downstream end-of-stream has been processed" in envoy API doc is about the stream from client to the envoy proxy, which more or less corresponds to
onComplete()
of client's request StreamObserver in proxyless case (Because the local xds plugin itself is the "envoy proxy".). I think it shouldn't be stated as "end-of-stream has been processed" for the proxyless case, in which the stream connects to the backend directly. cc @dfawley @ejona86There 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.
I also just noticed that by the description of this envoy API doc, in bidi-streaming or client-streaming case, the
timeout
may not be converted to grpc deadline. (Althoughmax_grpc_timeout
can always be converted to grpc deadline)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.
Deleted the comment if you don't like it (although I don't think there is any problem stating in that way as the description is from the perspective of a Route, "downstream" still makes senses from an implementation's perspective).
Envoy's API doc also mentions that a value of 0 for
timeout
will disable the route's timeout. Added that case as well.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.
The
timeout
java field is a combination oftimeout
envoy api field andmax_grpc_timeout
envoy api field (The latter, if specified, overrides the former). And I noticed that the two envoy api fields measure different time span for grpc requests, especially for client-streaming case. The latter definitely does not measure the span from "downstream EOS"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.
I didn't notice this detail before (
timeout
starts counting after the client sends its end-stream). This behavior might be difficult to implement -- at least we can't do it in Go for unary RPCs without some changes in the channel.@markdroth do you think we'll need to match Envoy behavior here, or could we treat it as a known difference and call it out in the design?
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.
I don't think it's really necessary to mimic Envoy's behavior in this regard. I think it's fine for us to just use this to control our existing timeout semantics, just as if timeout were set via the service config.
We should call this out in the gRFC, though.
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.
A preexisting management server may set the HTTP
timeout
for only 500ms, withgrpc_max_timeout
unset. This works perfectly for long client streaming with envoy proxy. But it will fail all client streaming requests from a proxyless grpc client.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.
How about we don't support HTTP
timeout
for client/bidi streaming, onlymax_grpc_timeout
is supported for them?