-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(storage): add support for DirectPath over Interconnect #14006
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
base: main
Are you sure you want to change the base?
Changes from all commits
23147be
213ada7
c1b4f5f
e0177bd
aee5030
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,6 +134,9 @@ public final class GrpcStorageOptions extends StorageOptions | |
| private static final String GCS_SCOPE = "https://www.googleapis.com/auth/devstorage.full_control"; | ||
| private static final Set<String> SCOPES = ImmutableSet.of(GCS_SCOPE); | ||
| private static final String DEFAULT_HOST = "https://storage.googleapis.com"; | ||
| private static final String DEFAULT_HOST_DIRECT_PATH = "https://storage-direct.googleapis.com"; | ||
| private static final String DEFAULT_HOST_NO_SCHEME = "storage.googleapis.com"; | ||
|
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. These are unused and the string literals are hardcoded in rewriteHost() and overrideAuthority().
Contributor
Author
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. Done. Replaced hardcoded string literals in rewriteHost() and overrideAuthority() with DEFAULT_HOST_DIRECT_PATH and DEFAULT_HOST_NO_SCHEME constants. Co-authored by AI Agent |
||
| private static final String DEFAULT_HOST_DIRECT_PATH_NO_SCHEME = "storage-direct.googleapis.com"; | ||
| // If true, disable the bound-token-by-default feature for DirectPath. | ||
| private static final boolean DIRECT_PATH_BOUND_TOKEN_DISABLED = | ||
| Boolean.parseBoolean( | ||
|
|
@@ -142,6 +145,7 @@ public final class GrpcStorageOptions extends StorageOptions | |
| private final GrpcRetryAlgorithmManager retryAlgorithmManager; | ||
| private final java.time.Duration terminationAwaitDuration; | ||
| private final boolean attemptDirectPath; | ||
| private final boolean attemptDirectPathXdsOverInterconnect; | ||
| private final boolean enableGrpcClientMetrics; | ||
|
|
||
| private final boolean grpcClientMetricsManuallyEnabled; | ||
|
|
@@ -160,6 +164,7 @@ private GrpcStorageOptions(Builder builder, GrpcStorageDefaults serviceDefaults) | |
| builder.terminationAwaitDuration, | ||
| serviceDefaults.getTerminationAwaitDurationJavaTime()); | ||
| this.attemptDirectPath = builder.attemptDirectPath; | ||
| this.attemptDirectPathXdsOverInterconnect = builder.attemptDirectPathXdsOverInterconnect; | ||
| this.enableGrpcClientMetrics = builder.enableGrpcClientMetrics; | ||
| this.grpcClientMetricsManuallyEnabled = builder.grpcMetricsManuallyEnabled; | ||
| this.grpcInterceptorProvider = builder.grpcInterceptorProvider; | ||
|
|
@@ -197,6 +202,23 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE | |
| this.openTelemetry = HttpStorageOptions.getDefaultInstance().getOpenTelemetry(); | ||
| } | ||
|
|
||
| private static String rewriteHost(String endpoint, String oldHost, String newHost) { | ||
| String prefix = ""; | ||
| String rest = endpoint; | ||
| int schemeIndex = endpoint.indexOf("://"); | ||
| if (schemeIndex >= 0) { | ||
| prefix = endpoint.substring(0, schemeIndex + 3); | ||
| rest = endpoint.substring(schemeIndex + 3); | ||
| } | ||
| if (rest.startsWith(oldHost)) { | ||
| int len = oldHost.length(); | ||
| if (rest.length() == len || rest.charAt(len) == ':' || rest.charAt(len) == '/') { | ||
| return prefix + newHost + rest.substring(len); | ||
| } | ||
| } | ||
| return endpoint; | ||
| } | ||
|
|
||
| /** | ||
| * We have to perform several introspections and detections to cross-wire/support several features | ||
| * that are either gapic primitives, ServiceOption primitives or GCS semantic requirements. | ||
|
|
@@ -230,6 +252,9 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE | |
| */ | ||
| private Tuple<StorageSettings, Opts<UserProject>> resolveSettingsAndOpts() throws IOException { | ||
| String endpoint = getHost(); | ||
| if (attemptDirectPathXdsOverInterconnect) { | ||
| endpoint = rewriteHost(endpoint, DEFAULT_HOST_NO_SCHEME, DEFAULT_HOST_DIRECT_PATH_NO_SCHEME); | ||
| } | ||
| URI uri = URI.create(endpoint); | ||
| String scheme = uri.getScheme(); | ||
| int port = uri.getPort(); | ||
|
|
@@ -322,7 +347,8 @@ private Tuple<StorageSettings, Opts<UserProject>> resolveSettingsAndOpts() throw | |
| InstantiatingGrpcChannelProvider.newBuilder() | ||
| .setEndpoint(endpoint) | ||
| .setAllowNonDefaultServiceAccount(true) | ||
| .setAttemptDirectPath(attemptDirectPath); | ||
| .setAttemptDirectPath(attemptDirectPath || attemptDirectPathXdsOverInterconnect) | ||
| .setAttemptDirectPathXdsOverInterconnect(attemptDirectPathXdsOverInterconnect); | ||
|
|
||
| if (!DIRECT_PATH_BOUND_TOKEN_DISABLED) { | ||
| channelProviderBuilder.setAllowHardBoundTokenTypes( | ||
|
|
@@ -337,6 +363,18 @@ private Tuple<StorageSettings, Opts<UserProject>> resolveSettingsAndOpts() throw | |
| channelProviderBuilder.setAttemptDirectPathXds(); | ||
| } | ||
|
|
||
| if (attemptDirectPathXdsOverInterconnect) { | ||
| com.google.api.core.ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder> | ||
| existingConfigurator = channelProviderBuilder.getChannelConfigurator(); | ||
| channelProviderBuilder.setChannelConfigurator( | ||
| channelBuilder -> { | ||
| if (existingConfigurator != null) { | ||
| channelBuilder = existingConfigurator.apply(channelBuilder); | ||
| } | ||
| return channelBuilder.overrideAuthority(DEFAULT_HOST_NO_SCHEME); | ||
| }); | ||
| } | ||
|
|
||
| if (scheme.equals("http")) { | ||
| channelProviderBuilder.setChannelConfigurator(ManagedChannelBuilder::usePlaintext); | ||
| } | ||
|
|
@@ -428,6 +466,7 @@ public int hashCode() { | |
| retryAlgorithmManager, | ||
| terminationAwaitDuration, | ||
| attemptDirectPath, | ||
| attemptDirectPathXdsOverInterconnect, | ||
| enableGrpcClientMetrics, | ||
| grpcInterceptorProvider, | ||
| blobWriteSessionConfig, | ||
|
|
@@ -445,6 +484,7 @@ public boolean equals(Object o) { | |
| } | ||
| GrpcStorageOptions that = (GrpcStorageOptions) o; | ||
| return attemptDirectPath == that.attemptDirectPath | ||
| && attemptDirectPathXdsOverInterconnect == that.attemptDirectPathXdsOverInterconnect | ||
| && enableGrpcClientMetrics == that.enableGrpcClientMetrics | ||
| && Objects.equals(retryAlgorithmManager, that.retryAlgorithmManager) | ||
| && Objects.equals(terminationAwaitDuration, that.terminationAwaitDuration) | ||
|
|
@@ -494,6 +534,7 @@ public static final class Builder extends StorageOptions.Builder { | |
| private StorageRetryStrategy storageRetryStrategy; | ||
| private java.time.Duration terminationAwaitDuration; | ||
| private boolean attemptDirectPath = GrpcStorageDefaults.INSTANCE.isAttemptDirectPath(); | ||
| private boolean attemptDirectPathXdsOverInterconnect = false; | ||
| private boolean enableGrpcClientMetrics = | ||
| GrpcStorageDefaults.INSTANCE.isEnableGrpcClientMetrics(); | ||
| private GrpcInterceptorProvider grpcInterceptorProvider = | ||
|
|
@@ -512,6 +553,7 @@ public static final class Builder extends StorageOptions.Builder { | |
| this.storageRetryStrategy = gso.getRetryAlgorithmManager().retryStrategy; | ||
| this.terminationAwaitDuration = gso.getTerminationAwaitDuration(); | ||
| this.attemptDirectPath = gso.attemptDirectPath; | ||
| this.attemptDirectPathXdsOverInterconnect = gso.attemptDirectPathXdsOverInterconnect; | ||
| this.enableGrpcClientMetrics = gso.enableGrpcClientMetrics; | ||
| this.grpcInterceptorProvider = gso.grpcInterceptorProvider; | ||
| this.blobWriteSessionConfig = gso.blobWriteSessionConfig; | ||
|
|
@@ -556,6 +598,18 @@ public GrpcStorageOptions.Builder setAttemptDirectPath(boolean attemptDirectPath | |
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Option for whether this client should attempt to use DirectPath over Interconnect (on-premise | ||
| * xDS name resolution). | ||
| * | ||
| * @since 2.72.0 | ||
| */ | ||
| public GrpcStorageOptions.Builder setAttemptDirectPathXdsOverInterconnect( | ||
|
Contributor
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. Add Beta API annotation, till the feature is GA |
||
| boolean attemptDirectPathXdsOverInterconnect) { | ||
| this.attemptDirectPathXdsOverInterconnect = attemptDirectPathXdsOverInterconnect; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Option for whether this client should emit internal gRPC client internal metrics to Cloud | ||
| * Monitoring. To disable metric reporting, set this to false. True by default. Emitting metrics | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.cloud.storage.it; | ||
|
|
||
| import static org.junit.Assume.assumeTrue; | ||
|
|
||
| import com.google.cloud.storage.Storage; | ||
| import com.google.cloud.storage.StorageOptions; | ||
| import com.google.cloud.storage.TransportCompatibility.Transport; | ||
| import com.google.cloud.storage.it.runner.StorageITRunner; | ||
| import com.google.cloud.storage.it.runner.annotations.Backend; | ||
| import com.google.cloud.storage.it.runner.annotations.Inject; | ||
| import com.google.cloud.storage.it.runner.annotations.SingleBackend; | ||
| import com.google.cloud.storage.it.runner.annotations.StorageFixture; | ||
| import org.junit.Ignore; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| @RunWith(StorageITRunner.class) | ||
| @SingleBackend(Backend.PROD) | ||
| public final class ITGrpcDirectPathTest { | ||
|
|
||
| @Inject | ||
| @StorageFixture(Transport.GRPC) | ||
| public Storage storage; | ||
|
|
||
| @Ignore( | ||
| "Bypassed because DirectPath over Interconnect (GCI) requires a specialized hybrid network environment (Interconnect and Traffic Director configured for storage-direct) and cannot be validated in standard CI or local workstations.") | ||
| @Test | ||
| public void clientShouldWork_directPathXdsOverInterconnect() throws Exception { | ||
| assumeTrue( | ||
| "Environment cannot resolve storage-direct.googleapis.com", canResolveDirectPathAddress()); | ||
| StorageOptions options = | ||
| StorageOptions.grpc() | ||
| .setCredentials(storage.getOptions().getCredentials()) | ||
| .setAttemptDirectPathXdsOverInterconnect(true) | ||
| .setEnableGrpcClientMetrics(false) | ||
| .build(); | ||
| try (Storage client = options.getService()) { | ||
| client.list(Storage.BucketListOption.pageSize(1)); | ||
| } | ||
| } | ||
|
|
||
| private static boolean canResolveDirectPathAddress() { | ||
| try { | ||
| java.net.InetAddress.getAllByName("storage-direct.googleapis.com"); | ||
| return true; | ||
| } catch (java.net.UnknownHostException e) { | ||
| return false; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you look into the feedback related to overrideAuthority here https://docs.google.com/document/d/1d9OS84flOtAWD9Bx4HGdzKFV2t1_XlB5l8YnXWUto7Q/edit?tab=t.0