-
Notifications
You must be signed in to change notification settings - Fork 460
feat(storage): add resource span attributes for ACO ( App Centric Observability ) for async client #16151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bajajneha27
wants to merge
21
commits into
googleapis:main
Choose a base branch
from
bajajneha27:509338299-async
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(storage): add resource span attributes for ACO ( App Centric Observability ) for async client #16151
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
e78f737
feat(storage): add resource span attributes ACO ( App Centric Observa…
bajajneha27 7add0c0
Adding LRU cache and span attributes to other bucket and object opera…
bajajneha27 25f555c
fix ci failures
bajajneha27 b0bd6c2
fix ci failures
bajajneha27 56024fd
fix ci failures
bajajneha27 f340a84
fix ci failures
bajajneha27 5fce21f
fix ci failures
bajajneha27 4f450da
fix ci failures
bajajneha27 5f1df5e
move BucketMetadataCache to separate file
bajajneha27 894b039
more refactoring
bajajneha27 3153e60
more refactoring
bajajneha27 fa97dd5
feat(storage): add resource span attributes for ACO ( App Centric Obs…
bajajneha27 2046b9d
fix ci failure
bajajneha27 945df69
Refactoring
bajajneha27 b57eba8
sync changes
bajajneha27 377cf3c
refactor and remove unnecessary code
bajajneha27 ce5fcaf
fix ci failure
bajajneha27 6d490c3
rebase with main branch
bajajneha27 6f939a6
fix ci failure
bajajneha27 8834436
Add tests
bajajneha27 ab7a6df
address review comments
bajajneha27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,12 +18,21 @@ | |
| #include "google/cloud/storage/internal/async/reader_connection_tracing.h" | ||
| #include "google/cloud/storage/internal/async/rewriter_connection_tracing.h" | ||
| #include "google/cloud/storage/internal/async/writer_connection_tracing.h" | ||
| #include "google/cloud/storage/internal/bucket_metadata_cache.h" | ||
| #include "google/cloud/storage/options.h" | ||
| #include "google/cloud/internal/opentelemetry.h" | ||
| #include "google/cloud/version.h" | ||
| #include "google/storage/v2/storage.pb.h" | ||
| #include <algorithm> | ||
| #include <chrono> | ||
| #include <future> | ||
| #include <memory> | ||
| #include <mutex> | ||
| #include <vector> | ||
|
|
||
| namespace google { | ||
| namespace cloud { | ||
|
|
||
| namespace storage_internal { | ||
| GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN | ||
|
|
||
|
|
@@ -33,20 +42,18 @@ class AsyncConnectionTracing : public storage::AsyncConnection { | |
| public: | ||
| explicit AsyncConnectionTracing( | ||
| std::shared_ptr<storage::AsyncConnection> impl) | ||
| : impl_(std::move(impl)) {} | ||
| : impl_(std::move(impl)), | ||
| cache_(std::make_shared<BucketMetadataCache>()) {} | ||
|
|
||
| Options options() const override { return impl_->options(); } | ||
| ~AsyncConnectionTracing() override = default; | ||
|
|
||
| future<StatusOr<google::storage::v2::Bucket>> GetBucket( | ||
| GetBucketParams p) override { | ||
| auto span = internal::MakeSpan("storage::AsyncConnection::GetBucket"); | ||
| internal::OTelScope scope(span); | ||
| return internal::EndSpan(std::move(span), impl_->GetBucket(std::move(p))); | ||
| } | ||
| Options options() const override { return impl_->options(); } | ||
|
|
||
| future<StatusOr<google::storage::v2::Object>> InsertObject( | ||
| InsertObjectParams p) override { | ||
| auto span = internal::MakeSpan("storage::AsyncConnection::InsertObject"); | ||
| EnrichSpan(*span, p.options, | ||
| p.request.write_object_spec().resource().bucket()); | ||
| internal::OTelScope scope(span); | ||
| return internal::EndSpan(std::move(span), | ||
| impl_->InsertObject(std::move(p))); | ||
|
|
@@ -55,6 +62,7 @@ class AsyncConnectionTracing : public storage::AsyncConnection { | |
| future<StatusOr<std::shared_ptr<storage::ObjectDescriptorConnection>>> Open( | ||
| OpenParams p) override { | ||
| auto span = internal::MakeSpan("storage::AsyncConnection::Open"); | ||
| EnrichSpan(*span, p.options, p.read_spec.bucket()); | ||
| internal::OTelScope scope(span); | ||
| return impl_->Open(std::move(p)) | ||
| .then([oc = opentelemetry::context::RuntimeContext::GetCurrent(), | ||
|
|
@@ -74,13 +82,16 @@ class AsyncConnectionTracing : public storage::AsyncConnection { | |
| future<StatusOr<std::unique_ptr<storage::AsyncReaderConnection>>> ReadObject( | ||
| ReadObjectParams p) override { | ||
| auto span = internal::MakeSpan("storage::AsyncConnection::ReadObject"); | ||
| EnrichSpan(*span, p.options, p.request.bucket()); | ||
| internal::OTelScope scope(span); | ||
| auto wrap = [oc = opentelemetry::context::RuntimeContext::GetCurrent(), | ||
| span = std::move(span)](auto f) | ||
| -> StatusOr<std::unique_ptr<storage::AsyncReaderConnection>> { | ||
| auto reader = f.get(); | ||
| internal::DetachOTelContext(oc); | ||
| if (!reader) return internal::EndSpan(*span, std::move(reader).status()); | ||
| if (!reader) { | ||
| return internal::EndSpan(*span, std::move(reader).status()); | ||
| } | ||
| return MakeTracingReaderConnection(std::move(span), *std::move(reader)); | ||
| }; | ||
| return impl_->ReadObject(std::move(p)).then(std::move(wrap)); | ||
|
|
@@ -89,28 +100,28 @@ class AsyncConnectionTracing : public storage::AsyncConnection { | |
| future<StatusOr<storage::ReadPayload>> ReadObjectRange( | ||
| ReadObjectParams p) override { | ||
| auto span = internal::MakeSpan("storage::AsyncConnection::ReadObjectRange"); | ||
| EnrichSpan(*span, p.options, p.request.bucket()); | ||
| internal::OTelScope scope(span); | ||
| return impl_->ReadObjectRange(std::move(p)) | ||
| .then([oc = opentelemetry::context::RuntimeContext::GetCurrent(), | ||
| span = std::move(span)](auto f) { | ||
| auto result = f.get(); | ||
| internal::DetachOTelContext(oc); | ||
| return internal::EndSpan(*span, std::move(result)); | ||
| }); | ||
| return internal::EndSpan(std::move(span), | ||
| impl_->ReadObjectRange(std::move(p))); | ||
| } | ||
|
|
||
| future<StatusOr<std::unique_ptr<storage::AsyncWriterConnection>>> | ||
| StartAppendableObjectUpload(AppendableUploadParams p) override { | ||
| auto span = internal::MakeSpan( | ||
| "storage::AsyncConnection::StartAppendableObjectUpload"); | ||
| EnrichSpan(*span, p.options, | ||
| p.request.write_object_spec().resource().bucket()); | ||
| internal::OTelScope scope(span); | ||
| return impl_->StartAppendableObjectUpload(std::move(p)) | ||
| .then([oc = opentelemetry::context::RuntimeContext::GetCurrent(), | ||
| span = std::move(span)](auto f) | ||
| -> StatusOr<std::unique_ptr<storage::AsyncWriterConnection>> { | ||
| auto w = f.get(); | ||
| internal::DetachOTelContext(oc); | ||
| if (!w) return internal::EndSpan(*span, std::move(w).status()); | ||
| if (!w) { | ||
| return internal::EndSpan(*span, std::move(w).status()); | ||
| } | ||
| return MakeTracingWriterConnection(span, *std::move(w)); | ||
| }); | ||
| } | ||
|
|
@@ -119,14 +130,18 @@ class AsyncConnectionTracing : public storage::AsyncConnection { | |
| ResumeAppendableObjectUpload(AppendableUploadParams p) override { | ||
| auto span = internal::MakeSpan( | ||
| "storage::AsyncConnection::ResumeAppendableObjectUpload"); | ||
| EnrichSpan(*span, p.options, | ||
| p.request.write_object_spec().resource().bucket()); | ||
| internal::OTelScope scope(span); | ||
| return impl_->ResumeAppendableObjectUpload(std::move(p)) | ||
| .then([oc = opentelemetry::context::RuntimeContext::GetCurrent(), | ||
| span = std::move(span)](auto f) | ||
| -> StatusOr<std::unique_ptr<storage::AsyncWriterConnection>> { | ||
| auto w = f.get(); | ||
| internal::DetachOTelContext(oc); | ||
| if (!w) return internal::EndSpan(*span, std::move(w).status()); | ||
| if (!w) { | ||
| return internal::EndSpan(*span, std::move(w).status()); | ||
| } | ||
| return MakeTracingWriterConnection(span, *std::move(w)); | ||
| }); | ||
| } | ||
|
|
@@ -135,14 +150,18 @@ class AsyncConnectionTracing : public storage::AsyncConnection { | |
| StartUnbufferedUpload(UploadParams p) override { | ||
| auto span = | ||
| internal::MakeSpan("storage::AsyncConnection::StartUnbufferedUpload"); | ||
| EnrichSpan(*span, p.options, | ||
| p.request.write_object_spec().resource().bucket()); | ||
| internal::OTelScope scope(span); | ||
| return impl_->StartUnbufferedUpload(std::move(p)) | ||
| .then([oc = opentelemetry::context::RuntimeContext::GetCurrent(), | ||
| span = std::move(span)](auto f) | ||
| -> StatusOr<std::unique_ptr<storage::AsyncWriterConnection>> { | ||
| auto w = f.get(); | ||
| internal::DetachOTelContext(oc); | ||
| if (!w) return internal::EndSpan(*span, std::move(w).status()); | ||
| if (!w) { | ||
| return internal::EndSpan(*span, std::move(w).status()); | ||
| } | ||
| return MakeTracingWriterConnection(span, *std::move(w)); | ||
| }); | ||
| } | ||
|
|
@@ -151,14 +170,18 @@ class AsyncConnectionTracing : public storage::AsyncConnection { | |
| StartBufferedUpload(UploadParams p) override { | ||
| auto span = | ||
| internal::MakeSpan("storage::AsyncConnection::StartBufferedUpload"); | ||
| EnrichSpan(*span, p.options, | ||
| p.request.write_object_spec().resource().bucket()); | ||
| internal::OTelScope scope(span); | ||
| return impl_->StartBufferedUpload(std::move(p)) | ||
| .then([oc = opentelemetry::context::RuntimeContext::GetCurrent(), | ||
| span = std::move(span)](auto f) | ||
| -> StatusOr<std::unique_ptr<storage::AsyncWriterConnection>> { | ||
| auto w = f.get(); | ||
| internal::DetachOTelContext(oc); | ||
| if (!w) return internal::EndSpan(*span, std::move(w).status()); | ||
| if (!w) { | ||
| return internal::EndSpan(*span, std::move(w).status()); | ||
| } | ||
| return MakeTracingWriterConnection(span, *std::move(w)); | ||
| }); | ||
| } | ||
|
|
@@ -198,13 +221,15 @@ class AsyncConnectionTracing : public storage::AsyncConnection { | |
| future<StatusOr<google::storage::v2::Object>> ComposeObject( | ||
| ComposeObjectParams p) override { | ||
| auto span = internal::MakeSpan("storage::AsyncConnection::ComposeObject"); | ||
| EnrichSpan(*span, p.options, p.request.destination().bucket()); | ||
| internal::OTelScope scope(span); | ||
| return internal::EndSpan(std::move(span), | ||
| impl_->ComposeObject(std::move(p))); | ||
| } | ||
|
|
||
| future<Status> DeleteObject(DeleteObjectParams p) override { | ||
| auto span = internal::MakeSpan("storage::AsyncConnection::DeleteObject"); | ||
| EnrichSpan(*span, p.options, p.request.bucket()); | ||
| internal::OTelScope scope(span); | ||
| return internal::EndSpan(std::move(span), | ||
| impl_->DeleteObject(std::move(p))); | ||
|
|
@@ -217,8 +242,103 @@ class AsyncConnectionTracing : public storage::AsyncConnection { | |
| impl_->RewriteObject(std::move(p)), enabled); | ||
| } | ||
|
|
||
| future<StatusOr<google::storage::v2::Bucket>> GetBucket( | ||
| GetBucketParams p) override { | ||
| auto span = internal::MakeSpan("storage::AsyncConnection::GetBucket"); | ||
| internal::OTelScope scope(span); | ||
| auto const bucket_name = p.request.name(); | ||
| auto const options = p.options; | ||
| return impl_->GetBucket(std::move(p)) | ||
| .then([oc = opentelemetry::context::RuntimeContext::GetCurrent(), | ||
| span = std::move(span), cache = cache_, bucket_name, | ||
| options](future<StatusOr<google::storage::v2::Bucket>> f) | ||
| -> StatusOr<google::storage::v2::Bucket> { | ||
| auto result = f.get(); | ||
| internal::DetachOTelContext(oc); | ||
| if (result.ok()) { | ||
| EnrichSpan(*span, options, *result, bucket_name, *cache); | ||
| } else { | ||
| cache->MaybeInvalidate(result, bucket_name); | ||
| } | ||
| return internal::EndSpan(*span, std::move(result)); | ||
| }); | ||
| } | ||
|
|
||
| private: | ||
| BucketMetadataCache& cache() const { return *cache_; } | ||
|
|
||
| void MaybeTriggerBackgroundFetch(Options const& options, | ||
| std::string const& bucket_name) { | ||
| if (!cache().StartFetch(bucket_name)) { | ||
| return; | ||
| } | ||
|
|
||
| auto guard = ScopedFetch(cache_, bucket_name); | ||
| google::storage::v2::GetBucketRequest request; | ||
| auto const normalized_bucket_name = | ||
| BucketMetadataCache::NormalizeBucketName(bucket_name); | ||
| request.set_name("projects/_/buckets/" + normalized_bucket_name); | ||
| GetBucketParams params{std::move(request), options}; | ||
|
|
||
| impl_->GetBucket(std::move(params)) | ||
| .then([cache = cache_, bucket_name, guard = std::move(guard)]( | ||
| future<StatusOr<google::storage::v2::Bucket>> f) { | ||
| auto metadata = f.get(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: pls spell out the type for readability. |
||
| if (metadata.ok()) { | ||
| BucketCacheEntry entry = BucketCacheEntry::FromLocation( | ||
| metadata->project() + "/buckets/" + | ||
| BucketMetadataCache::NormalizeBucketName(bucket_name), | ||
| metadata->location(), metadata->location_type()); | ||
| cache->Put(bucket_name, std::move(entry)); | ||
| } else if (metadata.status().code() == | ||
| StatusCode::kPermissionDenied) { | ||
| BucketCacheEntry entry{ | ||
| "projects/_/buckets/" + | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: let's make this a class-level constant? |
||
| BucketMetadataCache::NormalizeBucketName(bucket_name), | ||
| "global"}; | ||
| cache->Put(bucket_name, std::move(entry)); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| static void EnrichSpan(opentelemetry::trace::Span& span, | ||
| BucketCacheEntry const& entry) { | ||
| span.SetAttribute("gcp.resource.destination.id", entry.id); | ||
| span.SetAttribute("gcp.resource.destination.location", entry.location); | ||
| } | ||
|
|
||
| static void EnrichSpan(opentelemetry::trace::Span& span, | ||
| Options const& options, | ||
| google::storage::v2::Bucket const& bucket, | ||
| std::string const& bucket_name, | ||
| BucketMetadataCache& cache) { | ||
| auto const enabled = options.get< | ||
| google::cloud::storage_experimental::OTelSpanEnrichmentOption>(); | ||
| if (!enabled) return; | ||
| auto entry = BucketCacheEntry::FromLocation( | ||
| bucket.project() + "/buckets/" + | ||
| BucketMetadataCache::NormalizeBucketName(bucket_name), | ||
| bucket.location(), bucket.location_type()); | ||
| EnrichSpan(span, entry); | ||
| cache.Put(bucket_name, std::move(entry)); | ||
| } | ||
|
|
||
| void EnrichSpan(opentelemetry::trace::Span& span, Options const& options, | ||
| std::string const& bucket_name) { | ||
| if (bucket_name.empty()) return; | ||
| auto const enabled = options.get< | ||
| google::cloud::storage_experimental::OTelSpanEnrichmentOption>(); | ||
| if (!enabled) return; | ||
| auto entry = cache().Get(bucket_name); | ||
| if (entry.has_value()) { | ||
| EnrichSpan(span, *entry); | ||
| } else { | ||
| MaybeTriggerBackgroundFetch(options, bucket_name); | ||
| } | ||
| } | ||
|
|
||
| std::shared_ptr<storage::AsyncConnection> impl_; | ||
| std::shared_ptr<BucketMetadataCache> cache_; | ||
| }; | ||
|
|
||
| } // namespace | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.