Skip to content

Commit 292f3b9

Browse files
authored
xds: implement routing in xDS resolver with config selector API (#7275)
Name resolver implementation for performing xDS request routing before the call is made: the resolver emits a config selector to the Channel to let calls make routing decision before delegating to the corresponding cluster load balancer's picker. This is a branched xDS name resolver implementation. It will replace the existing xDS resolver once the Channel's integration for using config selector is done.
1 parent 03f83bb commit 292f3b9

8 files changed

+1073
-6
lines changed

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

+2-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import static io.grpc.xds.XdsSubchannelPickers.BUFFER_PICKER;
2525

2626
import com.google.common.annotations.VisibleForTesting;
27-
import io.grpc.CallOptions;
2827
import io.grpc.ConnectivityState;
2928
import io.grpc.InternalLogId;
3029
import io.grpc.LoadBalancer;
@@ -51,9 +50,6 @@ class ClusterManagerLoadBalancer extends LoadBalancer {
5150

5251
@VisibleForTesting
5352
static final int DELAYED_CHILD_DELETION_TIME_MINUTES = 15;
54-
@VisibleForTesting
55-
static final CallOptions.Key<String> ROUTING_CLUSTER_NAME_KEY =
56-
CallOptions.Key.create("io.grpc.xds.ROUTING_CLUSTER_NAME_KEY");
5753

5854
private final Map<String, ChildLbState> childLbStates = new HashMap<>();
5955
private final Helper helper;
@@ -148,7 +144,8 @@ private void updateOverallBalancingState() {
148144
SubchannelPicker picker = new SubchannelPicker() {
149145
@Override
150146
public PickResult pickSubchannel(PickSubchannelArgs args) {
151-
String clusterName = args.getCallOptions().getOption(ROUTING_CLUSTER_NAME_KEY);
147+
String clusterName =
148+
args.getCallOptions().getOption(XdsNameResolver2.CLUSTER_SELECTION_KEY);
152149
SubchannelPicker delegate = childPickers.get(clusterName);
153150
if (delegate == null) {
154151
return

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

+3
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,9 @@ static StructOrError<RouteAction> fromEnvoyProtoRouteAction(
11531153
case WEIGHTED_CLUSTERS:
11541154
List<io.envoyproxy.envoy.config.route.v3.WeightedCluster.ClusterWeight> clusterWeights
11551155
= proto.getWeightedClusters().getClustersList();
1156+
if (clusterWeights.isEmpty()) {
1157+
return StructOrError.fromError("No cluster found in weighted cluster list");
1158+
}
11561159
weightedClusters = new ArrayList<>();
11571160
for (io.envoyproxy.envoy.config.route.v3.WeightedCluster.ClusterWeight clusterWeight
11581161
: clusterWeights) {

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

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ final class RouteMatch {
4545
this.headerMatchers = headerMatchers;
4646
}
4747

48+
@VisibleForTesting
4849
RouteMatch(@Nullable String pathPrefixMatch, @Nullable String pathExactMatch) {
4950
this(
5051
new PathMatcher(pathExactMatch, pathPrefixMatch, null),

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

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import io.grpc.Status;
3030
import io.grpc.alts.GoogleDefaultChannelBuilder;
3131
import io.grpc.internal.ObjectPool;
32+
import io.grpc.xds.Bootstrapper.BootstrapInfo;
3233
import io.grpc.xds.Bootstrapper.ChannelCreds;
3334
import io.grpc.xds.Bootstrapper.ServerInfo;
3435
import io.grpc.xds.EnvoyProtoData.DropOverload;
@@ -549,6 +550,7 @@ void removeClientStats(String clusterName, @Nullable String clusterServiceName)
549550
throw new UnsupportedOperationException();
550551
}
551552

553+
// TODO(chengyuanzhang): eliminate this factory
552554
abstract static class XdsClientFactory {
553555
abstract XdsClient createXdsClient();
554556
}
@@ -685,4 +687,8 @@ boolean isUseProtocolV3() {
685687
return useProtocolV3;
686688
}
687689
}
690+
691+
interface XdsClientPoolFactory {
692+
ObjectPool<XdsClient> newXdsClientObjectPool(BootstrapInfo bootstrapInfo);
693+
}
688694
}

0 commit comments

Comments
 (0)