Skip to content
This repository was archived by the owner on Sep 26, 2023. It is now read-only.

Commit 4f63b61

Browse files
feat: update DirectPath environment variables (#1412)
Co-authored-by: Vadym Matsishevskyi <[email protected]>
1 parent 0eac650 commit 4f63b61

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
@InternalExtensionOnly
8181
public final class InstantiatingGrpcChannelProvider implements TransportChannelProvider {
8282
static final String DIRECT_PATH_ENV_VAR = "GOOGLE_CLOUD_ENABLE_DIRECT_PATH";
83+
private static final String DIRECT_PATH_ENV_DISABLE_DIRECT_PATH =
84+
"GOOGLE_CLOUD_DISABLE_DIRECT_PATH";
8385
static final long DIRECT_PATH_KEEP_ALIVE_TIME_SECONDS = 3600;
8486
static final long DIRECT_PATH_KEEP_ALIVE_TIMEOUT_SECONDS = 20;
8587
// reduce the thundering herd problem of too many channels trying to (re)connect at the same time
@@ -243,17 +245,27 @@ public ManagedChannel createSingleChannel() throws IOException {
243245
return GrpcTransportChannel.create(outerChannel);
244246
}
245247

246-
// TODO(weiranf): Use attemptDirectPath as the only indicator once setAttemptDirectPath is adapted
248+
// TODO(mohanli): Use attemptDirectPath as the only indicator once setAttemptDirectPath is adapted
247249
// and the env var is removed from client environment.
248250
private boolean isDirectPathEnabled(String serviceAddress) {
251+
String disableDirectPathEnv = envProvider.getenv(DIRECT_PATH_ENV_DISABLE_DIRECT_PATH);
252+
boolean isDirectPathDisabled = Boolean.parseBoolean(disableDirectPathEnv);
253+
if (isDirectPathDisabled) {
254+
return false;
255+
}
256+
// Only check attemptDirectPath when DIRECT_PATH_ENV_DISABLE_DIRECT_PATH is not set.
249257
if (attemptDirectPath != null) {
250258
return attemptDirectPath;
251259
}
252260
// Only check DIRECT_PATH_ENV_VAR when attemptDirectPath is not set.
253261
String whiteList = envProvider.getenv(DIRECT_PATH_ENV_VAR);
254-
if (whiteList == null) return false;
262+
if (whiteList == null) {
263+
return false;
264+
}
255265
for (String service : whiteList.split(",")) {
256-
if (!service.isEmpty() && serviceAddress.contains(service)) return true;
266+
if (!service.isEmpty() && serviceAddress.contains(service)) {
267+
return true;
268+
}
257269
}
258270
return false;
259271
}

0 commit comments

Comments
 (0)