Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request maps standard and debug OpenTelemetry SDK instruments to Cloud Monitoring descriptor names under the storage.googleapis.com/client/ namespace, configures latency and size histogram views for these metrics, and adds corresponding unit tests. Feedback on the new tests recommends recording metrics once before the retry loop rather than inside it to avoid non-deterministic behavior and potential test flakiness.
| for (int i = 0; i != 50 && export_count.load() == 0; ++i) { | ||
| latency->Record(1.0, opentelemetry::context::Context{}); | ||
| size->Record(1024.0, opentelemetry::context::Context{}); | ||
| std::this_thread::sleep_for(kExportInterval); | ||
| } |
There was a problem hiding this comment.
Recording metrics inside the loop can lead to non-deterministic test behavior and potential flakiness. If the background export thread is slow to wake up, multiple records will be accumulated, resulting in a histogram with more than one sample. If the matchers ExpectedLatencyHistogram() or ExpectedSizeHistogram() assert a specific count or sum, the test will fail.
To make the test deterministic and robust, record the metrics exactly once before entering the loop, and then simply sleep/wait in the loop until the export completes.
latency->Record(1.0, opentelemetry::context::Context{});
size->Record(1024.0, opentelemetry::context::Context{});
for (int i = 0; i != 50 && export_count.load() == 0; ++i) {
std::this_thread::sleep_for(kExportInterval);
}There was a problem hiding this comment.
Moved Record() outside the wait loop so each histogram is recorded once before waiting for the export.
Replied by cpriti-o11y-agent
631feab to
7fdb367
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16638 +/- ##
==========================================
+ Coverage 92.73% 92.75% +0.01%
==========================================
Files 2271 2271
Lines 226963 227031 +68
==========================================
+ Hits 210476 210578 +102
+ Misses 16487 16453 -34 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
kalragauri
left a comment
There was a problem hiding this comment.
nit: this PR only adds internal formatter and view plumbing in storage_internal, and the instruments themselves are wired up in follow-up PRs. A feat(storage): prefix makes release/changes.sh list it in CHANGELOG.md as a user-visible feature before those instruments ship.
Consider using impl(storage): in the title and noting in the description that instrument recording lands in follow-up PRs.
| data) { | ||
| EXPECT_THAT( | ||
| data.scope_metric_data_, | ||
| Contains(WithMetricsData(AllOf( |
There was a problem hiding this comment.
This AllOf(...) runs on every non-empty Export(), while PeriodicExportingMetricReader starts its background collection as soon as MakeGrpcMeterProvider() attaches it. If a collection runs between latency->Record(...) and size->Record(...), that export contains only gcp.client.request.duration and fails this assertion.
Consider testing one instrument per provider like ValidateGrpcClientAttemptSize above, or recording matched instrument names across exports until all expected instruments arrive.
There was a problem hiding this comment.
Updated ValidateStorageClientHistograms to accumulate verified instrument names across exports until all expected instruments arrive with the right buckets, avoiding any race with periodic collection.
Replied by cpriti-o11y-agent
|
|
||
| auto provider = MakeGrpcMeterProvider(std::move(mock), TestReaderOptions()); | ||
| auto meter = provider->GetMeter(kStorageMeterName, version_string()); | ||
| auto latency = meter->CreateDoubleHistogram("gcp.client.request.duration", |
There was a problem hiding this comment.
ValidateStorageClientHistograms only records gcp.client.request.duration and gcp.storage.client.request.body.size, leaving the other nine latency instruments and gcp.storage.client.response.body.size unverified. A typo or misplaced entry in MakeGrpcMeterProvider() would silently fall back to default OpenTelemetry histogram buckets without failing a test.
Can we exercise every registered latency and size instrument name against ExpectedLatencyHistogram() and ExpectedSizeHistogram()?
There was a problem hiding this comment.
Updated ValidateStorageClientHistograms to record and verify every registered latency and size histogram instrument against ExpectedLatencyHistogram() and ExpectedSizeHistogram().
Replied by cpriti-o11y-agent
| std::replace(s.begin(), s.end(), '.', '_'); | ||
| return "storage.googleapis.com/client/" + std::move(s); | ||
| } | ||
| std::replace(s.begin(), s.end(), '.', '/'); |
There was a problem hiding this comment.
Moving std::replace(s.begin(), s.end(), '.', '/') below the kInternalMetricPrefix check changes how dotted internal metric names are formatted. internal/client/foo.bar now keeps a literal ., and internal.client.foo lands under customer-visible storage.googleapis.com/client/ instead of internal/client/.
Consider moving the kInternalMetricPrefix branch directly below this std::replace and adding a test case so internal-prefix handling stays unchanged.
There was a problem hiding this comment.
Good catch—moved the kInternalMetricPrefix check below std::replace and added test cases for dotted internal metric names.
Replied by cpriti-o11y-agent
| if (s == "gcp.client.request.duration") { | ||
| return "storage.googleapis.com/client/request_duration"; | ||
| } | ||
| constexpr std::string_view kStorageClientPrefix = "gcp.storage.client."; |
There was a problem hiding this comment.
nit: std::string_view is used here without a direct #include <string_view>, relying on a transitive include.
There was a problem hiding this comment.
Added #include <string_view>.
Replied by cpriti-o11y-agent
| // accidentally land in the internal namespace. | ||
| {"client/internal/client/duration", | ||
| "storage.googleapis.com/client/client/internal/client/duration"}, | ||
| // Standard and debug OTel SDK instruments map to their Cloud Monitoring |
There was a problem hiding this comment.
Now that these library-owned SDK instruments map to customer-visible storage.googleapis.com/client/, the comments on MetricNameFormatter (line 191) and kInternalMetricPrefix in metrics_exporter_options.h are stale. Both still say instruments created by this library go to internal/client/.
There was a problem hiding this comment.
Updated the comments on kInternalMetricPrefix and MetricNameFormatter to reflect that customer-visible SDK instruments map under storage.googleapis.com/client/.
Replied by cpriti-o11y-agent
| "gcp.client.request.duration", | ||
| "gcp.storage.client.ttfb", | ||
| "rpc.client.call.duration", | ||
| "http.client.request.duration", |
There was a problem hiding this comment.
"http.client.request.duration" measures HTTP/REST requests, while MakeGrpcMeterProvider() lives in storage_grpc and is only wired into gRPC clients with api="GRPC". Will a follow-up PR share this provider setup with a REST metrics exporter, or can this be omitted?
There was a problem hiding this comment.
Removed "http.client.request.duration" from MakeGrpcMeterProvider() for now; we'll register it when REST metrics are wired in a follow-up PR.
Replied by cpriti-o11y-agent
| AddLatencyHistogramView(*p, StorageMeterScope(), | ||
| MeterScope const storage_scope = StorageMeterScope(); | ||
| for (char const* name : { | ||
| "gcp.client.request.duration", |
There was a problem hiding this comment.
Consider defining shared constexpr std::string_view constants (like ChannelCreationLatencyInstrument() below.
There was a problem hiding this comment.
Defined shared constexpr std::string_view instrument name constants in metrics_meter_provider.h so view registration and tests stay in sync.
Replied by cpriti-o11y-agent
|
Updated the PR title to Replied by cpriti-o11y-agent |
…ram views Update `MetricNameFormatterOption` in `MetricsExporterOptions()` to map standard and debug OpenTelemetry SDK instrument names (`gcp.client.request.duration` and `gcp.storage.client.*`) to their Cloud Monitoring target descriptors under `storage.googleapis.com/client/`. Also register explicit latency (`s`) and size (`By`) histogram views for the Storage client instruments under the `gl-cpp` meter scope in `MakeGrpcMeterProvider()`. [Generated-by: AI]
ddf6352 to
91e3430
Compare
|
|
||
| /// Storage SDK latency histogram instruments registered with explicit buckets. | ||
| inline constexpr std::array<std::string_view, 9> | ||
| kStorageLatencyHistogramInstruments = {{ |
There was a problem hiding this comment.
nit: since ValidateStorageClientHistograms now iterates kStorageLatencyHistogramInstruments too, a misspelled name here would pass the test and only show up as default buckets once the real instrument is created.
Will the follow-up PRs create instruments from named constants that these arrays are built from, rather than repeating the string literals?
There was a problem hiding this comment.
Yes—we'll share named constants between the instrument recorders and these view arrays in the follow-up wiring PRs so the names stay in sync.
Replied by cpriti-o11y-agent
| std::this_thread::sleep_for(kExportInterval); | ||
| } | ||
| std::lock_guard<std::mutex> lk(mu); | ||
| EXPECT_EQ(verified.size(), total_expected); |
There was a problem hiding this comment.
nit: this EXPECT_EQ(verified.size(), total_expected) only reports two counts on failure, so it does not say which instrument never arrived.
Consider EXPECT_THAT(verified, UnorderedElementsAreArray(...)) over the two instrument lists so a failure names the missing instrument.
There was a problem hiding this comment.
Updated the final assertion to UnorderedElementsAreArray over the expected instrument names so any missing instrument is named on failure.
Replied by cpriti-o11y-agent
|
|
||
| std::mutex mu; | ||
| std::set<std::string> verified; | ||
| auto const total_expected = expected_latency.size() + expected_size.size(); |
There was a problem hiding this comment.
nit: here auto const total_expected deduces a std::size_t, and auto h on lines 309 and 315 hides the return type of CreateDoubleHistogram(). The style guide asks for explicit scalar types and for not hiding function return types behind auto.
There was a problem hiding this comment.
Replaced auto with explicit std::size_t and pushed CreateDoubleHistogram() directly into instruments.
Replied by cpriti-o11y-agent
| constexpr std::string_view kStorageClientPrefix = "gcp.storage.client."; | ||
| if (absl::StartsWith(s, kStorageClientPrefix)) { | ||
| s.erase(0, kStorageClientPrefix.size()); | ||
| std::replace(s.begin(), s.end(), '.', '_'); |
There was a problem hiding this comment.
Missed this in the earlier pass: nothing here says why gcp.storage.client.* names are flattened with _ while every other name becomes a / path. A future editor could reasonably unify the two branches and break the mapping to the registered descriptors.
Consider a one-line comment stating that these SDK metrics are registered in Cloud Monitoring under flat underscore names.
There was a problem hiding this comment.
Added a comment noting that these SDK metrics are registered in Cloud Monitoring under flat underscore names.
Replied by cpriti-o11y-agent
Adds internal Cloud Monitoring metric name formatting and explicit histogram bucket views for the Google Cloud Storage OpenTelemetry SDK metrics:
gcp.client.request.durationtostorage.googleapis.com/client/request_durationandgcp.storage.client.<name>(.->_) tostorage.googleapis.com/client/<name>while preservinginternal/client/routing.kStorageMeterNameusing sharedconstexpr std::string_viewinstrument name constants.This PR adds the internal formatter and view plumbing; instrument recording lands in follow-up PRs.
Created by cpriti-o11y-agent