-
Notifications
You must be signed in to change notification settings - Fork 460
feat(storage): add resource span attributes for ACO ( App Centric Observability ) #16119
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
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
3822bf4
feat: create a generic wrapper for gRPC and REST pure background thre…
bajajneha27 063b9c8
add unit tests and address review comments
bajajneha27 60d2c0f
feat(storage): add resource span attributes ACO ( App Centric Observa…
bajajneha27 3c08a7a
Adding LRU cache and span attributes to other bucket and object opera…
bajajneha27 c26f3f1
fix ci failures
bajajneha27 aa61af9
fix ci failures
bajajneha27 779609f
fix ci failures
bajajneha27 9d3fa0e
fix ci failures
bajajneha27 d1479b2
fix ci failures
bajajneha27 ea1f6ba
fix ci failures
bajajneha27 c10e1cc
move BucketMetadataCache to separate file
bajajneha27 7a4c3b0
add unit tests for bucket_metdata_cache
bajajneha27 6e547d8
more refactoring
bajajneha27 4712919
more refactoring
bajajneha27 2b5beb8
address review comments
bajajneha27 f55343d
address review comments
bajajneha27 abcf751
ci failure fix
bajajneha27 649e148
fix ci failure
bajajneha27 8f40bb5
using completetion_queue to run background threads
bajajneha27 dfba6bb
use generic+background_thread
bajajneha27 e1238c6
Address review comments
bajajneha27 d2e3d03
removing unnecessary code
bajajneha27 f444568
rebase with latest code
bajajneha27 b36e6bb
address review comments
bajajneha27 62a12bb
More code changes to prevent use-after-free
bajajneha27 a1fb18d
do not clear in_flight_fetch_ while clearing cache
bajajneha27 bcede29
address review comment
bajajneha27 210b1ab
rebase with main branch and resolve merge conflict
bajajneha27 98472b5
fix ci failures
bajajneha27 fb53265
Rebase with main branch
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
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
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
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
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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include "google/cloud/storage/internal/bucket_metadata_cache.h" | ||
| #include "google/cloud/storage/bucket_metadata.h" | ||
| #include <mutex> | ||
| #include <utility> | ||
|
|
||
| namespace google { | ||
| namespace cloud { | ||
| namespace storage_internal { | ||
| GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN | ||
|
|
||
| BucketCacheEntry BucketCacheEntry::FromMetadata( | ||
| storage::BucketMetadata const& m) { | ||
| std::string loc = m.location(); | ||
| if (m.location_type() == "multi-region" || | ||
| m.location_type() == "dual-region") { | ||
| loc = "global"; | ||
| } | ||
| return { | ||
| "projects/" + std::to_string(m.project_number()) + "/buckets/" + m.name(), | ||
| std::move(loc)}; | ||
| } | ||
|
|
||
| void BucketMetadataCache::MoveToFront(std::list<std::string>::iterator it) { | ||
| list_.splice(list_.begin(), list_, it); | ||
| } | ||
|
|
||
| absl::optional<BucketCacheEntry> BucketMetadataCache::Get( | ||
| std::string const& bucket_name) { | ||
| std::unique_lock<std::mutex> lk(mu_); | ||
| auto it = map_.find(bucket_name); | ||
| if (it == map_.end()) return absl::nullopt; | ||
|
|
||
| MoveToFront(it->second.second); | ||
| return it->second.first; | ||
| } | ||
|
|
||
| void BucketMetadataCache::Put(std::string const& bucket_name, | ||
| BucketCacheEntry entry) { | ||
| if (max_size_ == 0) return; | ||
| std::unique_lock<std::mutex> lk(mu_); | ||
| auto it = map_.find(bucket_name); | ||
| if (it != map_.end()) { | ||
| it->second.first = std::move(entry); | ||
| MoveToFront(it->second.second); | ||
| return; | ||
| } | ||
|
|
||
| if (map_.size() >= max_size_ && !list_.empty()) { | ||
| auto oldest = list_.back(); | ||
| list_.pop_back(); | ||
| map_.erase(oldest); | ||
| } | ||
|
|
||
| list_.push_front(bucket_name); | ||
| map_[bucket_name] = {std::move(entry), list_.begin()}; | ||
| } | ||
|
|
||
| void BucketMetadataCache::Invalidate(std::string const& bucket_name) { | ||
| std::unique_lock<std::mutex> lk(mu_); | ||
| auto it = map_.find(bucket_name); | ||
| if (it != map_.end()) { | ||
| list_.erase(it->second.second); | ||
| map_.erase(it); | ||
| } | ||
| } | ||
|
|
||
| void BucketMetadataCache::Clear() { | ||
| std::unique_lock<std::mutex> lk(mu_); | ||
| map_.clear(); | ||
| list_.clear(); | ||
| } | ||
|
|
||
| bool BucketMetadataCache::StartFetch(std::string const& bucket_name) { | ||
| std::unique_lock<std::mutex> lk(mu_); | ||
| if (in_flight_fetch_.find(bucket_name) != in_flight_fetch_.end()) { | ||
| return false; | ||
| } | ||
| in_flight_fetch_.insert(bucket_name); | ||
| return true; | ||
| } | ||
|
|
||
| void BucketMetadataCache::EndFetch(std::string const& bucket_name) { | ||
| std::unique_lock<std::mutex> lk(mu_); | ||
| in_flight_fetch_.erase(bucket_name); | ||
| } | ||
|
|
||
| GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END | ||
| } // namespace storage_internal | ||
| } // namespace cloud | ||
| } // namespace google |
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 |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_BUCKET_METADATA_CACHE_H | ||
| #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_BUCKET_METADATA_CACHE_H | ||
|
|
||
| #include "google/cloud/storage/version.h" | ||
| #include "absl/types/optional.h" | ||
| #include <cstddef> | ||
| #include <list> | ||
| #include <memory> | ||
| #include <mutex> | ||
| #include <string> | ||
| #include <unordered_map> | ||
| #include <unordered_set> | ||
| #include <utility> | ||
|
|
||
| namespace google { | ||
| namespace cloud { | ||
| namespace storage { | ||
| GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN | ||
| class BucketMetadata; | ||
| GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END | ||
| } // namespace storage | ||
| namespace storage_internal { | ||
| GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN | ||
|
|
||
| struct BucketCacheEntry { | ||
| std::string id; | ||
| std::string location; | ||
|
|
||
| static BucketCacheEntry FromMetadata(storage::BucketMetadata const& m); | ||
| }; | ||
|
|
||
| class BucketMetadataCache { | ||
| public: | ||
| explicit BucketMetadataCache(std::size_t max_size = 10000) | ||
|
bajajneha27 marked this conversation as resolved.
|
||
| : max_size_(max_size) {} | ||
|
|
||
| absl::optional<BucketCacheEntry> Get(std::string const& bucket_name); | ||
| void Put(std::string const& bucket_name, BucketCacheEntry entry); | ||
| void Invalidate(std::string const& bucket_name); | ||
| void Clear(); | ||
| bool StartFetch(std::string const& bucket_name); | ||
| void EndFetch(std::string const& bucket_name); | ||
|
|
||
| private: | ||
| void MoveToFront(std::list<std::string>::iterator it); | ||
|
|
||
| std::size_t max_size_; | ||
| std::mutex mu_; | ||
| std::list<std::string> list_; | ||
| std::unordered_map<std::string, std::pair<BucketCacheEntry, | ||
| std::list<std::string>::iterator>> | ||
| map_; | ||
| std::unordered_set<std::string> in_flight_fetch_; | ||
| }; | ||
|
|
||
| // Tracks an in-flight fetch and clears it when destroyed. | ||
| class ScopedFetch { | ||
| public: | ||
| ScopedFetch() = default; | ||
| // Shared ownership of BucketMetadataCache keeps the cache alive during async | ||
| // callbacks and ensures ScopedFetch remains copyable for lambda captures. | ||
| ScopedFetch(std::shared_ptr<BucketMetadataCache> cache, | ||
|
bajajneha27 marked this conversation as resolved.
|
||
| std::string bucket_name) | ||
| : state_(std::make_shared<State>(std::move(cache), | ||
| std::move(bucket_name))) {} | ||
|
|
||
| private: | ||
| struct State { | ||
| State(std::shared_ptr<BucketMetadataCache> c, std::string b) | ||
| : cache(std::move(c)), bucket_name(std::move(b)) {} | ||
| ~State() { | ||
| if (cache) cache->EndFetch(bucket_name); | ||
| } | ||
| std::shared_ptr<BucketMetadataCache> cache; | ||
| std::string bucket_name; | ||
| }; | ||
| std::shared_ptr<State> state_; | ||
| }; | ||
|
|
||
| GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END | ||
| } // namespace storage_internal | ||
| } // namespace cloud | ||
| } // namespace google | ||
|
|
||
| #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_BUCKET_METADATA_CACHE_H | ||
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.