Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the PayloadMetrics class to record OpenTelemetry metrics for request and response payload body sizes in Google Cloud Storage, along with comprehensive unit tests and build file updates. The review feedback suggests simplifying the implementation and tests by directly using google::cloud::version_string() instead of defining and using a custom SemanticVersionString() helper.
| std::string SemanticVersionString() { | ||
| return std::to_string(google::cloud::version_major()) + "." + | ||
| std::to_string(google::cloud::version_minor()) + "." + | ||
| std::to_string(google::cloud::version_patch()); | ||
| } |
There was a problem hiding this comment.
There was a problem hiding this comment.
I would keep SemanticVersionString() here. version_string() returns v<major>.<minor>.<patch> plus any pre-release and build metadata, so gcp.client.version would no longer match what OperationMetrics and AttemptMetrics emit. The bare major.minor.patch form is what #16685 and #16686 landed with.
| opentelemetry::nostd::shared_ptr< | ||
| opentelemetry::metrics::MeterProvider> const& provider, | ||
| std::string server_address, std::string rpc_system) | ||
| : client_version_(SemanticVersionString()), |
| std::string const expected_version = | ||
| std::to_string(google::cloud::version_major()) + "." + | ||
| std::to_string(google::cloud::version_minor()) + "." + | ||
| std::to_string(google::cloud::version_patch()); |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #16712 +/- ##
==========================================
+ Coverage 92.78% 92.80% +0.02%
==========================================
Files 2279 2283 +4
Lines 228396 228561 +165
==========================================
+ Hits 211921 212123 +202
+ Misses 16475 16438 -37 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
e0324ed to
b728eaf
Compare
| opentelemetry::metrics::MeterProvider> const& provider, | ||
| std::string server_address, std::string rpc_system); | ||
|
|
||
| void RecordRequestBodySize(PayloadLabels const& labels, std::uint64_t bytes, |
There was a problem hiding this comment.
RecordRequestBodySize does not say what one call stands for: a whole operation, one attempt, or one chunk. The histogram's shape depends on that, and the instrument description (Total logical payload bytes uploaded.) does not settle it either.
There was a problem hiding this comment.
Good catch! Updated the method comments and instrument descriptions to specify that each call records the total logical payload bytes for one completed logical operation (including 0-byte objects), rather than per-attempt or per-chunk sizes.
Replied by cpriti-o11y-agent
| std::string SemanticVersionString() { | ||
| return std::to_string(google::cloud::version_major()) + "." + | ||
| std::to_string(google::cloud::version_minor()) + "." + | ||
| std::to_string(google::cloud::version_patch()); | ||
| } |
There was a problem hiding this comment.
I would keep SemanticVersionString() here. version_string() returns v<major>.<minor>.<patch> plus any pre-release and build metadata, so gcp.client.version would no longer match what OperationMetrics and AttemptMetrics emit. The bare major.minor.patch form is what #16685 and #16686 landed with.
| using Attr = std::pair<opentelemetry::nostd::string_view, | ||
| opentelemetry::common::AttributeValue>; | ||
|
|
||
| opentelemetry::nostd::string_view ToNostd(std::string_view sv) { |
There was a problem hiding this comment.
It looks like ToNostd and SemanticVersionString are now in three places: here, operation_metrics.cc and attempt_metrics.cc. The five base attributes in RecordBodySize are repeated across the three recorders too, so a change to gcp.client.version would need three edits. Would it make sense to move the two functions and the base attribute list into internal/metrics_attributes.h, which keeps them in storage_internal and out of the public API?
There was a problem hiding this comment.
Agreed, moved ToNostd, SemanticVersionString, and a MakeStorageMetricAttributes helper for the 5 common attributes into internal/metrics_attributes.{h,cc} and updated PayloadMetrics, OperationMetrics, and AttemptMetrics to share them.
Replied by cpriti-o11y-agent
| using HistPtr = opentelemetry::nostd::unique_ptr< | ||
| opentelemetry::metrics::Histogram<std::uint64_t>>; | ||
|
|
||
| std::map<std::string, std::string> ExtractStringAttrs( |
There was a problem hiding this comment.
It looks like ExtractStringAttrs() is a verbatim copy of the helper in operation_metrics_test.cc, and attempt_metrics_test.cc has a variant.
Would it make sense to move one version into google/cloud/testing_util (or a storage-specific location) and use it from these tests?
There was a problem hiding this comment.
Makes sense! Extracted ExtractStringMetricAttrs and ExtractMetricAttrs into google/cloud/storage/testing/metrics_test_utils.h and updated payload_metrics_test.cc, operation_metrics_test.cc, and attempt_metrics_test.cc to reuse them.
Replied by cpriti-o11y-agent
b728eaf to
408a00c
Compare
kalragauri
left a comment
There was a problem hiding this comment.
The PR description still reflects only the initial commit and omits the shared-helper refactor across metrics_attributes.{h,cc}, OperationMetrics, AttemptMetrics, and storage/testing/metrics_test_utils.h. It also leaves out the metrics_constants.h / metrics_meter_provider.{h,_test.cc} updates and that PayloadMetrics is not wired into callers yet.
Could you refresh the description so the squash commit message covers the full diff?
| if (auto const* sv = | ||
| opentelemetry::nostd::get_if<opentelemetry::nostd::string_view>( | ||
| &value)) { | ||
| result.strings.emplace(k, std::string(sv->data(), sv->size())); |
There was a problem hiding this comment.
result.strings.emplace ignores its return value (as do result.ints.emplace and ExtractStringMetricAttrs), so duplicate attribute keys are silently kept first-wins. If a recorder repeats a base key in MakeStorageMetricAttributes, UnorderedElementsAre can pass even though the OTel SDK keeps the last value.
Consider calling ADD_FAILURE() whenever a key appears more than once (including across strings and ints).
There was a problem hiding this comment.
Done, both helpers now call ADD_FAILURE() on duplicate keys.
Replied by cpriti-o11y-agent
| using MetricAttribute = std::pair<opentelemetry::nostd::string_view, | ||
| opentelemetry::common::AttributeValue>; | ||
|
|
||
| inline opentelemetry::nostd::string_view ToNostd(std::string_view sv) { |
There was a problem hiding this comment.
ToNostd, SemanticVersionString, and MakeStorageMetricAttributes are now shared helpers here, but metrics_attributes_test.cc has no direct tests for them. Existing recorder tests only pass null-terminated strings, so dropping sv.size() in ToNostd or calling MakeStorageMetricAttributes with zero extra attributes is untested.
Would it make sense to add unit tests for them in metrics_attributes_test.cc, including a non-null-terminated std::string_view slice?
There was a problem hiding this comment.
Done, added unit tests in metrics_attributes_test.cc including a non-null-terminated slice.
Replied by cpriti-o11y-agent
|
|
||
| namespace google { | ||
| namespace cloud { | ||
| namespace storage_internal { |
There was a problem hiding this comment.
This header is in storage_internal, while every other namespaced file under google/cloud/storage/testing/ (such as canonical_errors.h) uses google::cloud::storage::testing without an inline version namespace. Keeping test-only utilities under storage::testing matches the rest of the directory and avoids mixing test symbols into the production internal namespace.
Can we move these helpers to google::cloud::storage::testing?
There was a problem hiding this comment.
Done, moved to google::cloud::storage::testing and updated callers.
Replied by cpriti-o11y-agent
| void RecordRequestBodySize(PayloadLabels const& labels, std::uint64_t bytes, | ||
| opentelemetry::context::Context const& ctx) const; | ||
|
|
||
| /// Records the total logical payload bytes downloaded for one completed |
There was a problem hiding this comment.
This comment says "one completed logical Storage operation (including 0-byte objects)", which reads as skipping early-closed or partial downloads. Like Go's reader close path and Java's description, this metric counts bytes delivered to the application on close, including partial reads, rather than full object size.
Should we reword this (and RecordRequestBodySize for uploads closed early) so callers do not skip partial streams or emit Content-Length?
There was a problem hiding this comment.
Done, reworded both doc comments to cover partial and early-closed streams.
Replied by cpriti-o11y-agent
…ts, and PayloadMetrics docs
Adds
storage_internal::PayloadMetrics(google/cloud/storage/internal/payload_metrics.{h,cc}) to record operation-scoped payload body size OpenTelemetry histograms:gcp.storage.client.request.body.size(UInt64Histogram, unitBy)gcp.storage.client.response.body.size(UInt64Histogram, unitBy)Also in this PR:
google/cloud/storage/internal/metrics_constants.hand adds them tokStorageSizeHistogramInstrumentsingoogle/cloud/storage/internal/grpc/metrics_meter_provider.{h,_test.cc}.MetricAttribute,ToNostd,SemanticVersionString,MakeStorageMetricAttributes) intogoogle/cloud/storage/internal/metrics_attributes.{h,cc}with unit tests inmetrics_attributes_test.cc, and updatesOperationMetricsandAttemptMetricsto reuse them.CapturedMetricAttrs,ExtractMetricAttrs,ExtractStringMetricAttrs) intogoogle/cloud/storage/testing/metrics_test_utils.hundergoogle::cloud::storage::testingwith duplicate-key failure checks, and updatesattempt_metrics_test.cc,operation_metrics_test.cc, andpayload_metrics_test.ccto use them.PayloadMetricsis not wired into callers yet; caller wiring will follow in a subsequent PR.Created by cpriti-o11y-agent