Skip to content

Commit 009d91d

Browse files
authored
feat(GCS+gRPC): option to configure plugin (#6991)
Make it easier to experiment with configuration options for the GCS+gRPC plugin. This is useful in benchmarking, and might be useful in the final form of the plugin.
1 parent 15a0d47 commit 009d91d

8 files changed

Lines changed: 70 additions & 32 deletions

google/cloud/storage/benchmarks/aggregate_throughput_benchmark.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,10 @@ int main(int argc, char* argv[]) {
142142
auto channels = options->grpc_channel_count;
143143
if (channels == 0) channels = (std::max)(options->thread_count / 4, 4);
144144
client = DefaultGrpcClient(
145-
google::cloud::Options{}.set<google::cloud::GrpcNumChannelsOption>(
146-
channels));
145+
google::cloud::Options{}
146+
.set<google::cloud::GrpcNumChannelsOption>(channels)
147+
.set<google::cloud::storage_experimental::GrpcPluginOption>(
148+
options->grpc_plugin_config));
147149
}
148150
#endif // GOOGLE_CLOUD_CPP_STORAGE_HAVE_GRPC
149151
std::vector<gcs::ObjectMetadata> objects;

google/cloud/storage/benchmarks/aggregate_throughput_options.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ ParseAggregateThroughputOptions(std::vector<std::string> const& argv,
6868
[&options](std::string const& val) {
6969
options.grpc_channel_count = std::stoi(val);
7070
}},
71+
{"--grpc-plugin-config",
72+
"low-level experimental settings for the GCS+gRPC plugin",
73+
[&options](std::string const& val) {
74+
options.grpc_plugin_config = val;
75+
}},
7176
};
7277
auto usage = BuildUsage(desc, argv[0]);
7378

google/cloud/storage/benchmarks/aggregate_throughput_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct AggregateThroughputOptions {
3434
std::size_t read_buffer_size = 4 * kMiB;
3535
ApiName api = ApiName::kApiGrpc;
3636
int grpc_channel_count = 0;
37+
std::string grpc_plugin_config;
3738
bool exit_after_parse = false;
3839
};
3940

google/cloud/storage/benchmarks/aggregate_throughput_options_test.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ TEST(AggregateThroughputOptions, Basic) {
3535
"--read-buffer-size=1MiB",
3636
"--api=XML",
3737
"--grpc-channel-count=16",
38+
"--grpc-plugin-config=default",
3839
},
3940
"");
4041
ASSERT_STATUS_OK(options);

