diff --git a/google-cloud-bigtable/pom.xml b/google-cloud-bigtable/pom.xml index 08b8135714..1a9d1ab4e4 100644 --- a/google-cloud-bigtable/pom.xml +++ b/google-cloud-bigtable/pom.xml @@ -499,6 +499,9 @@ ${project.build.directory}/test-grpc-logs/directpath-it REQUIRE_DIRECT_PATH + + true + com.google.cloud.bigtable.data.v2.it.*IT @@ -575,6 +578,9 @@ ${project.build.directory}/test-grpc-logs/directpath-ipv4only-it REQUIRE_DIRECT_PATH_IPV4 + + true + com.google.cloud.bigtable.data.v2.it.*IT diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java index 9535f1d1ae..5a9e03cf10 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java @@ -100,6 +100,8 @@ public class EnhancedBigtableStubSettings extends StubSettings IDEMPOTENT_RETRY_CODES = ImmutableSet.of(Code.DEADLINE_EXCEEDED, Code.UNAVAILABLE); @@ -345,7 +347,15 @@ public boolean getEnableRetryInfo() { /** Returns a builder for the default ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { - return BigtableStubSettings.defaultGrpcTransportProviderBuilder() + Boolean isDirectpathEnabled = Boolean.parseBoolean(System.getenv(CBT_ENABLE_DIRECTPATH)); + InstantiatingGrpcChannelProvider.Builder grpcTransportProviderBuilder = + BigtableStubSettings.defaultGrpcTransportProviderBuilder(); + if (isDirectpathEnabled) { + // Attempts direct access to CBT service over gRPC to improve throughput, + // whether the attempt is allowed is totally controlled by service owner. + grpcTransportProviderBuilder.setAttemptDirectPathXds().setAttemptDirectPath(true); + } + return grpcTransportProviderBuilder .setChannelPoolSettings( ChannelPoolSettings.builder() .setInitialChannelCount(10) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env/CloudEnv.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env/CloudEnv.java index d10fd5ea5d..d7b9523b83 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env/CloudEnv.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env/CloudEnv.java @@ -168,21 +168,18 @@ private static void injectTracingCookie( private void configureConnection(StubSettings.Builder stubSettings) { // Build an remote address restricting interceptor final ClientInterceptor interceptor; - boolean enableDirectPath = false; switch (getConnectionMode()) { case DEFAULT: // nothing special return; case REQUIRE_DIRECT_PATH: - enableDirectPath = true; interceptor = buildRemoteAddrInterceptor( "DirectPath IPv4 or IPv6", Predicates.or(DIRECT_PATH_IPV4_MATCHER, DIRECT_PATH_IPV6_MATCHER)); break; case REQUIRE_DIRECT_PATH_IPV4: - enableDirectPath = true; interceptor = buildRemoteAddrInterceptor("DirectPath IPv4", Predicates.or(DIRECT_PATH_IPV4_MATCHER)); break; @@ -205,10 +202,6 @@ private void configureConnection(StubSettings.Builder stubSettings) { final ApiFunction oldConfigurator = channelProvider.getChannelConfigurator(); - if (enableDirectPath) { - channelProvider.setAttemptDirectPath(true).setAttemptDirectPathXds(); - } - @SuppressWarnings("rawtypes") final ApiFunction newConfigurator = new ApiFunction() {