Skip to content

Commit 992d59d

Browse files
authored
impl(GCS+gRPC): new options for gRPC metrics (#14094)
1 parent 7c0c6dc commit 992d59d

File tree

4 files changed

+75
-2
lines changed

4 files changed

+75
-2
lines changed

google/cloud/storage/grpc_plugin.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,44 @@ struct [[deprecated(
6060
*/
6161
google::cloud::storage::Client DefaultGrpcClient(Options opts = {});
6262

63+
/**
64+
* Enable gRPC telemetry for GCS RPCs.
65+
*
66+
* Troubleshooting problems with GCS over gRPC is difficult without some
67+
* telemetry indicating how the client is configured, and what load balancing
68+
* information was available to the gRPC library.
69+
*
70+
* When this option is enabled (the default), the GCS client will export the
71+
* gRPC telemetry discussed in [gRFC/66] and [gRFC/78] to
72+
* [Google Cloud Monitoring]. Google Cloud Support can use this information to
73+
* more quickly diagnose problems related to GCS and gRPC.
74+
*
75+
* Sending this data does not incur any billing charges, and requires minimal
76+
* CPU (a single RPC every few minutes) or memory (a few KiB to batch the
77+
* telemetry).
78+
*
79+
* [gRFC/66]: https://github.com/grpc/proposal/blob/master/A66-otel-stats.md
80+
* [gRFC/78]:
81+
* https://github.com/grpc/proposal/blob/master/A78-grpc-metrics-wrr-pf-xds.md
82+
* [Google Cloud Monitoring]: https://cloud.google.com/monitoring/docs
83+
*/
84+
struct EnableGrpcMetrics {
85+
using Type = bool;
86+
};
87+
88+
/**
89+
* gRPC telemetry export period.
90+
*
91+
* When `EnableGrpcMetrics` is enabled, this option controls the frequency at
92+
* which metrics are exported to [Google Cloud Monitoring]. The default is 60
93+
* seconds. Values below 60 seconds are ignored.
94+
*
95+
* [Google Cloud Monitoring]: https://cloud.google.com/monitoring/docs
96+
*/
97+
struct GrpcMetricsPeriod {
98+
using Type = std::chrono::seconds;
99+
};
100+
63101
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
64102
} // namespace storage_experimental
65103
} // namespace cloud

google/cloud/storage/internal/async/default_options.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "google/cloud/storage/async/resume_policy.h"
1919
#include "google/cloud/storage/async/writer_connection.h"
2020
#include "google/cloud/storage/internal/grpc/default_options.h"
21-
#include "google/cloud/storage/internal/grpc/stub.h"
2221
#include <limits>
2322

2423
namespace google {

google/cloud/storage/internal/grpc/default_options.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ namespace storage_internal {
3131
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
3232
namespace {
3333

34+
auto constexpr kMinMetricsPeriod = std::chrono::seconds(5);
35+
auto constexpr kDefaultMetricsPeriod = std::chrono::seconds(60);
36+
3437
int DefaultGrpcNumChannels(std::string const& endpoint) {
3538
// When using DirectPath the gRPC library already does load balancing across
3639
// multiple sockets, it makes little sense to perform additional load
@@ -81,7 +84,15 @@ Options DefaultOptionsGrpc(Options options) {
8184
"storage.googleapis.com", options);
8285
options = google::cloud::internal::MergeOptions(
8386
std::move(options),
84-
Options{}.set<EndpointOption>(ep).set<AuthorityOption>(ep));
87+
Options{}
88+
.set<EndpointOption>(ep)
89+
.set<AuthorityOption>(ep)
90+
.set<storage_experimental::EnableGrpcMetrics>(true)
91+
.set<storage_experimental::GrpcMetricsPeriod>(kDefaultMetricsPeriod));
92+
if (options.get<storage_experimental::GrpcMetricsPeriod>() <
93+
kMinMetricsPeriod) {
94+
options.set<storage_experimental::GrpcMetricsPeriod>(kMinMetricsPeriod);
95+
}
8596
// We can only compute this once the endpoint is known, so take an additional
8697
// step.
8798
auto const num_channels =

google/cloud/storage/internal/grpc/default_options_test.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,31 @@ TEST(DefaultOptionsGrpc, DefaultOptionsUploadBuffer) {
120120
EXPECT_EQ(with_override, 256 * 1024L);
121121
}
122122

123+
TEST(DefaultOptionsGrpc, MetricsEnabled) {
124+
auto const options = DefaultOptionsGrpc(Options{});
125+
EXPECT_TRUE(options.get<storage_experimental::EnableGrpcMetrics>());
126+
}
127+
128+
TEST(DefaultOptionsGrpc, MetricsPeriod) {
129+
auto const options = DefaultOptionsGrpc(Options{});
130+
EXPECT_GE(options.get<storage_experimental::GrpcMetricsPeriod>(),
131+
std::chrono::seconds(60));
132+
}
133+
134+
TEST(DefaultOptionsGrpc, MinMetricsPeriod) {
135+
auto const o0 =
136+
DefaultOptionsGrpc(Options{}.set<storage_experimental::GrpcMetricsPeriod>(
137+
std::chrono::seconds(0)));
138+
EXPECT_GT(o0.get<storage_experimental::GrpcMetricsPeriod>(),
139+
std::chrono::seconds(0));
140+
141+
auto const m5 =
142+
DefaultOptionsGrpc(Options{}.set<storage_experimental::GrpcMetricsPeriod>(
143+
std::chrono::seconds(-5)));
144+
EXPECT_GT(m5.get<storage_experimental::GrpcMetricsPeriod>(),
145+
std::chrono::seconds(0));
146+
}
147+
123148
} // namespace
124149
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
125150
} // namespace storage_internal

0 commit comments

Comments
 (0)