Skip to content

Commit 2dd5105

Browse files
feat: Add Experimental DirectPath support (#8)
* Add Experimental DirectPath support * finish removing DirectPathEnv * format * remove sys prop check, this will be enabled in the next version of grpc * english
1 parent 746cebb commit 2dd5105

File tree

6 files changed

+46
-202
lines changed

6 files changed

+46
-202
lines changed

google-cloud-bigtable/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@
257257
</goals>
258258
<configuration>
259259
<systemPropertyVariables>
260-
<bigtable.env>direct_path</bigtable.env>
260+
<bigtable.env>prod</bigtable.env>
261261
<!-- TODO(igorbernstein): This property should be auto set by gax -->
262262
<io.grpc.internal.DnsNameResolverProvider.enable_grpclb>true</io.grpc.internal.DnsNameResolverProvider.enable_grpclb>
263263
</systemPropertyVariables>

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

+39-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.google.common.collect.ImmutableSet;
4343
import java.util.List;
4444
import java.util.Set;
45+
import java.util.logging.Logger;
4546
import javax.annotation.Nonnull;
4647
import org.threeten.bp.Duration;
4748

@@ -74,10 +75,18 @@
7475
* }</pre>
7576
*/
7677
public class EnhancedBigtableStubSettings extends StubSettings<EnhancedBigtableStubSettings> {
78+
private static final Logger logger =
79+
Logger.getLogger(EnhancedBigtableStubSettings.class.getName());
80+
7781
// The largest message that can be received is a 256 MB ReadRowsResponse.
7882
private static final int MAX_MESSAGE_SIZE = 256 * 1024 * 1024;
7983
private static final String SERVER_DEFAULT_APP_PROFILE_ID = "";
8084

85+
// TODO(igorbernstein2): Remove this once DirectPath goes to public beta
86+
// Temporary endpoint for the DirectPath private alpha
87+
private static final String DIRECT_PATH_ENV_VAR = "GOOGLE_CLOUD_ENABLE_DIRECT_PATH";
88+
private static final String DIRECT_PATH_ENDPOINT = "directpath-bigtable.googleapis.com:443";
89+
8190
private static final Set<Code> IDEMPOTENT_RETRY_CODES =
8291
ImmutableSet.of(Code.DEADLINE_EXCEEDED, Code.UNAVAILABLE);
8392

@@ -133,6 +142,12 @@ public class EnhancedBigtableStubSettings extends StubSettings<EnhancedBigtableS
133142
private EnhancedBigtableStubSettings(Builder builder) {
134143
super(builder);
135144

145+
if (DIRECT_PATH_ENDPOINT.equals(builder.getEndpoint())) {
146+
logger.warning(
147+
"Connecting to Bigtable using DirectPath."
148+
+ " This is currently an experimental feature and should not be used in production.");
149+
}
150+
136151
// Since point reads & streaming reads share the same base callable that converts grpc errors
137152
// into ApiExceptions, they must have the same retry codes.
138153
Preconditions.checkState(
@@ -404,7 +419,14 @@ private Builder() {
404419
// Defaults provider
405420
BigtableStubSettings.Builder baseDefaults = BigtableStubSettings.newBuilder();
406421

407-
setEndpoint(baseDefaults.getEndpoint());
422+
// TODO(igorbernstein): remove this once DirectPath goes to public Beta and uses the default
423+
// endpoint.
424+
if (isDirectPathEnabled()) {
425+
setEndpoint(DIRECT_PATH_ENDPOINT);
426+
} else {
427+
setEndpoint(baseDefaults.getEndpoint());
428+
}
429+
408430
setTransportChannelProvider(defaultTransportChannelProvider());
409431
setStreamWatchdogCheckInterval(baseDefaults.getStreamWatchdogCheckInterval());
410432
setStreamWatchdogProvider(baseDefaults.getStreamWatchdogProvider());
@@ -503,6 +525,22 @@ private static void copyRetrySettings(
503525
dest.setRetryableCodes(source.getRetryableCodes());
504526
dest.setRetrySettings(source.getRetrySettings());
505527
}
528+
529+
// TODO(igorbernstein): Remove this once DirectPath goes to public beta
530+
// Extracted from InstantiatingGrpcChannelProvider#isDirectPathEnabled
531+
private static boolean isDirectPathEnabled() {
532+
String whiteList = System.getenv(DIRECT_PATH_ENV_VAR);
533+
if (whiteList == null) {
534+
return false;
535+
}
536+
537+
for (String service : whiteList.split(",")) {
538+
if (!service.isEmpty() && DIRECT_PATH_ENDPOINT.contains(service)) {
539+
return true;
540+
}
541+
}
542+
return false;
543+
}
506544
// </editor-fold>
507545

508546
// <editor-fold desc="Public API">

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/DirectPathFallbackIT.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
2424
import com.google.cloud.bigtable.data.v2.BigtableDataClient;
2525
import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
26-
import com.google.cloud.bigtable.test_helpers.env.DirectPathEnv;
2726
import com.google.cloud.bigtable.test_helpers.env.TestEnvRule;
2827
import io.grpc.ManagedChannelBuilder;
2928
import io.grpc.alts.ComputeEngineChannelBuilder;
@@ -82,8 +81,8 @@ public DirectPathFallbackIT() {
8281
public void setup() throws IOException {
8382
assume()
8483
.withMessage("DirectPath integration tests can only run against DirectPathEnv")
85-
.that(testEnvRule.env())
86-
.isInstanceOf(DirectPathEnv.class);
84+
.that(testEnvRule.env().isDirectPathEnabled())
85+
.isTrue();
8786

8887
BigtableDataSettings defaultSettings = testEnvRule.env().getDataClientSettings();
8988
InstantiatingGrpcChannelProvider defaultTransportProvider =

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

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ public boolean isInstanceAdminSupported() {
7474
return true;
7575
}
7676

77+
public boolean isDirectPathEnabled() {
78+
return "bigtable".equals(System.getenv("GOOGLE_CLOUD_ENABLE_DIRECT_PATH"));
79+
}
80+
7781
void cleanUpStale() {
7882
cleanupStaleTables();
7983
if (isInstanceAdminSupported()) {

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

-194
This file was deleted.

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

-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ protected void before() throws Throwable {
6363
case "prod":
6464
testEnv = ProdEnv.fromSystemProperties();
6565
break;
66-
case "direct_path":
67-
testEnv = DirectPathEnv.create();
68-
break;
6966
default:
7067
throw new IllegalArgumentException(
7168
String.format(

0 commit comments

Comments
 (0)