Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces MetricsConnection, a decorator for StorageConnection that records operation-level OpenTelemetry metrics, along with its corresponding unit tests. The review feedback suggests several improvements: replacing default parameters in the test harness to comply with the repository style guide's restriction on internal namespaces, refactoring the Read method in MetricsObjectReadSource to return early on error, and simplifying a return statement in ReadObject by removing an explicit std::unique_ptr conversion.
| std::unique_ptr<MetricsHarness> MakeHarness( | ||
| std::string server_address = "storage.googleapis.com", | ||
| std::string rpc_system = "grpc") { |
There was a problem hiding this comment.
The repository style guide disallows default parameters in internal namespaces (including storage_internal and its nested anonymous namespaces), even in unit tests. Please replace the default parameters with explicit function overloads.
std::unique_ptr<MetricsHarness> MakeHarness(
std::string server_address,
std::string rpc_system);
std::unique_ptr<MetricsHarness> MakeHarness() {
return MakeHarness("storage.googleapis.com", "grpc");
}
std::unique_ptr<MetricsHarness> MakeHarness(
std::string server_address,
std::string rpc_system) {References
- Disallow Default Parameters in
internalNamespaces: Reject default argument values in functions, member functions, and constructors declared ininternalnamespaces. (link)
| if (!result) { | ||
| RecordOnce(result.status()); | ||
| } else if (!child_->IsOpen()) { | ||
| RecordOnce(Status{}); | ||
| } | ||
| return result; |
There was a problem hiding this comment.
Following the 'Return Early' principle from the style guide, we can return immediately when result is an error. This simplifies the control flow and avoids the else if block.
if (!result) {
RecordOnce(result.status());
return result;
}
if (!child_->IsOpen()) {
RecordOnce(Status{});
}
return result;References
- Return Early: Avoid unnecessary
elseblocks to reduce indentation and keep the main logic flow linear. (link)
| return std::unique_ptr<storage::internal::ObjectReadSource>( | ||
| std::make_unique<MetricsObjectReadSource>(metrics_, start, ctx, | ||
| *std::move(reader))); |
There was a problem hiding this comment.
Since MetricsObjectReadSource publicly inherits from storage::internal::ObjectReadSource, std::unique_ptr<MetricsObjectReadSource> implicitly converts to std::unique_ptr<storage::internal::ObjectReadSource>. We can simplify this return statement by removing the explicit constructor call.
return std::make_unique<MetricsObjectReadSource>(metrics_, start, ctx,
*std::move(reader));
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #16724 +/- ##
==========================================
+ Coverage 92.78% 92.83% +0.04%
==========================================
Files 2279 2282 +3
Lines 228396 229219 +823
==========================================
+ Hits 211921 212789 +868
+ Misses 16475 16430 -45 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Adds the internal
MetricsConnectionStorageConnectiondecorator (andMakeMetricsConnection()factory) that records operation-level OpenTelemetry metrics (gcp.storage.client.operationsandgcp.client.request.duration) via a constructor-injectedOperationMetricsrecorder:gcp.storage.operation,gcp.client.method,rpc.method, anderror.type(ComputeErrorType) labels, propagating the activeopentelemetry::context::ContextReadObjectresponses inMetricsObjectReadSourceso operation metrics span the full download lifetime (recording once on open failure, EOF, read error, earlyClose(), or abandonment) while preserving the openingContextSignBlobwithout double-counting logical Storage operationsmetricsis nullAlso registers
metrics_connection.{h,cc,_test.cc}in Bazel and CMake build files.Created by cpriti-o11y-agent