Skip to content

Commit 9062944

Browse files
authored
feat: Create new environment variable to toggle directpath scoped to cloud bigtable. (#2261)
* mend * mend * address code comments * formatting fix * fixed pom to set environment variable and not a system property * tagged myself in todo,added environment variable to directpath ipv4 only profile
1 parent 38e3d7b commit 9062944

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

google-cloud-bigtable/pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,9 @@
499499
<bigtable.grpc-log-dir>${project.build.directory}/test-grpc-logs/directpath-it</bigtable.grpc-log-dir>
500500
<bigtable.connection-mode>REQUIRE_DIRECT_PATH</bigtable.connection-mode>
501501
</systemPropertyVariables>
502+
<environmentVariables>
503+
<CBT_ENABLE_DIRECTPATH>true</CBT_ENABLE_DIRECTPATH>
504+
</environmentVariables>
502505
<includes>
503506
<!-- TODO(igorbernstein): Once the control plane is accessible via directpath, add admin tests -->
504507
<include>com.google.cloud.bigtable.data.v2.it.*IT</include>
@@ -575,6 +578,9 @@
575578
<bigtable.grpc-log-dir>${project.build.directory}/test-grpc-logs/directpath-ipv4only-it</bigtable.grpc-log-dir>
576579
<bigtable.connection-mode>REQUIRE_DIRECT_PATH_IPV4</bigtable.connection-mode>
577580
</systemPropertyVariables>
581+
<environmentVariables>
582+
<CBT_ENABLE_DIRECTPATH>true</CBT_ENABLE_DIRECTPATH>
583+
</environmentVariables>
578584
<includes>
579585
<!-- TODO(igorbernstein): Once the control plane is accessible via directpath, add admin tests -->
580586
<include>com.google.cloud.bigtable.data.v2.it.*IT</include>

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ public class EnhancedBigtableStubSettings extends StubSettings<EnhancedBigtableS
100100
private static final int MAX_MESSAGE_SIZE = 256 * 1024 * 1024;
101101
private static final String SERVER_DEFAULT_APP_PROFILE_ID = "";
102102

103+
// TODO(meeral-k): add documentation
104+
private static final String CBT_ENABLE_DIRECTPATH = "CBT_ENABLE_DIRECTPATH";
103105
private static final Set<Code> IDEMPOTENT_RETRY_CODES =
104106
ImmutableSet.of(Code.DEADLINE_EXCEEDED, Code.UNAVAILABLE);
105107

@@ -345,7 +347,15 @@ public boolean getEnableRetryInfo() {
345347

346348
/** Returns a builder for the default ChannelProvider for this service. */
347349
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
348-
return BigtableStubSettings.defaultGrpcTransportProviderBuilder()
350+
Boolean isDirectpathEnabled = Boolean.parseBoolean(System.getenv(CBT_ENABLE_DIRECTPATH));
351+
InstantiatingGrpcChannelProvider.Builder grpcTransportProviderBuilder =
352+
BigtableStubSettings.defaultGrpcTransportProviderBuilder();
353+
if (isDirectpathEnabled) {
354+
// Attempts direct access to CBT service over gRPC to improve throughput,
355+
// whether the attempt is allowed is totally controlled by service owner.
356+
grpcTransportProviderBuilder.setAttemptDirectPathXds().setAttemptDirectPath(true);
357+
}
358+
return grpcTransportProviderBuilder
349359
.setChannelPoolSettings(
350360
ChannelPoolSettings.builder()
351361
.setInitialChannelCount(10)

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env/CloudEnv.java

-7
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,18 @@ private static void injectTracingCookie(
168168
private void configureConnection(StubSettings.Builder stubSettings) {
169169
// Build an remote address restricting interceptor
170170
final ClientInterceptor interceptor;
171-
boolean enableDirectPath = false;
172171

173172
switch (getConnectionMode()) {
174173
case DEFAULT:
175174
// nothing special
176175
return;
177176
case REQUIRE_DIRECT_PATH:
178-
enableDirectPath = true;
179177
interceptor =
180178
buildRemoteAddrInterceptor(
181179
"DirectPath IPv4 or IPv6",
182180
Predicates.or(DIRECT_PATH_IPV4_MATCHER, DIRECT_PATH_IPV6_MATCHER));
183181
break;
184182
case REQUIRE_DIRECT_PATH_IPV4:
185-
enableDirectPath = true;
186183
interceptor =
187184
buildRemoteAddrInterceptor("DirectPath IPv4", Predicates.or(DIRECT_PATH_IPV4_MATCHER));
188185
break;
@@ -205,10 +202,6 @@ private void configureConnection(StubSettings.Builder stubSettings) {
205202
final ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder> oldConfigurator =
206203
channelProvider.getChannelConfigurator();
207204

208-
if (enableDirectPath) {
209-
channelProvider.setAttemptDirectPath(true).setAttemptDirectPathXds();
210-
}
211-
212205
@SuppressWarnings("rawtypes")
213206
final ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder> newConfigurator =
214207
new ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder>() {

0 commit comments

Comments
 (0)