Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces HttpAttemptTimingMetrics to record HTTP request attempt durations using OpenTelemetry, along with a path normalization utility ComputeUrlTemplate and corresponding unit tests. The review feedback recommends adhering to the repository style guide by removing the default parameter for host in ComputeUrlTemplate (which is in an internal namespace) and providing explicit overloads instead. Additionally, it suggests simplifying IsKnownJsonLiteralSegment by consolidating the allowed segments into a single array.
| std::string ComputeUrlTemplate(std::string_view path, | ||
| std::string_view host = ""); |
There was a problem hiding this comment.
According to the repository style guide, default parameter values are disallowed in internal namespaces (such as google::cloud::storage_internal). Please provide an explicit function overload instead of using a default argument.
std::string ComputeUrlTemplate(std::string_view path);
std::string ComputeUrlTemplate(std::string_view path,
std::string_view host);References
- Disallow Default Parameters in internal Namespaces: Reject default argument values in functions, member functions, and constructors declared in internal namespaces (e.g., google::cloud::::internal, google::cloud::_internal). Require all internal callers and unit tests to explicitly supply all arguments. Suggest explicit function overloads if a simpler calling syntax is needed. (link)
|
|
||
| } // namespace | ||
|
|
||
| std::string ComputeUrlTemplate(std::string_view path, std::string_view host) { |
There was a problem hiding this comment.
To support the overload of ComputeUrlTemplate without the default parameter (adhering to the style guide for internal namespaces), please define both overloads here.
std::string ComputeUrlTemplate(std::string_view path) {
return ComputeUrlTemplate(path, "");
}
std::string ComputeUrlTemplate(std::string_view path, std::string_view host) {References
- Disallow Default Parameters in internal Namespaces: Reject default argument values in functions, member functions, and constructors declared in internal namespaces (e.g., google::cloud::::internal, google::cloud::_internal). Require all internal callers and unit tests to explicitly supply all arguments. Suggest explicit function overloads if a simpler calling syntax is needed. (link)
| bool IsKnownJsonLiteralSegment(std::string_view segment) { | ||
| constexpr std::array<std::string_view, 27> kAllowed = {{ | ||
| "storage", | ||
| "v1", | ||
| "upload", | ||
| "download", | ||
| "b", | ||
| "o", | ||
| "iam", | ||
| "testPermissions", | ||
| "acl", | ||
| "defaultObjectAcl", | ||
| "notificationConfigs", | ||
| "hmacKeys", | ||
| "projects", | ||
| "serviceAccount", | ||
| "folders", | ||
| "managedFolders", | ||
| "anywhereCaches", | ||
| "lockRetentionPolicy", | ||
| "rewriteTo", | ||
| "copyTo", | ||
| "moveTo", | ||
| "compose", | ||
| "restore", | ||
| "rename", | ||
| "operations", | ||
| "disable", | ||
| "pause", | ||
| }}; | ||
| for (std::string_view allowed : kAllowed) { | ||
| if (segment == allowed) return true; | ||
| } | ||
| return segment == "resume"; | ||
| } |
There was a problem hiding this comment.
For better readability and consistency, we can include "resume" directly in the kAllowed array instead of checking it separately at the end of the function.
bool IsKnownJsonLiteralSegment(std::string_view segment) {
constexpr std::array<std::string_view, 28> kAllowed = {{
"storage",
"v1",
"upload",
"download",
"b",
"o",
"iam",
"testPermissions",
"acl",
"defaultObjectAcl",
"notificationConfigs",
"hmacKeys",
"projects",
"serviceAccount",
"folders",
"managedFolders",
"anywhereCaches",
"lockRetentionPolicy",
"rewriteTo",
"copyTo",
"moveTo",
"compose",
"restore",
"rename",
"operations",
"disable",
"pause",
"resume",
}};
for (std::string_view allowed : kAllowed) {
if (segment == allowed) return true;
}
return false;
}
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #16723 +/- ##
==========================================
+ Coverage 92.78% 92.80% +0.02%
==========================================
Files 2279 2281 +2
Lines 228396 228614 +218
==========================================
+ Hits 211921 212176 +255
+ Misses 16475 16438 -37 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Adds the internal
HttpAttemptTimingMetricsrecorder andComputeUrlTemplate()normalizer for per-attempt HTTP duration metrics:http.client.request.duration(DoubleHistogram, units) registered inkStorageLatencyHistogramInstrumentsandmetrics_constants.h(kHttpRequestDurationMetric)gcp.client.version,gcp.client.artifact,gcp.client.service,server.address) plusrpc.system.name("http"),http.request.method,url.template,http.response.status_code(int64),error.type, andnetwork.pathComputeUrlTemplate()normalizes JSON API paths (with or without leading/, as well as full resumable session URLs), XML path-style paths, and case-insensitive XML virtual-hosted paths, stripping?query/#fragment, collapsing consecutive slashes, and redacting unrecognized segments sourl.templatecardinality stays strictly boundedAlso registers
http_attempt_timing_metrics.{h,cc,_test.cc}in Bazel and CMake build files.Created by cpriti-o11y-agent