Skip to content

Commit 77c9ba2

Browse files
committed
Explicitly set value of 0 in RouteAction is different than unset. Fallback should not happen if the timeout value in RouteAction is set (including 0).
1 parent 49c14d2 commit 77c9ba2

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

xds/src/main/java/io/grpc/xds/EnvoyProtoData.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,24 +1136,23 @@ static StructOrError<HeaderMatcher> convertEnvoyProtoHeaderMatcher(
11361136
* See corresponding Envoy proto message {@link io.envoyproxy.envoy.config.route.v3.RouteAction}.
11371137
*/
11381138
static final class RouteAction {
1139-
private final long timeoutNano;
1139+
@Nullable
1140+
private final Long timeoutNano;
11401141
// Exactly one of the following fields is non-null.
11411142
@Nullable
11421143
private final String cluster;
11431144
@Nullable
11441145
private final List<ClusterWeight> weightedClusters;
11451146

11461147
@VisibleForTesting
1147-
RouteAction(
1148-
long timeoutNano,
1149-
@Nullable String cluster,
1148+
RouteAction(@Nullable Long timeoutNano, @Nullable String cluster,
11501149
@Nullable List<ClusterWeight> weightedClusters) {
11511150
this.timeoutNano = timeoutNano;
11521151
this.cluster = cluster;
11531152
this.weightedClusters = weightedClusters;
11541153
}
11551154

1156-
1155+
@Nullable
11571156
Long getTimeoutNano() {
11581157
return timeoutNano;
11591158
}
@@ -1190,7 +1189,9 @@ public int hashCode() {
11901189
@Override
11911190
public String toString() {
11921191
ToStringHelper toStringHelper = MoreObjects.toStringHelper(this);
1193-
toStringHelper.add("timeout", timeoutNano + "ns");
1192+
if (timeoutNano != null) {
1193+
toStringHelper.add("timeout", timeoutNano + "ns");
1194+
}
11941195
if (cluster != null) {
11951196
toStringHelper.add("cluster", cluster);
11961197
}
@@ -1230,7 +1231,7 @@ static StructOrError<RouteAction> fromEnvoyProtoRouteAction(
12301231
return StructOrError.fromError(
12311232
"Unknown cluster specifier: " + proto.getClusterSpecifierCase());
12321233
}
1233-
long timeoutNano = 0L;
1234+
Long timeoutNano = null;
12341235
if (proto.hasMaxStreamDuration()) {
12351236
io.envoyproxy.envoy.config.route.v3.RouteAction.MaxStreamDuration maxStreamDuration
12361237
= proto.getMaxStreamDuration();

xds/src/main/java/io/grpc/xds/XdsNameResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ public Result selectConfig(PickSubchannelArgs args) {
359359
// TODO(chengyuanzhang): avoid service config generation and parsing for each call.
360360
Map<String, ?> rawServiceConfig = Collections.emptyMap();
361361
if (enableTimeout) {
362-
long timeoutNano = selectedRoute.getRouteAction().getTimeoutNano();
363-
if (timeoutNano == 0) {
362+
Long timeoutNano = selectedRoute.getRouteAction().getTimeoutNano();
363+
if (timeoutNano == null) {
364364
timeoutNano = routingConfig.fallbackTimeoutNano;
365365
}
366366
if (timeoutNano > 0) {

xds/src/test/java/io/grpc/xds/EnvoyProtoDataTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public void convertRoute() {
214214
new Route(
215215
new RouteMatch(new PathMatcher("/service/method", null, null),
216216
Collections.<HeaderMatcher>emptyList(), null),
217-
new RouteAction(0, "cluster-foo", null)));
217+
new RouteAction(null, "cluster-foo", null)));
218218

219219
io.envoyproxy.envoy.config.route.v3.Route unsupportedProto =
220220
io.envoyproxy.envoy.config.route.v3.Route.newBuilder()
@@ -477,7 +477,7 @@ public void convertRouteAction_timeoutUnset() {
477477
.setCluster("cluster-foo")
478478
.build();
479479
StructOrError<RouteAction> struct = RouteAction.fromEnvoyProtoRouteAction(proto);
480-
assertThat(struct.getStruct().getTimeoutNano()).isEqualTo(0);
480+
assertThat(struct.getStruct().getTimeoutNano()).isNull();
481481
}
482482

483483
@Test

xds/src/test/java/io/grpc/xds/XdsNameResolverTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public void resolved_noTimeout() {
297297
resolver.start(mockListener);
298298
FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
299299
Route route = new Route(new RouteMatch(null, call1.getFullMethodNameForPath()),
300-
new RouteAction(0L, cluster1, null)); // per-route timeout unset
300+
new RouteAction(null, cluster1, null)); // per-route timeout unset
301301
VirtualHost virtualHost = new VirtualHost("does not matter",
302302
Collections.singletonList(AUTHORITY), Collections.singletonList(route));
303303
xdsClient.deliverLdsUpdate(AUTHORITY, 0L, Collections.singletonList(virtualHost));
@@ -317,7 +317,7 @@ public void resolved_fallbackToHttpMaxStreamDurationAsTimeout() {
317317
resolver.start(mockListener);
318318
FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
319319
Route route = new Route(new RouteMatch(null, call1.getFullMethodNameForPath()),
320-
new RouteAction(0L, cluster1, null)); // per-route timeout unset
320+
new RouteAction(null, cluster1, null)); // per-route timeout unset
321321
VirtualHost virtualHost = new VirtualHost("does not matter",
322322
Collections.singletonList(AUTHORITY), Collections.singletonList(route));
323323
xdsClient.deliverLdsUpdate(AUTHORITY, TimeUnit.SECONDS.toNanos(5L),

0 commit comments

Comments
 (0)