Skip to content

impl(storage): add status and checksum error classification for OTel metrics - #16639

Open
cpriti-os wants to merge 5 commits into
googleapis:mainfrom
cpriti-os:feat-storage-metrics-error-type
Open

cpriti-os wants to merge 5 commits into
googleapis:mainfrom
cpriti-os:feat-storage-metrics-error-type

Conversation

@cpriti-os

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

Copy link
Copy Markdown
Contributor

Adds storage_internal::ComputeErrorType(Status const&) to map google::cloud::Status outcomes to low-cardinality error.type attribute strings for OpenTelemetry client metrics:

  • "OK" on success.
  • "CHECKSUM_MISMATCH" on client/server CRC32C and MD5 hash validation failures.
  • Preserves fine-grained HTTP status mappings from error_info().metadata() (429 -> "RESOURCE_EXHAUSTED", 408/504 -> "DEADLINE_EXCEEDED", 500 -> "INTERNAL") and falls back to StatusCodeToString(status.code()).

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 introduces a new utility, ComputeErrorType, to classify google::cloud::Status codes into low-cardinality error type strings for metrics, along with associated unit tests and build configuration updates. The feedback highlights a compilation issue where absl::StrContainsIgnoreCase is used but does not exist in Abseil. To fix this, the status message should be converted to lowercase using absl::AsciiStrToLower (which requires including <absl/strings/ascii.h>) before performing standard absl::StrContains checks.

Comment on lines +15 to +17
#include "google/cloud/storage/internal/metrics_error_type.h"
#include "absl/strings/match.h"
#include <string_view>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

To support case-insensitive string matching using absl::AsciiStrToLower, we need to include <absl/strings/ascii.h>.

#include "google/cloud/storage/internal/metrics_error_type.h"
#include "absl/strings/ascii.h"
#include "absl/strings/match.h"
#include <string_view>
References
  1. Prefer including headers (such as <string_view>) directly in .cc files rather than .h files if they are only needed in the implementation, to reduce compilation times for other files that include the header.

Comment on lines +35 to +37
return (absl::StrContainsIgnoreCase(msg, "crc32c") ||
absl::StrContainsIgnoreCase(msg, "md5")) &&
absl::StrContainsIgnoreCase(msg, "match");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Abseil does not have a function named absl::StrContainsIgnoreCase. Using it will cause a compilation error. Instead, convert the message to lowercase using absl::AsciiStrToLower and perform standard absl::StrContains checks.

  std::string const lower_msg = absl::AsciiStrToLower(msg);
  return (absl::StrContains(lower_msg, "crc32c") ||
          absl::StrContains(lower_msg, "md5")) &&
         absl::StrContains(lower_msg, "match");

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.

absl::StrContainsIgnoreCase is provided by "absl/strings/match.h" and avoids allocating a lowercase std::string copy on each check.


Replied by cpriti-o11y-agent

@cpriti-os cpriti-os changed the title feat(storage): add error type classification for OTel metrics feat(storage): add status and checksum error classification for OTel metrics Nov 9, 2026
@cpriti-os
cpriti-os force-pushed the feat-storage-metrics-error-type branch from a217274 to a4cded8 Compare November 9, 2026 08:07
@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.74%. Comparing base (c796fcd) to head (e462f53).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16639      +/-   ##
==========================================
- Coverage   92.75%   92.74%   -0.02%     
==========================================
  Files        2271     2273       +2     
  Lines      227219   227276      +57     
==========================================
+ Hits       210763   210785      +22     
- Misses      16456    16491      +35     

☔ 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 marked this pull request as ready for review November 9, 2026 09:08
@cpriti-os
cpriti-os requested review from a team as code owners November 9, 2026 09:08
@cpriti-os
cpriti-os requested a review from kalragauri November 9, 2026 09:08
…metrics

Add `storage_internal::ComputeErrorType(Status const&)` to classify
`Status` values into low-cardinality `error.type` attribute strings for
OpenTelemetry client metrics:

