fix(storage): add App Hub storage.googleapis.com prefix to destination.id - #16480
Conversation
There was a problem hiding this comment.
Code Review
This pull request prepends the '//storage.googleapis.com/' prefix to bucket resource IDs in the connection tracing and bucket metadata cache implementations, and updates the corresponding unit tests. However, several mock setups in connection_tracing_test.cc incorrectly add this prefix to the project field of the mock Bucket metadata. Since the implementation already prepends the prefix, this results in a double prefix during execution. These mock values should be reverted to match the actual GCS gRPC API behavior, which returns the project field without the prefix.
| auto res1 = connection->GetBucket({req, options}).then(expect_no_context); | ||
| google::storage::v2::Bucket bucket_meta; | ||
| bucket_meta.set_project("projects/123456"); | ||
| bucket_meta.set_project("//storage.googleapis.com/projects/123456"); |
There was a problem hiding this comment.
The GCS gRPC API returns the project field in the format projects/{project_id} or projects/{project_number} (without the //storage.googleapis.com/ prefix). Changing this mock response to include the prefix is incorrect and does not reflect real-world behavior. Furthermore, since connection_tracing.cc prepends //storage.googleapis.com/ to metadata->project(), setting this to a prefixed value in the test will result in a double prefix (//storage.googleapis.com///storage.googleapis.com/projects/123456/...) during execution, which would cause the test assertion to fail. Please revert this change to keep the mock response aligned with the actual API behavior.
bucket_meta.set_project("projects/123456");|
|
||
| google::storage::v2::Bucket bucket_meta; | ||
| bucket_meta.set_project("projects/123456"); | ||
| bucket_meta.set_project("//storage.googleapis.com/projects/123456"); |
There was a problem hiding this comment.
The GCS gRPC API returns the project field in the format projects/{project_id} or projects/{project_number} (without the //storage.googleapis.com/ prefix). Changing this mock response to include the prefix is incorrect and does not reflect real-world behavior. Furthermore, since connection_tracing.cc prepends //storage.googleapis.com/ to metadata->project(), setting this to a prefixed value in the test will result in a double prefix (//storage.googleapis.com///storage.googleapis.com/projects/123456/...) during execution, which would cause the test assertion to fail. Please revert this change to keep the mock response aligned with the actual API behavior.
bucket_meta.set_project("projects/123456");| actual->GetBucket({bucket_req, options}).then(expect_no_context); | ||
| google::storage::v2::Bucket bucket_meta; | ||
| bucket_meta.set_project("projects/123456"); | ||
| bucket_meta.set_project("//storage.googleapis.com/projects/123456"); |
There was a problem hiding this comment.
The GCS gRPC API returns the project field in the format projects/{project_id} or projects/{project_number} (without the //storage.googleapis.com/ prefix). Changing this mock response to include the prefix is incorrect and does not reflect real-world behavior. Furthermore, since connection_tracing.cc prepends //storage.googleapis.com/ to metadata->project(), setting this to a prefixed value in the test will result in a double prefix (//storage.googleapis.com///storage.googleapis.com/projects/123456/...) during execution, which would cause the test assertion to fail. Please revert this change to keep the mock response aligned with the actual API behavior.
bucket_meta.set_project("projects/123456");
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #16480 +/- ##
=======================================
Coverage 92.34% 92.35%
=======================================
Files 2262 2262
Lines 217173 217207 +34
=======================================
+ Hits 200549 200591 +42
+ Misses 16624 16616 -8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
0183592 to
7c16336
Compare
| if (!enabled) return; | ||
| auto entry = BucketCacheEntry::FromLocation( | ||
| bucket.project() + "/buckets/" + | ||
| std::string(kResourceNamePrefix) + bucket.project() + "/buckets/" + |
There was a problem hiding this comment.
If bucket.project() (or metadata->project() above) is empty, this string concatenation produces "//storage.googleapis.com//buckets/" without a projects/_ segment.
Should we fall back to "projects/_" whenever the project string is empty or m.project_number() == 0?
There was a problem hiding this comment.
Good catch. Done: BucketCacheEntry::ResourceName() now falls back to projects/_ when the project is empty, and FromMetadata does the same when project_number() == 0. Added tests.
| return FromLocation( | ||
| "projects/" + std::to_string(m.project_number()) + "/buckets/" + m.name(), | ||
| m.location(), m.location_type()); | ||
| return FromLocation("//storage.googleapis.com/projects/" + |
There was a problem hiding this comment.
nit: constructing this resource ID (and its "projects/_" fallback on kPermissionDenied) is now duplicated across 3 non-test files (bucket_metadata_cache.cc, tracing_connection.cc, and async/connection_tracing.cc).
Can we centralize this formatting in BucketCacheEntry to keep the sync and async implementations consistent?
There was a problem hiding this comment.
Done. Resource name construction now lives in BucketCacheEntry::ResourceName() / FromUnknownProject(), used by both the sync and async paths.
| static constexpr char kProjectBucketPrefix[] = "projects/_/buckets/"; | ||
| static constexpr char kGlobalLocation[] = "global"; | ||
| // The App Hub / Cloud Asset Inventory full resource name prefix. | ||
| static constexpr char kResourceNamePrefix[] = "//storage.googleapis.com/"; |
There was a problem hiding this comment.
nit: consider moving kResourceNamePrefix to bucket_metadata_cache.h (or BucketCacheEntry) and reusing it in bucket_metadata_cache.cc and tracing_connection.cc.
There was a problem hiding this comment.
Done. Moved to kStorageResourceNamePrefix in bucket_metadata_cache.h and reused via BucketCacheEntry::ResourceName().
Move the //storage.googleapis.com/ prefix and bucket resource name construction into BucketCacheEntry so the sync and async tracing paths share one implementation. Fall back to projects/_ when the project is empty or the project number is 0.
5c31d91 to
827a75a
Compare
Cloud Trace''s App Hub URI extractor requires a full resource name of the form
//storage.googleapis.com/projects/{project}/buckets/{bucket}. A bare path likeprojects/{project}/buckets/{bucket}is rejected and the span is silently dropped from App Hub enrichment.This PR adds the
//storage.googleapis.com/prefix togcp.resource.destination.idemitted by the C++ Storage SDK (when OTel Span enrichment is enabled), aligning it with Cloud Trace expectations.