Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Create new environment variable to toggle directpath scoped to cloud bigtable. #2261

Merged
merged 7 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions google-cloud-bigtable/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@
<bigtable.grpc-log-dir>${project.build.directory}/test-grpc-logs/directpath-it</bigtable.grpc-log-dir>
<bigtable.connection-mode>REQUIRE_DIRECT_PATH</bigtable.connection-mode>
</systemPropertyVariables>
<environmentVariables>
<CBT_ENABLE_DIRECTPATH>true</CBT_ENABLE_DIRECTPATH>
</environmentVariables>
meeral-k marked this conversation as resolved.
Show resolved Hide resolved
<includes>
<!-- TODO(igorbernstein): Once the control plane is accessible via directpath, add admin tests -->
<include>com.google.cloud.bigtable.data.v2.it.*IT</include>
Expand Down Expand Up @@ -575,6 +578,9 @@
<bigtable.grpc-log-dir>${project.build.directory}/test-grpc-logs/directpath-ipv4only-it</bigtable.grpc-log-dir>
<bigtable.connection-mode>REQUIRE_DIRECT_PATH_IPV4</bigtable.connection-mode>
</systemPropertyVariables>
<environmentVariables>
<CBT_ENABLE_DIRECTPATH>true</CBT_ENABLE_DIRECTPATH>
</environmentVariables>
<includes>
<!-- TODO(igorbernstein): Once the control plane is accessible via directpath, add admin tests -->
<include>com.google.cloud.bigtable.data.v2.it.*IT</include>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public class EnhancedBigtableStubSettings extends StubSettings<EnhancedBigtableS
private static final int MAX_MESSAGE_SIZE = 256 * 1024 * 1024;
private static final String SERVER_DEFAULT_APP_PROFILE_ID = "";

// TODO(meeral-k): add documentation
private static final String CBT_ENABLE_DIRECTPATH = "CBT_ENABLE_DIRECTPATH";
meeral-k marked this conversation as resolved.
Show resolved Hide resolved
private static final Set<Code> IDEMPOTENT_RETRY_CODES =
ImmutableSet.of(Code.DEADLINE_EXCEEDED, Code.UNAVAILABLE);

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -205,10 +202,6 @@ private void configureConnection(StubSettings.Builder stubSettings) {
final ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder> oldConfigurator =
channelProvider.getChannelConfigurator();

if (enableDirectPath) {
channelProvider.setAttemptDirectPath(true).setAttemptDirectPathXds();
}

@SuppressWarnings("rawtypes")
final ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder> newConfigurator =
new ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder>() {
Expand Down
Loading