Skip to content

feat(storage): add Cloud Monitoring metric name formatting and histogram views - #16638

Open
cpriti-os wants to merge 2 commits into
googleapis:mainfrom
cpriti-os:feat-storage-metrics-formatter-and-views
Open

cpriti-os wants to merge 2 commits into
googleapis:mainfrom
cpriti-os:feat-storage-metrics-formatter-and-views

Conversation

@cpriti-os

@cpriti-os cpriti-os commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Extends the GCS OpenTelemetry metrics exporter and meter provider for the client-side OpenTelemetry metrics specification:

  • Updates MetricsExporterOptions() metric name formatter 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/.
  • Registers explicit latency (s) and size (By) histogram bucket views for the Storage client instruments under the gl-cpp meter scope in MakeGrpcMeterProvider().

Created by cpriti-o11y-agent

@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Nov 9, 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 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.

Comment on lines +289 to +293
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);
}

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

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);
  }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved Record() outside the wait loop so each histogram is recorded once before waiting for the export.


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]
@cpriti-os
cpriti-os force-pushed the feat-storage-metrics-formatter-and-views branch from 631feab to 7fdb367 Compare November 9, 2026 07:07
@cpriti-os cpriti-os changed the title feat(storage): add Monarch metric name formatting and histogram views for OTel metrics feat(storage): add Cloud Monitoring metric name formatting and histogram views Nov 9, 2026
@cpriti-os
cpriti-os marked this pull request as ready for review November 9, 2026 07:13
@cpriti-os
cpriti-os requested review from a team as code owners November 9, 2026 07:13
@cpriti-os
cpriti-os requested a review from kalragauri November 9, 2026 07:13
@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.45%. Comparing base (b1e9b10) to head (d4255b6).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16638      +/-   ##
==========================================
- Coverage   92.48%   92.45%   -0.03%     
==========================================
  Files        2269     2269              
  Lines      222192   222233      +41     
==========================================
- Hits       205487   205470      -17     
- Misses      16705    16763      +58     

☔ 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