- `"OK"` on success
- `"CHECKSUM_MISMATCH"` on client/server CRC32C and MD5 hash mismatches
- Canonical status names (`"RESOURCE_EXHAUSTED"` for HTTP 429,
  `"DEADLINE_EXCEEDED"` for HTTP 408/504, `"INTERNAL"` for HTTP 500, and
  `StatusCodeToString(status.code())`) otherwise

[Generated-by: AI]
@cpriti-os cpriti-os changed the title feat(storage): add status and checksum error classification for OTel metrics impl(storage): add status and checksum error classification for OTel metrics Nov 20, 2026
@cpriti-os
cpriti-os force-pushed the feat-storage-metrics-error-type branch from a4cded8 to 65e13a1 Compare November 20, 2026 06:49
namespace {

bool IsChecksumMismatch(Status const& status) {
auto const code = status.code();

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.

auto here (and on metadata at line 44) hides function return types rather than repeating a type written on the right-hand side; see the auto rules in .gemini/styleguide.md.

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.

Replaced auto with explicit types for code and metadata.


Replied by cpriti-o11y-agent

absl::StrContains(msg, "(): mismatched hashes in ")) {
return true;
}
return (absl::StrContainsIgnoreCase(msg, "crc32c") ||

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.

The crc32c/md5 plus match fallback here also fires on any kInvalidArgument whose message echoes a user-chosen name, for example Status(StatusCode::kInvalidArgument, "Invalid bucket name: 'md5-match'").

Should those requests be counted as CHECKSUM_MISMATCH?

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.

Good catch—tightened the fallback to match GCS's checksum mismatch phrases ("mismatched crc32c" / "mismatched md5" / "doesn't match calculated" / "does not match calculated") and added "Invalid bucket name: 'md5-match'" as a negative test case.


Replied by cpriti-o11y-agent

if (status.code() != StatusCode::kUnavailable) return {};
auto const& metadata = status.error_info().metadata();
auto const it = metadata.find("http_status_code");
if (it == metadata.end()) return {};

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.

http_status_code is only present when the error body is empty or is JSON with a reason and domain entry (see ParseJsonError()). A 429 or 504 with an HTML or plain-text body, such as one from a proxy, falls through here and is reported as UNAVAILABLE.

Is that split intended, and if so could the comment above say when http_status_code is absent?

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.

Yes, falling through to UNAVAILABLE when http_status_code is absent (such as HTML/plain-text proxy responses) is intended; updated the comment to document when the metadata key is present.


Replied by cpriti-o11y-agent

@cpriti-os
cpriti-os requested a review from kalragauri November 23, 2026 04:17
absl::StrContains(msg, "(): mismatched hashes in ")) {
return true;
}
return absl::StrContainsIgnoreCase(msg, "mismatched crc32c") ||

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.

Tightening the fallback here dropped GCS's gRPC WriteObject and BidiWriteObject checksum mismatch responses, which return kInvalidArgument with "Object crc32c mismatch: server computed: ...", "Checksummed data message crc32c mismatch: server computed: ...", and "Object MD5 mismatch: server computed: ..." (also noted in google-cloud-go's isServerChecksumError).

Existing CI passes because ComputeErrorType() is not wired up yet, but once wired up this will classify gRPC server checksum failures as "INVALID_ARGUMENT" both against live GCS and in storage-testbench BidiWriteObject tests. Consider also matching "crc32c mismatch: server computed:" and "md5 mismatch: server computed:" (with unit tests covering them).

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.

Great catch—added "crc32c mismatch: server computed:" and "md5 mismatch: server computed:" (case-insensitive) to IsChecksumMismatch along with unit tests for the gRPC WriteObject/BidiWriteObject messages.


Replied by cpriti-o11y-agent

@cpriti-os
cpriti-os requested a review from kalragauri November 24, 2026 09:00

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