Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces utility functions NormalizeServerAddress and NetworkPathOfPeer in a new metrics_attributes component to assist with GCS metrics, along with corresponding unit tests and build file updates. The review feedback identifies a bug in ParseIpv6 where malformed IPv6 addresses with out-of-range or unparseable groups are incorrectly validated as true, and suggests fixing this logic and adding a corresponding unit test case to ensure they are correctly classified as unknown.
| if (!ParseUint(ip.substr(0, colon), 16, groups[i]) || groups[i] > 0xFFFF) { | ||
| return true; | ||
| } |
There was a problem hiding this comment.
In ParseIpv6, if a non-empty group fails to parse or its value exceeds 0xFFFF (e.g., 80400), the function incorrectly returns true (treating it as a valid IPv6 address). This causes malformed IPv6 addresses to be classified as "cloudpath" instead of "unknown".
We should only return true early if the group is empty (which is valid for compressed IPv6 addresses like ::). If the group is not empty and parsing fails or the value is out of range, we should return false.
auto const part = ip.substr(0, colon);
if (part.empty()) return true;
if (!ParseUint(part, 16, groups[i]) || groups[i] > 0xFFFF) {
return false;
}There was a problem hiding this comment.
Good catch—updated ParseIpv6 to validate all hex groups and reject overflowing or malformed IPv6 addresses as "unknown".
Replied by cpriti-o11y-agent
| {"", "unknown"}, | ||
| {"unix:/tmp/sock", "unknown"}, | ||
| {"not-an-ip", "unknown"}, | ||
| {"ipv4:999.0.0.1:443", "unknown"}, |
There was a problem hiding this comment.
Added test cases for overflowing and malformed IPv6 addresses (as well as percent-encoded gRPC IPv6 peers and zone IDs).
Replied by cpriti-o11y-agent
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #16683 +/- ##
==========================================
+ Coverage 92.73% 92.75% +0.01%
==========================================
Files 2271 2273 +2
Lines 226963 227118 +155
==========================================
+ Hits 210476 210660 +184
+ Misses 16487 16458 -29 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| } // namespace | ||
|
|
||
| std::string NormalizeServerAddress(std::string_view endpoint) { | ||
| std::size_t const scheme_pos = endpoint.find("://"); |
There was a problem hiding this comment.
Matching only "://" here (and only dns, google-c2p, and google-c2p-experimental below) mishandles valid gRPC name-resolution targets without // or under xds:///. For example, dns:storage.googleapis.com normalizes to "dns", dns:storage.googleapis.com:443 stays unchanged, and xds:///storage.googleapis.com becomes "".
There was a problem hiding this comment.
Good catch, added xds to the scheme://[authority]/target list and handled dns:host[:port] without //, with test cases for both.
Replied by cpriti-o11y-agent
| {"ipv6:[2001:4860:8040:]:443", "unknown"}, | ||
| {"ipv6:[2001:4860:8040::1", "unknown"}, | ||
| {"2001::4860::1", "unknown"}, | ||
| {":::", "unknown"}, |
There was a problem hiding this comment.
The "unknown" cases ending here miss the unclosed %5B branch in UnwrapBrackets (the one uncovered line in Codecov) and several parser guards. Dropping res.ptr == end in ParseUint, the 8-group bounds check in ParseIpv6Half, or the head_count group-count checks in ParseIpv6 would still leave this test green.
There was a problem hiding this comment.
Added "unknown" cases covering unclosed %5B, trailing non-numeric characters, too many IPv6 groups, and too few IPv6 groups without ::.
Replied by cpriti-o11y-agent
|
|
||
| bool ParseIpv6(std::string_view ip, bool& is_directpath) { | ||
| if (!absl::StrContains(ip, ':')) return false; | ||
| if (absl::StartsWithIgnoreCase(ip, "::ffff:") && |
There was a problem hiding this comment.
This "::ffff:" check only unmaps compressed dotted-quad IPv4-mapped addresses, so hex forms like ipv6:[::ffff:227e:1]:443 or 0:0:0:0:0:ffff:227e:1 (34.126.0.1) classify as "cloudpath" instead of "directpath".
Can we combine head and tail into one 8-group array and check groups[0..4] == 0 && groups[5] == 0xffff against 34.126.0.0/18 as well (leaving ::ffff:1 as "cloudpath")?
There was a problem hiding this comment.
Good idea, combined head and tail into one 8-group array and checked groups[0..4] == 0 && groups[5] == 0xffff against 34.126.0.0/18, with tests for ::ffff:227e:1 and 0:0:0:0:0:ffff:227e:1.
Replied by cpriti-o11y-agent
| "storage.googleapis.com"}, | ||
| {"https://storage.us-central1.rep.googleapis.com", | ||
| "storage.us-central1.rep.googleapis.com"}, | ||
| {"https://storage.googleapis.com/path#frag", "storage.googleapis.com"}, |
There was a problem hiding this comment.
nit: in "https://storage.googleapis.com/path#frag", find_first_of("/?#") stops at '/' before reaching '#', so removing '#' from metrics_attributes.cc would still pass this test.
There was a problem hiding this comment.
Good catch, updated the test input to "https://storage.googleapis.com#frag" so # is actually exercised.
Replied by cpriti-o11y-agent
| {"ipv6:[::FfFf:34.126.0.1]:443", "directpath"}, | ||
| {"ipv4:34.125.255.255:443", "cloudpath"}, | ||
| {"ipv4:34.126.64.0:443", "cloudpath"}, | ||
| {"ipv4:142.250.190.78:443", "cloudpath"}, |
There was a problem hiding this comment.
Rows like this one differ from the DirectPath ranges in several groups at once, so the "cloudpath" cases have no near-miss on the leading prefix. Dropping the octets[0] == 34, head[0] == 0x2001 or head[1] == 0x4860 comparison in metrics_attributes.cc still passes every row.
Consider adding "ipv4:35.126.0.1:443", "ipv6:[2002:4860:8040::1]:443" and "ipv6:[2001:4861:8040::1]:443" as "cloudpath" cases.
There was a problem hiding this comment.
Added "ipv4:35.126.0.1:443", "ipv6:[2002:4860:8040::1]:443", and "ipv6:[2001:4861:8040::1]:443" as "cloudpath" cases.
Replied by cpriti-o11y-agent
| return res.ec == std::errc{} && res.ptr == end; | ||
| } | ||
|
|
||
| bool ParseIpv4(std::string_view ip, bool& is_directpath) { |
There was a problem hiding this comment.
ParseIpv4 and ParseIpv6 report validity through the return value and the classification through a bool& output parameter. The Google C++ style guide prefers return values over output parameters.
Consider returning std::optional<bool>, with std::nullopt meaning "not an IP address".
There was a problem hiding this comment.
Updated ParseIpv4 and ParseIpv6 to return std::optional<bool> instead of using a bool& output parameter.
Replied by cpriti-o11y-agent
There was a problem hiding this comment.
Running all cases in a loop inside TEST(MetricsAttributes, NetworkPathOfPeer) (and NormalizeServerAddress) collapses failures into a single test result. CI summaries cannot show which or how many cases broke without opening the log, and individual cases cannot be run with --gtest_filter.
Consider converting these to TEST_P suites so each case surfaces and filters independently.
There was a problem hiding this comment.
Converted both table tests to TEST_P suites so each case reports and filters independently.
Replied by cpriti-o11y-agent
Adds internal attribute normalization helpers for Google Cloud Storage OpenTelemetry client metrics:
storage_internal::NormalizeServerAddress(std::string_view): normalizes a configured endpoint into theserver.addressattribute by stripping URI schemes (https://,dns:///,google-c2p:///, etc.), paths/queries, IPv6 brackets, and trailing:port.storage_internal::NetworkPathOfPeer(std::string_view): classifies a gRPC peer URI or IP literal into"directpath"(34.126.0.0/18,2001:4860:8040::/42),"cloudpath", or"unknown"for thenetwork.pathattribute.This PR adds the internal helpers and unit tests; metric instrument wiring lands in follow-up PRs.
Created by cpriti-o11y-agent