Skip to content

impl(storage): add ServerUnreachedMetrics recorder for OTel server.unreached counter - #16714

Open
cpriti-os wants to merge 2 commits into
googleapis:mainfrom
cpriti-os:impl-storage-server-unreached-metrics
Open

cpriti-os wants to merge 2 commits into
googleapis:mainfrom
cpriti-os:impl-storage-server-unreached-metrics

Conversation

@cpriti-os

Copy link
Copy Markdown
Contributor

Adds the internal ServerUnreachedMetrics recorder for the gcp.storage.client.server.unreached OpenTelemetry counter (UInt64Counter, unit {request}).

Records failed attempts that did not reach Google Cloud Storage with the standard Storage base attributes (gcp.client.version, gcp.client.artifact, gcp.client.service, server.address) plus rpc.system.name, gcp.storage.operation, network.path, and error.type, propagating the explicit opentelemetry::context::Context and safely no-oping when the provider, meter, or instrument is null.

Also registers server_unreached_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 26, 2026 07:53
@cpriti-os
cpriti-os requested a review from kalragauri November 26, 2026 07:53
@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Nov 26, 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 the ServerUnreachedMetrics class to track and record failed requests that do not reach Google Cloud Storage, along with corresponding unit tests and build configuration updates. The review feedback suggests simplifying the implementation and tests by replacing the custom SemanticVersionString() helper with the existing google::cloud::version_string() function, which also ensures pre-release or development suffixes are correctly preserved.

Comment on lines +44 to +48
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());
}

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

We can remove the redundant SemanticVersionString() helper function and use google::cloud::version_string() directly. This simplifies the code and ensures any pre-release or development suffixes are correctly preserved in the metrics.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same point as my reply on #16712: 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.

opentelemetry::nostd::shared_ptr<
opentelemetry::metrics::MeterProvider> const& provider,
std::string server_address)
: client_version_(SemanticVersionString()),

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

Use google::cloud::version_string() directly instead of SemanticVersionString().

    : client_version_(google::cloud::version_string()),

Comment on lines +124 to +127
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());

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

We can simplify this by using google::cloud::version_string() directly instead of manually formatting the version components.

  std::string const expected_version = google::cloud::version_string();

@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.45763% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.79%. Comparing base (4a2bfb0) to head (af2dc06).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
.../storage/internal/server_unreached_metrics_test.cc 97.59% 2 Missing ⚠️
...cloud/storage/internal/server_unreached_metrics.cc 97.14% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16714      +/-   ##
==========================================
+ Coverage   92.78%   92.79%   +0.01%     
==========================================
  Files        2277     2279       +2     
  Lines      228147   228265     +118     
==========================================
+ Hits       211696   211829     +133     
+ Misses      16451    16436      -15     

☔ 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.

@cpriti-os
cpriti-os force-pushed the impl-storage-server-unreached-metrics branch from 902964c to 85cd0d7 Compare November 26, 2026 11:45
@cpriti-os
cpriti-os force-pushed the impl-storage-server-unreached-metrics branch from 85cd0d7 to 5090454 Compare November 27, 2026 11:14
/// Labels for recording a failed attempt that did not reach the server
/// (`gcp.storage.client.server.unreached`).
struct ServerUnreachedLabels {
std::string_view rpc_system;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same point as my comment on #16713: rpc_system accepts any string here, while AttemptMetrics fixes "grpc" and "http" inside per-transport methods. Would it make sense to split this into RecordGrpcServerUnreached() and RecordHttpServerUnreached() (or take an enum class), so callers cannot pass an arbitrary value?

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.

Split RecordServerUnreached into RecordGrpcServerUnreached and RecordHttpServerUnreached and removed rpc_system from ServerUnreachedLabels.


Replied by cpriti-o11y-agent

struct ServerUnreachedLabels {
std::string_view rpc_system;
std::string_view operation;
std::string_view network_path;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

network_path comes before error_type here, while GrpcAttemptLabels and HttpAttemptLabels list error_type first. All of these fields are std::string_view, so a caller filling both structs for one attempt can swap the two values without a compile error. Would it make sense to keep the same relative order as the attempt labels?

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.

Reordered ServerUnreachedLabels to {operation, error_type, network_path} so it matches GrpcAttemptLabels and HttpAttemptLabels.


Replied by cpriti-o11y-agent

using CounterPtr = opentelemetry::nostd::unique_ptr<
opentelemetry::metrics::Counter<std::uint64_t>>;

std::map<std::string, std::string> ExtractStringAttrs(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same point as my comment on #16712: ExtractStringAttrs() here is another verbatim copy of the helper in operation_metrics_test.cc. Could this test use whichever shared location that thread settles on?

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.

I extracted the test attribute helpers into google/cloud/storage/testing/metrics_test_utils.h in #16712. Once #16712 merges, I will rebase and reuse it here.


Replied by cpriti-o11y-agent

using Attr = std::pair<opentelemetry::nostd::string_view,
opentelemetry::common::AttributeValue>;

opentelemetry::nostd::string_view ToNostd(std::string_view sv) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same point as my comment on #16712: ToNostd and SemanticVersionString are now in three places, here, operation_metrics.cc and attempt_metrics.cc.

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.

I moved these into shared metrics_attributes.{h,cc} in #16712. Once #16712 lands, I will rebase this PR onto main and reuse them here.


Replied by cpriti-o11y-agent

opentelemetry::metrics::MeterProvider> const& provider,
std::string server_address);

void RecordServerUnreached(ServerUnreachedLabels const& labels,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

RecordServerUnreached does not say whether to call it when the client cannot tell if the server was reached, such as a client-side timeout or a cancellation. The counter's meaning depends on that, and the instrument description (Number of failed requests that did not reach Google Cloud Storage.) does not settle it either.

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.

Updated the method doc comments and counter description to state that callers only invoke this for proven pre-response failures (such as DNS, TLS, connection, or auth errors) and not for ambiguous aborts like timeouts or cancellations.


Replied by cpriti-o11y-agent

Comment on lines +44 to +48
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());
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same point as my reply on #16712: 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.

@cpriti-os
cpriti-os requested a review from kalragauri December 1, 2026 05:07

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.

2 participants