Repository navigation
docs(storagecontrol): add Rapid Cache samples - #16611
sahusneha2004 wants to merge 2 commits into
Conversation
Adds samples for the Storage Control Rapid Cache CRUD APIs: storage_control_create_rapid_cache, storage_control_get_rapid_cache, storage_control_list_rapid_caches, storage_control_update_rapid_cache, storage_control_disable_rapid_cache. Refs b/482946642 [Generated-by: AI]
There was a problem hiding this comment.
Code Review
This pull request introduces code samples for managing Rapid Cache resources in the Google Cloud Storage Control service, including creation, retrieval, listing, updating, and disabling of caches. It also excludes these samples from the integration tests against production due to the long duration required to disable a Rapid Cache. The code review feedback requests replacing several instances of auto type deduction with explicit StatusOr types to comply with the repository's style guide regarding obscured domain and return types.
| // Creating a Rapid Cache is a long-running operation. This example blocks | ||
| // until it completes. Real applications may want to set up a callback, wait | ||
| // on a coroutine, or poll until it completes. | ||
| auto rapid_cache = client.CreateRapidCache(parent, cache).get(); |
There was a problem hiding this comment.
According to the repository style guide, using auto is disallowed when it hides StatusOr<T>, domain objects, or protobuf messages. Please explicitly specify the type google::cloud::StatusOr<google::storage::control::v2::RapidCache>.
google::cloud::StatusOr<google::storage::control::v2::RapidCache>
rapid_cache = client.CreateRapidCache(parent, cache).get();References
- Reject Obscured Domain & Return Types: Flag and reject auto when it hides StatusOr, domain objects, protobuf messages/fields, or function return types. (link)
| std::string const& bucket_name, std::string const& cache_id) { | ||
| auto const name = std::string{"projects/_/buckets/"} + bucket_name + | ||
| "/rapidCaches/" + cache_id; | ||
| auto rapid_cache = client.GetRapidCache(name); |
There was a problem hiding this comment.
According to the repository style guide, using auto is disallowed when it hides StatusOr<T>, domain objects, or protobuf messages. Please explicitly specify the type google::cloud::StatusOr<google::storage::control::v2::RapidCache>.
google::cloud::StatusOr<google::storage::control::v2::RapidCache>
rapid_cache = client.GetRapidCache(name);References
- Reject Obscured Domain & Return Types: Flag and reject auto when it hides StatusOr, domain objects, protobuf messages/fields, or function return types. (link)
| std::string const& bucket_name) { | ||
| auto const parent = std::string{"projects/_/buckets/"} + bucket_name; | ||
| // The returned range fetches additional pages as needed. | ||
| for (auto rapid_cache : client.ListRapidCaches(parent)) { |
There was a problem hiding this comment.
According to the repository style guide, using auto is disallowed when it hides StatusOr<T>, domain objects, or protobuf messages. Please explicitly specify the type google::cloud::StatusOr<google::storage::control::v2::RapidCache>.
for (google::cloud::StatusOr<google::storage::control::v2::RapidCache>
rapid_cache : client.ListRapidCaches(parent)) {References
- Reject Obscured Domain & Return Types: Flag and reject auto when it hides StatusOr, domain objects, protobuf messages/fields, or function return types. (link)
| // Updating a Rapid Cache is a long-running operation. This example blocks | ||
| // until it completes. Real applications may want to set up a callback, wait | ||
| // on a coroutine, or poll until it completes. | ||
| auto rapid_cache = client.UpdateRapidCache(cache, field_mask).get(); |
There was a problem hiding this comment.
According to the repository style guide, using auto is disallowed when it hides StatusOr<T>, domain objects, or protobuf messages. Please explicitly specify the type google::cloud::StatusOr<google::storage::control::v2::RapidCache>.
google::cloud::StatusOr<google::storage::control::v2::RapidCache>
rapid_cache = client.UpdateRapidCache(cache, field_mask).get();References
- Reject Obscured Domain & Return Types: Flag and reject auto when it hides StatusOr, domain objects, protobuf messages/fields, or function return types. (link)
| auto operation = | ||
| client.DisableRapidCache(google::cloud::NoAwaitTag{}, name); |
There was a problem hiding this comment.
According to the repository style guide, using auto is disallowed when it hides StatusOr<T>, domain objects, or protobuf messages. Please explicitly specify the type google::cloud::StatusOr<google::longrunning::Operation>.
google::cloud::StatusOr<google::longrunning::Operation> operation =
client.DisableRapidCache(google::cloud::NoAwaitTag{}, name);References
- Reject Obscured Domain & Return Types: Flag and reject auto when it hides StatusOr, domain objects, protobuf messages/fields, or function return types. (link)
| // cannot be disabled here, and must be disabled manually. | ||
| auto const parent = std::string{"projects/_/buckets/"} + *bucket_name; | ||
| std::string cache_id; | ||
| for (auto cache : client.ListRapidCaches(parent)) { |
There was a problem hiding this comment.
According to the repository style guide, using auto is disallowed when it hides StatusOr<T>, domain objects, or protobuf messages. Please explicitly specify the type google::cloud::StatusOr<google::storage::control::v2::RapidCache>.
for (google::cloud::StatusOr<google::storage::control::v2::RapidCache> cache :
client.ListRapidCaches(parent)) {References
- Reject Obscured Domain & Return Types: Flag and reject auto when it hides StatusOr, domain objects, protobuf messages/fields, or function return types. (link)
| // The cache moves to the "disabled" state shortly after the request. | ||
| auto const name = parent + "/rapidCaches/" + cache_id; | ||
| for (int i = 0; i != 12; ++i) { | ||
| auto cache = client.GetRapidCache(name); |
There was a problem hiding this comment.
According to the repository style guide, using auto is disallowed when it hides StatusOr<T>, domain objects, or protobuf messages. Please explicitly specify the type google::cloud::StatusOr<google::storage::control::v2::RapidCache>.
google::cloud::StatusOr<google::storage::control::v2::RapidCache> cache =
client.GetRapidCache(name);References
- Reject Obscured Domain & Return Types: Flag and reject auto when it hides StatusOr, domain objects, protobuf messages/fields, or function return types. (link)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16611 +/- ##
==========================================
+ Coverage 92.42% 92.46% +0.04%
==========================================
Files 2266 2266
Lines 221667 221667
==========================================
+ Hits 204872 204969 +97
+ Misses 16795 16698 -97 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ation test Set the explicit cache name (ID = zone), cache_type rapid-cache-ultra and ttl 24h on create; wait for the disable LRO; the auto-run asserts running state, cache type, list membership and the updated ttl, and bounds the disable wait. Aligns with googleapis/google-cloud-java#14529. b/482946642 [Generated-by: AI]
Adds C++ samples for the Storage Control Rapid Cache CRUD APIs in
google/cloud/storagecontrol/v2/samples/storage_control_rapid_cache_samples.cc:storage_control_create_rapid_cache(CreateRapidCache,cache_type = "rapid-cache-ultra"; waits for the LRO)storage_control_get_rapid_cachestorage_control_list_rapid_cachesstorage_control_update_rapid_cache(updatesttlvia aFieldMask; waits for the LRO)storage_control_disable_rapid_cache(starts the LRO withNoAwaitTagand does not wait: the cache isdisabledwithin seconds, but the operation only completes once the cache is fully removed, which can take 30+ minutes)Refs b/482946642
Testing / CI notes (please review)
GOOGLE_CLOUD_CPP_STORAGE_TEST_RAPID_CACHE_BUCKET_NAME. Rapid Cache Ultra needs a regional bucket with hierarchical namespace + UBLA in the same region as the cache zone. The shared test buckets don't qualify, and the generatedcc_testfor samples only links//:storagecontrol, soAutoRuncannot create a bucket itself. Following the folder-samples precedent (GOOGLE_CLOUD_CPP_STORAGE_TEST_FOLDER_BUCKET_NAME),AutoRunuses a pre-provisioned bucket and skips gracefully if the variable is unset. Zone:GOOGLE_CLOUD_CPP_STORAGE_TEST_RAPID_CACHE_ZONE, falling back toGOOGLE_CLOUD_CPP_TEST_ZONE, thenus-central1-a.integration-production.sh, like the Anywhere Cache samples: a disabled Rapid Cache takes 30+ minutes to be removed, which blocks back-to-back runs in the same zone and blocks bucket deletion (HTTP 409 "has Rapid Cache Ultra").AutoRundiscovers it viaListRapidCaches(by zone, ignoring disabled caches) instead of assuming it.Validation
clang-formatapplied;bazel buildOK.storage-prober-prelaunch-acv2with a regional HNS+UBLA bucket inus-central1(zoneus-central1-a): create → get → list → update (TTL 172800s) → disable → statedisabled— PASSED.typostool); relying on CI checkers.Alignment with googleapis/google-cloud-java#14529
The samples now follow the API usage in the Java Rapid Cache integration test (
ITRapidCacheTest.java). Where this section conflicts with the notes above, this section wins.Create: sets the cache
nameexplicitly toprojects/_/buckets/{bucket}/rapidCaches/{zone}, because the backend requires the cache ID to equal the zone (CreateRapidCacheRequesthas no ID field). Also setscache_type = "rapid-cache-ultra"andttl = 86400s(24h). Prints the name and state.Get: also prints
cache_type.Disable: now waits for the LRO (
DisableRapidCache(name).get()) instead of usingNoAwaitTag.AutoRun: uses
cache_id = zone, so theListRapidCacheslookup is gone. It checks:state == "running"andcache_typeafter createListRapidCachesttl == 172800safter updateThe disable wait is capped by a 10-minute polling policy. On timeout, AutoRun checks that
GetRapidCachereportsdisabledand does not fail. If an earlier step fails, cleanup sends aNoAwaitTagdisable.Region tags, env-var gating, and the
integration-production.shexclusion are unchanged.Validation (alignment commit):
clang-formatapplied;bazel buildOK. AutoRun ran live once againststorage-prober-prelaunch-acv2with a new regional HNS+UBLA bucket inus-central1(zoneus-central1-a). Create, get, list and update (TTL 172800s) passed. The disable LRO did not finish within 10 minutes (the polling policy returnedDEADLINE_EXCEEDED), but the cache state wasdisabled. Result: PASSED.