google/cloud/storage/grpc_plugin.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,32 @@ namespace cloud {
3030
namespace storage_experimental {
3131
inline namespace STORAGE_CLIENT_NS {
3232

33+
/**
34+
* Low-level experimental settings for the GCS+gRPC plugin.
35+
*
36+
* Possible values for the string include:
37+
*
38+
* - "default" or "none": do not use any special settings with gRPC.
39+
* - "dp": enable Google Direct Access (formerly 'Direct Path') equivalent to
40+
* setting both "pick-first-lb" and "enable-dns-srv-queries".
41+
* - "alts": same settings as "dp", but use the experimental ALTS credentials.
42+
* - "enable-dns-srv-queries": set the `grpc.dns_enable_srv_queries` channel
43+
* argument to `1`, see [dns-query-arg].
44+
* - "disable-dns-srv-queries": set the `grpc.dns_enable_srv_queries` channel
45+
* argument to `0`, see [dns-query-arg].
46+
* - "pick-first-lb": configure the gRPC load balancer to use the "pick_first"
47+
* policy.
48+
* - "exclusive": use an exclusive channel for each stub.
49+
*
50+
* Unknown values are ignored.
51+
*
52+
* [dns-query-arg]:
53+
* https://grpc.github.io/grpc/core/group__grpc__arg__keys.html#ga247ed6771077938be12ab24790a95732
54+
*/
55+
struct GrpcPluginOption {
56+
using Type = std::string;
57+
};
58+
3359
/**
3460
* Create a `google::cloud::storage::Client` object configured to use gRPC.
3561
*

google/cloud/storage/internal/grpc_client.cc

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "google/cloud/storage/internal/grpc_client.h"
16+
#include "google/cloud/storage/grpc_plugin.h"
1617
#include "google/cloud/storage/internal/grpc_object_read_source.h"
1718
#include "google/cloud/storage/internal/grpc_resumable_upload_session.h"
1819
#include "google/cloud/storage/internal/openssl_util.h"
@@ -56,14 +57,6 @@ auto constexpr kDirectPathConfig = R"json({
5657
}]
5758
})json";
5859

59-
bool DirectPathEnabled() {
60-
auto const direct_path_settings =
61-
google::cloud::internal::GetEnv("GOOGLE_CLOUD_ENABLE_DIRECT_PATH")
62-
.value_or("");
63-
return absl::c_any_of(absl::StrSplit(direct_path_settings, ','),
64-
[](absl::string_view v) { return v == "storage"; });
65-
}
66-
6760
int DefaultGrpcNumChannels() {
6861
auto constexpr kMinimumChannels = 4;
6962
auto const count = std::thread::hardware_concurrency();
@@ -94,10 +87,35 @@ Options DefaultOptionsGrpc(Options options) {
9487
std::shared_ptr<grpc::Channel> CreateGrpcChannel(
9588
GrpcAuthenticationStrategy& auth, Options const& options, int channel_id) {
9689
grpc::ChannelArguments args;
97-
args.SetInt("grpc.channel_id", channel_id);
98-
if (DirectPathEnabled()) {
90+
auto const& config = options.get<storage_experimental::GrpcPluginOption>();
91+
if (config.empty() || config == "default" || config == "none") {
92+
// Just configure for the regular path.
93+
args.SetInt("grpc.channel_id", channel_id);
94+
return auth.CreateChannel(options.get<EndpointOption>(), std::move(args));
95+
}
96+
std::set<absl::string_view> settings = absl::StrSplit(config, ',');
97+
auto const dp = settings.count("dp") != 0 || settings.count("alts") != 0;
98+
if (dp || settings.count("pick-first-lb") != 0) {
9999
args.SetServiceConfigJSON(kDirectPathConfig);
100100
}
101+
if (dp || settings.count("enable-dns-srv-queries") != 0) {
102+
args.SetInt("grpc.dns_enable_srv_queries", 1);
103+
}
104+
if (settings.count("disable-dns-srv-queries") != 0) {
105+
args.SetInt("grpc.dns_enable_srv_queries", 0);
106+
}
107+
if (settings.count("exclusive") != 0) {
108+
args.SetInt("grpc.channel_id", channel_id);
109+
}
110+
if (settings.count("alts") != 0) {
111+
grpc::experimental::AltsCredentialsOptions alts_opts;
112+
return grpc::CreateCustomChannel(
113+
options.get<EndpointOption>(),
114+
grpc::CompositeChannelCredentials(
115+
grpc::experimental::AltsCredentials(alts_opts),
116+
grpc::GoogleComputeEngineCredentials()),
117+
std::move(args));
118+
}
101119
return auth.CreateChannel(options.get<EndpointOption>(), std::move(args));
102120
}
103121

google/cloud/storage/internal/grpc_client.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ namespace storage {
2929
inline namespace STORAGE_CLIENT_NS {
3030
namespace internal {
3131

32-
/// Determine if using DirectPath for GCS has been enabled through
33-
/// GOOGLE_CLOUD_DIRECT_PATH.
34-
bool DirectPathEnabled();
32+
/**
33+
* The default options for gRPC.
34+
*
35+
* This adds some additional defaults to the options for REST.
36+
*/
3537
Options DefaultOptionsGrpc(Options = {});
3638

3739
class StorageStub;

google/cloud/storage/internal/grpc_client_test.cc

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "google/cloud/storage/internal/object_access_control_parser.h"
1818
#include "google/cloud/storage/internal/object_metadata_parser.h"
1919
#include "google/cloud/testing_util/is_proto_equal.h"
20-
#include "google/cloud/testing_util/scoped_environment.h"
2120
#include "google/cloud/testing_util/status_matchers.h"
2221
#include <google/protobuf/text_format.h>
2322
#include <gmock/gmock.h>
@@ -31,22 +30,6 @@ namespace {
3130

3231
namespace storage_proto = ::google::storage::v1;
3332
using ::google::cloud::testing_util::IsProtoEqual;
34-
using ::google::cloud::testing_util::ScopedEnvironment;
35-
36-
TEST(GrpcClientDirectPath, NotSet) {
37-
ScopedEnvironment env("GOOGLE_CLOUD_ENABLE_DIRECT_PATH", {});
38-
EXPECT_FALSE(DirectPathEnabled());
39-
}
40-
41-
TEST(GrpcClientDirectPath, Enabled) {
42-
ScopedEnvironment env("GOOGLE_CLOUD_ENABLE_DIRECT_PATH", "foo,storage,bar");
43-
EXPECT_TRUE(DirectPathEnabled());
44-
}
45-
46-
TEST(GrpcClientDirectPath, NotEnabled) {
47-
ScopedEnvironment env("GOOGLE_CLOUD_ENABLE_DIRECT_PATH", "not-quite-storage");
48-
EXPECT_FALSE(DirectPathEnabled());
49-
}
5033

5134
TEST(GrpcClientFromProto, ObjectSimple) {
5235
storage_proto::Object input;

0 commit comments

Comments
 (0)