|
80 | 80 | @InternalExtensionOnly
|
81 | 81 | public final class InstantiatingGrpcChannelProvider implements TransportChannelProvider {
|
82 | 82 | 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"; |
83 | 85 | static final long DIRECT_PATH_KEEP_ALIVE_TIME_SECONDS = 3600;
|
84 | 86 | static final long DIRECT_PATH_KEEP_ALIVE_TIMEOUT_SECONDS = 20;
|
85 | 87 | // 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 {
|
243 | 245 | return GrpcTransportChannel.create(outerChannel);
|
244 | 246 | }
|
245 | 247 |
|
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 |
247 | 249 | // and the env var is removed from client environment.
|
248 | 250 | 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. |
249 | 257 | if (attemptDirectPath != null) {
|
250 | 258 | return attemptDirectPath;
|
251 | 259 | }
|
252 | 260 | // Only check DIRECT_PATH_ENV_VAR when attemptDirectPath is not set.
|
253 | 261 | String whiteList = envProvider.getenv(DIRECT_PATH_ENV_VAR);
|
254 |
| - if (whiteList == null) return false; |
| 262 | + if (whiteList == null) { |
| 263 | + return false; |
| 264 | + } |
255 | 265 | 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 | + } |
257 | 269 | }
|
258 | 270 | return false;
|
259 | 271 | }
|
|
0 commit comments