Skip to content
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: Include XdsConfig as a CallOption #11968

Merged
merged 1 commit into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions xds/src/main/java/io/grpc/xds/XdsNameResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ final class XdsNameResolver extends NameResolver {

static final CallOptions.Key<String> CLUSTER_SELECTION_KEY =
CallOptions.Key.create("io.grpc.xds.CLUSTER_SELECTION_KEY");
static final CallOptions.Key<XdsConfig> XDS_CONFIG_CALL_OPTION_KEY =
CallOptions.Key.create("io.grpc.xds.XDS_CONFIG_CALL_OPTION_KEY");
static final CallOptions.Key<Long> RPC_HASH_KEY =
CallOptions.Key.create("io.grpc.xds.RPC_HASH_KEY");
static final CallOptions.Key<Boolean> AUTO_HOST_REWRITE_KEY =
Expand Down Expand Up @@ -467,6 +469,7 @@ public Result selectConfig(PickSubchannelArgs args) {
"Failed to parse service config (method config)"));
}
final String finalCluster = cluster;
final XdsConfig xdsConfig = routingCfg.xdsConfig;
final long hash = generateHash(routeAction.hashPolicies(), headers);
class ClusterSelectionInterceptor implements ClientInterceptor {
@Override
Expand All @@ -475,6 +478,7 @@ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
final Channel next) {
CallOptions callOptionsForCluster =
callOptions.withOption(CLUSTER_SELECTION_KEY, finalCluster)
.withOption(XDS_CONFIG_CALL_OPTION_KEY, xdsConfig)
.withOption(RPC_HASH_KEY, hash);
if (routeAction.autoHostRewrite()) {
callOptionsForCluster = callOptionsForCluster.withOption(AUTO_HOST_REWRITE_KEY, true);
Expand Down Expand Up @@ -801,7 +805,7 @@ private void updateRoutes(
}
// Make newly added clusters selectable by config selector and deleted clusters no longer
// selectable.
routingConfig = new RoutingConfig(httpMaxStreamDurationNano, routesData.build());
routingConfig = new RoutingConfig(xdsConfig, httpMaxStreamDurationNano, routesData.build());
for (String cluster : deletedClusters) {
int count = clusterRefs.get(cluster).refCount.decrementAndGet();
if (count == 0) {
Expand Down Expand Up @@ -879,17 +883,21 @@ private void cleanUpRoutes(Status error) {
* VirtualHost-level configuration for request routing.
*/
private static class RoutingConfig {
private final long fallbackTimeoutNano;
final XdsConfig xdsConfig;
final long fallbackTimeoutNano;
final ImmutableList<RouteData> routes;
final Status errorStatus;

private RoutingConfig(long fallbackTimeoutNano, ImmutableList<RouteData> routes) {
private RoutingConfig(
XdsConfig xdsConfig, long fallbackTimeoutNano, ImmutableList<RouteData> routes) {
this.xdsConfig = checkNotNull(xdsConfig, "xdsConfig");
this.fallbackTimeoutNano = fallbackTimeoutNano;
this.routes = checkNotNull(routes, "routes");
this.errorStatus = null;
}

private RoutingConfig(Status errorStatus) {
this.xdsConfig = null;
this.fallbackTimeoutNano = 0;
this.routes = null;
this.errorStatus = checkNotNull(errorStatus, "errorStatus");
Expand Down
4 changes: 4 additions & 0 deletions xds/src/test/java/io/grpc/xds/XdsNameResolverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,10 @@ private void assertCallSelectClusterResult(
clientCall.start(new NoopClientCallListener<>(), new Metadata());
assertThat(testCall.callOptions.getOption(XdsNameResolver.CLUSTER_SELECTION_KEY))
.isEqualTo("cluster:" + expectedCluster);
XdsConfig xdsConfig =
testCall.callOptions.getOption(XdsNameResolver.XDS_CONFIG_CALL_OPTION_KEY);
assertThat(xdsConfig).isNotNull();
assertThat(xdsConfig.getClusters()).containsKey(expectedCluster); // Without "cluster:" prefix
@SuppressWarnings("unchecked")
Map<String, ?> config = (Map<String, ?>) result.getConfig();
if (expectedTimeoutSec != null) {
Expand Down