-
Notifications
You must be signed in to change notification settings - Fork 4k
googleapis: DirectPath over Interconnect #12760
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
Merged
shivaspeaks
merged 9 commits into
grpc:master
from
shivaspeaks:directpath-over-interconnect
May 19, 2026
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
72b24f6
direct-path-interconnect
shivaspeaks 9b65e38
direct-path-interconnect
shivaspeaks 3aaa6ed
merge from master
shivaspeaks a52050e
rework with QueryParams
shivaspeaks 45cf39c
use one bootstrap file
shivaspeaks 39bce96
resolve comments
shivaspeaks 8106aae
remove empty ampersand edge case
shivaspeaks 20bf74a
use QueryParams instance to handle target
shivaspeaks 69ebc41
remove redundant if-else
shivaspeaks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
| import io.grpc.MetricRecorder; | ||
| import io.grpc.NameResolver; | ||
| import io.grpc.NameResolverRegistry; | ||
| import io.grpc.QueryParams; | ||
| import io.grpc.Status; | ||
| import io.grpc.SynchronizationContext; | ||
| import io.grpc.Uri; | ||
|
|
@@ -47,7 +48,6 @@ | |
| import java.io.Reader; | ||
| import java.net.HttpURLConnection; | ||
| import java.net.URI; | ||
| import java.net.URISyntaxException; | ||
| import java.net.URL; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.List; | ||
|
|
@@ -81,18 +81,26 @@ final class GoogleCloudToProdNameResolver extends NameResolver { | |
| private static HttpConnectionProvider httpConnectionProvider = HttpConnectionFactory.INSTANCE; | ||
| private static int c2pId = new Random().nextInt(); | ||
|
|
||
| private static synchronized BootstrapInfo getBootstrapInfo() | ||
| private static synchronized BootstrapInfo getBootstrapInfo(boolean isForcedXds) | ||
| throws XdsInitializationException, IOException { | ||
| if (bootstrapInfo != null) { | ||
| return bootstrapInfo; | ||
| } | ||
| BootstrapInfo bootstrapInfoTmp = | ||
| InternalGrpcBootstrapperImpl.parseBootstrap(generateBootstrap()); | ||
| BootstrapInfo newInfo; | ||
| if (isForcedXds) { | ||
| newInfo = InternalGrpcBootstrapperImpl.parseBootstrap( | ||
| generateBootstrap("", true)); | ||
| } else { | ||
| newInfo = InternalGrpcBootstrapperImpl.parseBootstrap( | ||
| generateBootstrap( | ||
| queryZoneMetadata(METADATA_URL_ZONE), | ||
| queryIpv6SupportMetadata(METADATA_URL_SUPPORT_IPV6))); | ||
| } | ||
| // Avoid setting global when testing | ||
| if (httpConnectionProvider == HttpConnectionFactory.INSTANCE) { | ||
| bootstrapInfo = bootstrapInfoTmp; | ||
| bootstrapInfo = newInfo; | ||
| } | ||
| return bootstrapInfoTmp; | ||
| return newInfo; | ||
| } | ||
|
|
||
| private final String authority; | ||
|
|
@@ -102,7 +110,8 @@ private static synchronized BootstrapInfo getBootstrapInfo() | |
| private final MetricRecorder metricRecorder; | ||
| private final NameResolver delegate; | ||
| private final boolean usingExecutorResource; | ||
| private final String schemeOverride = !isOnGcp ? "dns" : "xds"; | ||
| private final boolean forceXds; | ||
| private final String schemeOverride; | ||
| private XdsClientResult xdsClientPool; | ||
| private XdsClient xdsClient; | ||
| private Executor executor; | ||
|
|
@@ -122,16 +131,32 @@ private static synchronized BootstrapInfo getBootstrapInfo() | |
| NameResolver.Factory nameResolverFactory) { | ||
| this.executorResource = checkNotNull(executorResource, "executorResource"); | ||
| String targetPath = checkNotNull(checkNotNull(targetUri, "targetUri").getPath(), "targetPath"); | ||
| Uri grpcUri = Uri.create(targetUri.toString()); | ||
| String query = grpcUri.getRawQuery(); | ||
| this.forceXds = checkForceXds(query); | ||
| this.schemeOverride = (forceXds || isOnGcp) ? "xds" : "dns"; | ||
| String newQuery = stripForceXds(query); | ||
|
|
||
| Preconditions.checkArgument( | ||
| targetPath.startsWith("/"), | ||
| "the path component (%s) of the target (%s) must start with '/'", | ||
| targetPath, | ||
| targetUri); | ||
| authority = GrpcUtil.checkAuthority(targetPath.substring(1)); | ||
| syncContext = checkNotNull(args, "args").getSynchronizationContext(); | ||
| targetUri = overrideUriScheme(targetUri, schemeOverride); | ||
|
|
||
| Uri.Builder modifiedTargetBuilder = grpcUri.toBuilder().setScheme(schemeOverride); | ||
| if (newQuery != null) { | ||
| modifiedTargetBuilder.setRawQuery(newQuery); | ||
| } else { | ||
| modifiedTargetBuilder.setRawQuery(null); | ||
| } | ||
| if (schemeOverride.equals("xds")) { | ||
| modifiedTargetBuilder.setRawAuthority(C2P_AUTHORITY); | ||
| } | ||
| targetUri = URI.create(modifiedTargetBuilder.build().toString()); | ||
|
|
||
| if (schemeOverride.equals("xds")) { | ||
| targetUri = overrideUriAuthority(targetUri, C2P_AUTHORITY); | ||
| args = args.toBuilder() | ||
| .setArg(XdsNameResolverProvider.XDS_CLIENT_SUPPLIER, () -> xdsClient) | ||
| .build(); | ||
|
|
@@ -155,6 +180,11 @@ private static synchronized BootstrapInfo getBootstrapInfo() | |
| Resource<Executor> executorResource, | ||
| NameResolver.Factory nameResolverFactory) { | ||
| this.executorResource = checkNotNull(executorResource, "executorResource"); | ||
| String query = targetUri.getRawQuery(); | ||
|
Member
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. Consider working with the query component as an instance of |
||
| this.forceXds = checkForceXds(query); | ||
| this.schemeOverride = (forceXds || isOnGcp) ? "xds" : "dns"; | ||
| String newQuery = stripForceXds(query); | ||
|
|
||
| Preconditions.checkArgument( | ||
| targetUri.isPathAbsolute(), | ||
| "the path component of the target (%s) must start with '/'", | ||
|
|
@@ -167,6 +197,12 @@ private static synchronized BootstrapInfo getBootstrapInfo() | |
| authority = GrpcUtil.checkAuthority(pathSegments.get(0)); | ||
| syncContext = checkNotNull(args, "args").getSynchronizationContext(); | ||
| Uri.Builder modifiedTargetBuilder = targetUri.toBuilder().setScheme(schemeOverride); | ||
| if (newQuery != null) { | ||
| modifiedTargetBuilder.setRawQuery(newQuery); | ||
| } else { | ||
| modifiedTargetBuilder.setRawQuery(null); | ||
| } | ||
|
|
||
| if (schemeOverride.equals("xds")) { | ||
| modifiedTargetBuilder.setRawAuthority(C2P_AUTHORITY); | ||
| args = | ||
|
|
@@ -226,7 +262,7 @@ class Resolve implements Runnable { | |
| public void run() { | ||
| BootstrapInfo bootstrapInfo = null; | ||
| try { | ||
| bootstrapInfo = getBootstrapInfo(); | ||
| bootstrapInfo = getBootstrapInfo(forceXds); | ||
| } catch (IOException e) { | ||
| listener.onError( | ||
| Status.INTERNAL.withDescription("Unable to get metadata").withCause(e)); | ||
|
|
@@ -259,16 +295,11 @@ public void run() { | |
| executor.execute(new Resolve()); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| static ImmutableMap<String, ?> generateBootstrap() throws IOException { | ||
| return generateBootstrap( | ||
| queryZoneMetadata(METADATA_URL_ZONE), | ||
| queryIpv6SupportMetadata(METADATA_URL_SUPPORT_IPV6)); | ||
| } | ||
|
|
||
| private static ImmutableMap<String, ?> generateBootstrap(String zone, boolean supportIpv6) { | ||
| private static ImmutableMap<String, ?> generateBootstrap( | ||
| String zone, boolean supportIpv6) { | ||
| ImmutableMap.Builder<String, Object> nodeBuilder = ImmutableMap.builder(); | ||
| nodeBuilder.put("id", "C2P-" + (c2pId & Integer.MAX_VALUE)); | ||
| String nodeIdPrefix = isOnGcp ? "C2P-" : "C2P-non-gcp-"; | ||
| nodeBuilder.put("id", nodeIdPrefix + (c2pId & Integer.MAX_VALUE)); | ||
| if (!zone.isEmpty()) { | ||
| nodeBuilder.put("locality", ImmutableMap.of("zone", zone)); | ||
| } | ||
|
|
@@ -373,24 +404,26 @@ static void setC2pId(int c2pId) { | |
| GoogleCloudToProdNameResolver.c2pId = c2pId; | ||
| } | ||
|
|
||
| private static URI overrideUriScheme(URI uri, String scheme) { | ||
| URI res; | ||
| try { | ||
| res = new URI(scheme, uri.getAuthority(), uri.getPath(), uri.getQuery(), uri.getFragment()); | ||
| } catch (URISyntaxException ex) { | ||
| throw new IllegalArgumentException("Invalid scheme: " + scheme, ex); | ||
| private static boolean checkForceXds(String query) { | ||
| if (query == null) { | ||
| return false; | ||
| } | ||
| return res; | ||
| QueryParams params = QueryParams.fromRawQuery(query); | ||
| for (QueryParams.Entry entry : params.asList()) { | ||
| if ("force-xds".equals(entry.getKey())) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private static URI overrideUriAuthority(URI uri, String authority) { | ||
| URI res; | ||
| try { | ||
| res = new URI(uri.getScheme(), authority, uri.getPath(), uri.getQuery(), uri.getFragment()); | ||
| } catch (URISyntaxException ex) { | ||
| throw new IllegalArgumentException("Invalid authority: " + authority, ex); | ||
| private static String stripForceXds(String query) { | ||
| if (query == null) { | ||
| return null; | ||
| } | ||
| return res; | ||
| QueryParams params = QueryParams.fromRawQuery(query); | ||
| params.asList().removeIf(entry -> "force-xds".equals(entry.getKey())); | ||
| return params.toRawQuery(); | ||
| } | ||
|
|
||
| private enum HttpConnectionFactory implements HttpConnectionProvider { | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.