Skip to content

Commit bc3c764

Browse files
committed
xds: Include XdsConfig as a CallOption
This allows Filters to access the xds configuration for their own processing. From gRFC A83: > This data is available via the XdsConfig attribute introduced in A74. > If the xDS ConfigSelector is not already passing that attribute to the > filters, it will need to be changed to do so.
1 parent a57c14a commit bc3c764

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ final class XdsNameResolver extends NameResolver {
9494

9595
static final CallOptions.Key<String> CLUSTER_SELECTION_KEY =
9696
CallOptions.Key.create("io.grpc.xds.CLUSTER_SELECTION_KEY");
97+
static final CallOptions.Key<XdsConfig> XDS_CONFIG_CALL_OPTION_KEY =
98+
CallOptions.Key.create("io.grpc.xds.XDS_CONFIG_CALL_OPTION_KEY");
9799
static final CallOptions.Key<Long> RPC_HASH_KEY =
98100
CallOptions.Key.create("io.grpc.xds.RPC_HASH_KEY");
99101
static final CallOptions.Key<Boolean> AUTO_HOST_REWRITE_KEY =
@@ -467,6 +469,7 @@ public Result selectConfig(PickSubchannelArgs args) {
467469
"Failed to parse service config (method config)"));
468470
}
469471
final String finalCluster = cluster;
472+
final XdsConfig xdsConfig = routingCfg.xdsConfig;
470473
final long hash = generateHash(routeAction.hashPolicies(), headers);
471474
class ClusterSelectionInterceptor implements ClientInterceptor {
472475
@Override
@@ -475,6 +478,7 @@ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
475478
final Channel next) {
476479
CallOptions callOptionsForCluster =
477480
callOptions.withOption(CLUSTER_SELECTION_KEY, finalCluster)
481+
.withOption(XDS_CONFIG_CALL_OPTION_KEY, xdsConfig)
478482
.withOption(RPC_HASH_KEY, hash);
479483
if (routeAction.autoHostRewrite()) {
480484
callOptionsForCluster = callOptionsForCluster.withOption(AUTO_HOST_REWRITE_KEY, true);
@@ -801,7 +805,7 @@ private void updateRoutes(
801805
}
802806
// Make newly added clusters selectable by config selector and deleted clusters no longer
803807
// selectable.
804-
routingConfig = new RoutingConfig(httpMaxStreamDurationNano, routesData.build());
808+
routingConfig = new RoutingConfig(xdsConfig, httpMaxStreamDurationNano, routesData.build());
805809
for (String cluster : deletedClusters) {
806810
int count = clusterRefs.get(cluster).refCount.decrementAndGet();
807811
if (count == 0) {
@@ -879,17 +883,21 @@ private void cleanUpRoutes(Status error) {
879883
* VirtualHost-level configuration for request routing.
880884
*/
881885
private static class RoutingConfig {
882-
private final long fallbackTimeoutNano;
886+
final XdsConfig xdsConfig;
887+
final long fallbackTimeoutNano;
883888
final ImmutableList<RouteData> routes;
884889
final Status errorStatus;
885890

886-
private RoutingConfig(long fallbackTimeoutNano, ImmutableList<RouteData> routes) {
891+
private RoutingConfig(
892+
XdsConfig xdsConfig, long fallbackTimeoutNano, ImmutableList<RouteData> routes) {
893+
this.xdsConfig = checkNotNull(xdsConfig, "xdsConfig");
887894
this.fallbackTimeoutNano = fallbackTimeoutNano;
888895
this.routes = checkNotNull(routes, "routes");
889896
this.errorStatus = null;
890897
}
891898

892899
private RoutingConfig(Status errorStatus) {
900+
this.xdsConfig = null;
893901
this.fallbackTimeoutNano = 0;
894902
this.routes = null;
895903
this.errorStatus = checkNotNull(errorStatus, "errorStatus");

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,6 +1672,10 @@ private void assertCallSelectClusterResult(
16721672
clientCall.start(new NoopClientCallListener<>(), new Metadata());
16731673
assertThat(testCall.callOptions.getOption(XdsNameResolver.CLUSTER_SELECTION_KEY))
16741674
.isEqualTo("cluster:" + expectedCluster);
1675+
XdsConfig xdsConfig =
1676+
testCall.callOptions.getOption(XdsNameResolver.XDS_CONFIG_CALL_OPTION_KEY);
1677+
assertThat(xdsConfig).isNotNull();
1678+
assertThat(xdsConfig.getClusters()).containsKey(expectedCluster); // Without "cluster:" prefix
16751679
@SuppressWarnings("unchecked")
16761680
Map<String, ?> config = (Map<String, ?>) result.getConfig();
16771681
if (expectedTimeoutSec != null) {

0 commit comments

Comments
 (0)