Skip to content

impl(storage): add HttpAttemptTimingMetrics recorder and URL template normalizer - #16723

Open
cpriti-os wants to merge 4 commits into
googleapis:mainfrom
cpriti-os:impl-storage-http-attempt-timing-metrics
Open

cpriti-os wants to merge 4 commits into
googleapis:mainfrom
cpriti-os:impl-storage-http-attempt-timing-metrics

Conversation

@cpriti-os

Copy link
Copy Markdown
Contributor

Adds the internal HttpAttemptTimingMetrics recorder and ComputeUrlTemplate() normalizer for per-attempt HTTP duration metrics:

  • http.client.request.duration (DoubleHistogram, unit s) registered in kStorageLatencyHistogramInstruments and metrics_constants.h (kHttpRequestDurationMetric)
  • Emits the standard Storage base attributes (gcp.client.version, gcp.client.artifact, gcp.client.service, server.address) plus rpc.system.name ("http"), http.request.method, url.template, http.response.status_code (int64), error.type, and network.path
  • ComputeUrlTemplate() 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 so url.template cardinality stays strictly bounded

Also registers http_attempt_timing_metrics.{h,cc,_test.cc} in Bazel and CMake build files.


Created by cpriti-o11y-agent

@cpriti-os
cpriti-os requested review from a team as code owners November 30, 2026 08:32
@cpriti-os
cpriti-os requested a review from kalragauri November 30, 2026 08:32
@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Nov 30, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +43 to +44
std::string ComputeUrlTemplate(std::string_view path,
std::string_view host = "");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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
  1. 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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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
  1. 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)

Comment on lines +79 to +113
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";
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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

codecov Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.62385% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.80%. Comparing base (fdcfe38) to head (1e60fa5).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...ud/storage/internal/http_attempt_timing_metrics.cc 98.09% 2 Missing ⚠️
...orage/internal/http_attempt_timing_metrics_test.cc 99.11% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the Cloud Storage API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant