Repository navigation
Conversation
There was a problem hiding this comment.
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.
| #include "google/cloud/storage/internal/metrics_error_type.h" | ||
| #include "absl/strings/match.h" | ||
| #include <string_view> |
There was a problem hiding this comment.
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
- 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.
| return (absl::StrContainsIgnoreCase(msg, "crc32c") || | ||
| absl::StrContainsIgnoreCase(msg, "md5")) && | ||
| absl::StrContainsIgnoreCase(msg, "match"); |
There was a problem hiding this comment.
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");There was a problem hiding this comment.
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
a217274 to
a4cded8
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
…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]
a4cded8 to
65e13a1
Compare
| namespace { | ||
|
|
||
| bool IsChecksumMismatch(Status const& status) { | ||
| auto const code = status.code(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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") || |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 {}; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
| absl::StrContains(msg, "(): mismatched hashes in ")) { | ||
| return true; | ||
| } | ||
| return absl::StrContainsIgnoreCase(msg, "mismatched crc32c") || |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
Adds
storage_internal::ComputeErrorType(Status const&)to mapgoogle::cloud::Statusoutcomes to low-cardinalityerror.typeattribute strings for OpenTelemetry client metrics:"OK"on success."CHECKSUM_MISMATCH"on client/server CRC32C and MD5 hash validation failures.error_info().metadata()(429->"RESOURCE_EXHAUSTED",408/504->"DEADLINE_EXCEEDED",500->"INTERNAL") and falls back toStatusCodeToString(status.code()).Created by cpriti-o11y-agent