Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
42 changes: 31 additions & 11 deletions google/cloud/bigtable/internal/bigtable_stub_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "google/cloud/internal/algorithm.h"
#include "google/cloud/internal/api_client_header.h"
#include "google/cloud/internal/base64_transforms.h"
#include "google/cloud/internal/getenv.h"
#include "google/cloud/internal/opentelemetry.h"
#include "google/cloud/internal/unified_grpc_credentials.h"
#include "google/cloud/log.h"
Expand All @@ -47,17 +48,36 @@ std::shared_ptr<grpc::Channel> CreateGrpcChannel(
}

std::string FeaturesMetadata() {
static auto const* const kFeatures = new auto([] {
google::bigtable::v2::FeatureFlags proto;
proto.set_reverse_scans(true);
proto.set_last_scanned_row_responses(true);
proto.set_mutate_rows_rate_limit(true);
proto.set_mutate_rows_rate_limit2(true);
proto.set_routing_cookie(true);
proto.set_retry_info(true);
return internal::UrlsafeBase64Encode(proto.SerializeAsString());
}());
return *kFeatures;
auto const env = google::cloud::internal::GetEnv("CBT_ENABLE_DIRECTPATH");
bool const directpath_enabled =
env.has_value() && (*env == "true" || *env == "1");
Comment thread
hanshu-G marked this conversation as resolved.
Outdated
if (directpath_enabled) {
static auto const* const kFeaturesDirectPath = new auto([] {
google::bigtable::v2::FeatureFlags proto;
proto.set_reverse_scans(true);
proto.set_last_scanned_row_responses(true);
proto.set_mutate_rows_rate_limit(true);
proto.set_mutate_rows_rate_limit2(true);
proto.set_routing_cookie(true);
proto.set_retry_info(true);
proto.set_traffic_director_enabled(true);
proto.set_direct_access_requested(true);
return internal::UrlsafeBase64Encode(proto.SerializeAsString());
}());
return *kFeaturesDirectPath;
} else {
static auto const* const kFeaturesDefault = new auto([] {
google::bigtable::v2::FeatureFlags proto;
proto.set_reverse_scans(true);
proto.set_last_scanned_row_responses(true);
proto.set_mutate_rows_rate_limit(true);
proto.set_mutate_rows_rate_limit2(true);
proto.set_routing_cookie(true);
proto.set_retry_info(true);
return internal::UrlsafeBase64Encode(proto.SerializeAsString());
}());
return *kFeaturesDefault;
}
}
Comment thread
hanshu-G marked this conversation as resolved.

} // namespace
Expand Down
12 changes: 4 additions & 8 deletions google/cloud/bigtable/internal/defaults.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,14 @@ Options DefaultOptions(Options opts) {
}
}

auto const direct_path =
GetEnv("GOOGLE_CLOUD_ENABLE_DIRECT_PATH").value_or("");
if (absl::c_any_of(absl::StrSplit(direct_path, ','),
[](absl::string_view v) { return v == "bigtable"; })) {
opts.set<DataEndpointOption>(
"google-c2p:///directpath-bigtable.googleapis.com")
.set<AuthorityOption>("directpath-bigtable.googleapis.com");
auto const direct_path = GetEnv("CBT_ENABLE_DIRECTPATH");
Comment thread
hanshu-G marked this conversation as resolved.
Outdated
if (direct_path.has_value() &&
(*direct_path == "true" || *direct_path == "1")) {
opts.set<DataEndpointOption>("c2p://bigtable.googleapis.com");

// When using DirectPath the gRPC library already does load balancing across
// multiple sockets, it makes little sense to perform additional load
// balancing in the client library.
Comment thread
hanshu-G marked this conversation as resolved.
Outdated
if (!opts.has<GrpcNumChannelsOption>()) opts.set<GrpcNumChannelsOption>(1);
}

auto emulator = GetEnv("BIGTABLE_EMULATOR_HOST");
Expand Down
22 changes: 9 additions & 13 deletions google/cloud/bigtable/internal/defaults_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -426,24 +426,21 @@ TEST(EndpointEnvTest, UserCredentialsOverrideEmulatorEnv) {

TEST(EndpointEnvTest, DirectPathEnabled) {
ScopedEnvironment emulator("BIGTABLE_EMULATOR_HOST", absl::nullopt);
ScopedEnvironment direct_path("GOOGLE_CLOUD_ENABLE_DIRECT_PATH",
"storage,bigtable");
ScopedEnvironment direct_path("CBT_ENABLE_DIRECTPATH", "true");

auto opts = DefaultOptions();
EXPECT_EQ("google-c2p:///directpath-bigtable.googleapis.com",
opts.get<DataEndpointOption>());
EXPECT_EQ("directpath-bigtable.googleapis.com", opts.get<AuthorityOption>());
EXPECT_EQ("c2p://bigtable.googleapis.com", opts.get<DataEndpointOption>());
EXPECT_EQ("bigtable.googleapis.com", opts.get<AuthorityOption>());
// Admin endpoints are not affected.
EXPECT_EQ("bigtableadmin.googleapis.com", opts.get<AdminEndpointOption>());
EXPECT_EQ("bigtableadmin.googleapis.com",
opts.get<InstanceAdminEndpointOption>());
EXPECT_EQ(1, opts.get<GrpcNumChannelsOption>());
Comment thread
hanshu-G marked this conversation as resolved.
Outdated
}

TEST(EndpointEnvTest, DirectPathNoMatch) {
TEST(EndpointEnvTest, DirectPathNotEnabled) {
ScopedEnvironment emulator("BIGTABLE_EMULATOR_HOST", absl::nullopt);
ScopedEnvironment direct_path("GOOGLE_CLOUD_ENABLE_DIRECT_PATH",
"bigtable-not,almost-bigtable");
ScopedEnvironment direct_path("CBT_ENABLE_DIRECTPATH", "false");

auto opts = DefaultDataOptions(Options{});
EXPECT_EQ("bigtable.googleapis.com", opts.get<EndpointOption>());
Expand All @@ -452,18 +449,17 @@ TEST(EndpointEnvTest, DirectPathNoMatch) {

TEST(EndpointEnvTest, DirectPathOverridesUserEndpoints) {
ScopedEnvironment emulator("BIGTABLE_EMULATOR_HOST", absl::nullopt);
ScopedEnvironment direct_path("GOOGLE_CLOUD_ENABLE_DIRECT_PATH", "bigtable");
ScopedEnvironment direct_path("CBT_ENABLE_DIRECTPATH", "true");

auto opts = DefaultDataOptions(
Options{}.set<EndpointOption>("ignored").set<AuthorityOption>("ignored"));
EXPECT_EQ("google-c2p:///directpath-bigtable.googleapis.com",
opts.get<EndpointOption>());
EXPECT_EQ("directpath-bigtable.googleapis.com", opts.get<AuthorityOption>());
EXPECT_EQ("c2p://bigtable.googleapis.com", opts.get<EndpointOption>());
EXPECT_EQ("bigtable.googleapis.com", opts.get<AuthorityOption>());
}

TEST(EndpointEnvTest, EmulatorOverridesDirectPath) {
ScopedEnvironment emulator("BIGTABLE_EMULATOR_HOST", "emulator-host:8000");
ScopedEnvironment direct_path("GOOGLE_CLOUD_ENABLE_DIRECT_PATH", "bigtable");
ScopedEnvironment direct_path("CBT_ENABLE_DIRECTPATH", "true");

auto opts = DefaultDataOptions(Options{});
EXPECT_EQ("emulator-host:8000", opts.get<EndpointOption>());
Expand Down
Loading