feat: update DirectPath environment variables #1412
Changes from 1 commit
8250984
d70e56b
5d474e2
58c01eb
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 |
---|---|---|
|
@@ -79,6 +79,7 @@ | |
*/ | ||
@InternalExtensionOnly | ||
public final class InstantiatingGrpcChannelProvider implements TransportChannelProvider { | ||
static final String DIRECT_PATH_ENV_VAR = "GOOGLE_CLOUD_ENABLE_DIRECT_PATH"; | ||
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; | ||
|
@@ -243,14 +244,22 @@ public ManagedChannel createSingleChannel() throws IOException { | |
return GrpcTransportChannel.create(outerChannel); | ||
} | ||
|
||
private boolean isDirectPathEnabled() { | ||
// TODO(weiranf): Use attemptDirectPath as the only indicator once setAttemptDirectPath is adapted | ||
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. please file a bug for this and reference it here 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. Created b/192398509 to myself. |
||
// and the env var is removed from client environment. | ||
private boolean isDirectPathEnabled(String serviceAddress) { | ||
// Only check attemptDirectPath when DIRECT_PATH_ENV_DISABLE_DIRECT_PATH is not set. | ||
if (Boolean.parseBoolean(envProvider.getenv(DIRECT_PATH_ENV_DISABLE_DIRECT_PATH))) { | ||
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. This code is hard to follow due to the double negative. Probably better broken up into 3 separate statements. 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 |
||
return false; | ||
} | ||
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; | ||
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. all ifs are multiline, per google style 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 |
||
for (String service : whiteList.split(",")) { | ||
if (!service.isEmpty() && serviceAddress.contains(service)) return true; | ||
} | ||
return false; | ||
} | ||
|
||
|
@@ -304,7 +313,7 @@ private ManagedChannel createSingleChannel() throws IOException, GeneralSecurity | |
ManagedChannelBuilder<?> builder; | ||
|
||
// TODO(weiranf): Add API in ComputeEngineCredentials to check default service account. | ||
if (isDirectPathEnabled() | ||
if (isDirectPathEnabled(serviceAddress) | ||
&& credentials instanceof ComputeEngineCredentials | ||
&& isOnComputeEngine()) { | ||
builder = ComputeEngineChannelBuilder.forAddress(serviceAddress, port); | ||
|
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.
private
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.
The new ones should be private, I agree, but for the old ones, I guess it will technically make it a breaknig change
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.
I made the new one private, and keep the old one as what it is (i.e., without adding private).