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

feat: update DirectPath environment variables #1412

Merged
merged 4 commits into from Jun 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -80,6 +80,8 @@
@InternalExtensionOnly
public final class InstantiatingGrpcChannelProvider implements TransportChannelProvider {
static final String DIRECT_PATH_ENV_VAR = "GOOGLE_CLOUD_ENABLE_DIRECT_PATH";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new ones should be private, I agree, but for the old ones, I guess it will technically make it a breaknig change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the new one private, and keep the old one as what it is (i.e., without adding private).

private static final String DIRECT_PATH_ENV_DISABLE_DIRECT_PATH =
"GOOGLE_CLOUD_DISABLE_DIRECT_PATH";
static final long DIRECT_PATH_KEEP_ALIVE_TIME_SECONDS = 3600;
static final long DIRECT_PATH_KEEP_ALIVE_TIMEOUT_SECONDS = 20;
// reduce the thundering herd problem of too many channels trying to (re)connect at the same time
Expand Down Expand Up @@ -243,17 +245,27 @@ public ManagedChannel createSingleChannel() throws IOException {
return GrpcTransportChannel.create(outerChannel);
}

// TODO(weiranf): Use attemptDirectPath as the only indicator once setAttemptDirectPath is adapted
// TODO(mohanli): Use attemptDirectPath as the only indicator once setAttemptDirectPath is adapted
// and the env var is removed from client environment.
private boolean isDirectPathEnabled(String serviceAddress) {
String disableDirectPathEnv = envProvider.getenv(DIRECT_PATH_ENV_DISABLE_DIRECT_PATH);
boolean isDirectPathDisabled = Boolean.parseBoolean(disableDirectPathEnv);
if (isDirectPathDisabled) {
return false;
}
// Only check attemptDirectPath when DIRECT_PATH_ENV_DISABLE_DIRECT_PATH is not set.
if (attemptDirectPath != null) {
return attemptDirectPath;
}
// Only check DIRECT_PATH_ENV_VAR when attemptDirectPath is not set.
String whiteList = envProvider.getenv(DIRECT_PATH_ENV_VAR);
if (whiteList == null) return false;
if (whiteList == null) {
return false;
}
for (String service : whiteList.split(",")) {
if (!service.isEmpty() && serviceAddress.contains(service)) return true;
if (!service.isEmpty() && serviceAddress.contains(service)) {
return true;
}
}
return false;
}
Expand Down