Skip to content

Conversation

thiyaguk09
Copy link

Description

Fixes #

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

  • I have followed guidelines from CONTRIBUTING.MD and Samples Style Guide
  • Tests pass: npm test (see Testing)
  • Lint pass: npm run lint (see Style)
  • Required CI tests pass (see CI testing)
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • This pull request is from a branch created directly off of GoogleCloudPlatform/nodejs-docs-samples. Not a fork.
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new sample directory, and I created GitHub Actions workflow for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

Note: Any check with (dev), (experimental), or (legacy) can be ignored and should not block your PR from merging (see CI testing).

@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Sep 4, 2025
@thiyaguk09 thiyaguk09 marked this pull request as ready for review September 4, 2025 13:05
@thiyaguk09 thiyaguk09 requested review from a team as code owners September 4, 2025 13:05
Copy link

snippet-bot bot commented Sep 4, 2025

Here is the summary of changes.

You are about to add 7 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

Comment on lines +19 to +21
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion:

/**

  • Creates an Anywhere Cache instance for a Cloud Storage bucket.
  • Anywhere Cache is a feature that provides an SSD-backed zonal read cache.
  • This can significantly improve read performance for frequently accessed data
  • by caching it in the same zone as your compute resources.
  • @param {string} bucketName The name of the bucket to create the cache for.
  • Example: 'your-gcp-bucket-name'
  • @param {string} zone The zone where the cache will be created.
  • Example: 'us-central1-a'
    */

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your thoughtful suggestion and for providing such a well-crafted JSDoc comment. We aim to maintain a consistent documentation style across all our Cloud Storage samples to offer a unified experience for our users.

Adopting a new format, even if it is an improvement, could impact the overall cohesiveness and clarity of the sample set.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a standard currently being followed that we should adhere to for future reference?

const request = {
parent: bucketPath,
anywhereCache: {
zone: zoneName,
Copy link
Contributor

@iennae iennae Sep 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the default sample show a TTL and/or admissionPolicy ? (reading documentation here to better understand) https://cloud.google.com/storage/docs/anywhere-cache

Copy link
Author

@thiyaguk09 thiyaguk09 Sep 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the detailed question. You're right that ttlSeconds and admissionPolicy are available fields.

Our sample's goal is to show the simplest, most fundamental usage with only the required parameters. This approach ensures consistency and clarity across all language samples, making it easier for users to get started. While including optional fields would be a good demonstration, we keep the default samples minimal to focus on the core functionality. We appreciate you digging into the documentation!

Comment on lines +19 to +21
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion:

/**

  • Disables an Anywhere Cache instance.
  • Disabling a cache is the first step to permanently removing it. Once disabled,
  • the cache stops ingesting new data. After a grace period, the cache and its
  • contents are deleted. This is useful for decommissioning caches that are no
  • longer needed.
  • @param {string} bucketName The name of the bucket where the cache resides.
  • Example: 'your-gcp-bucket-name'
  • @param {string} cacheName The unique identifier of the cache instance to disable.
  • Example: 'cacheName'
    */

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your thoughtful suggestion and for providing such a well-crafted JSDoc comment. We aim to maintain a consistent documentation style across all our Cloud Storage samples to offer a unified experience for our users.

Adopting a new format, even if it is an improvement, could impact the overall cohesiveness and clarity of the sample set.


// Run request
const [response] = await controlClient.disableAnywhereCache(request);
console.log(`Disabled anywhere cache: ${response.name}.`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: based on if this actually disables or triggers it to be disabled:
wrap everything in a try .. catch and log instead:
console.log(Successfully initiated disablement for Anywhere Cache '${cacheName}'.);
console.log( Current State: ${response.state});

catch potential errors

catch (err) {
console.error(Error disabling Anywhere Cache '${cacheName}': ${err.message});
if (err.code === 5) {
// NOT_FOUND error can occur if the bucket or cache does not exist.
console.error(Please ensure the cache '${cacheName}' exists in bucket '${bucketName}'.);
} else if (err.code === 9) {
// FAILED_PRECONDITION can occur if the cache is already being disabled or is not in a RUNNING state.
console.error(Cache '${cacheName}' may not be in a state that allows disabling.);
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, our code samples are designed to demonstrate the simplest, "happy path" usage of a feature. We intentionally omit error handling to keep the code concise and focused on the core API call. This approach ensures all Cloud Storage samples share a consistent, minimal style, making them easier to understand at a glance.


function main(bucketName, cacheName) {
// [START storage_control_get_anywhere_cache]
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: suggestion of

/**

  • Retrieves details of a specific Anywhere Cache instance.
  • This function is useful for checking the current state, configuration (like TTL),
  • and other metadata of an existing cache.
  • @param {string} bucketName The name of the bucket where the cache resides.
  • Example: 'your-gcp-bucket-name'
  • @param {string} cacheName The unique identifier of the cache instance.
  • Example: 'my-anywhere-cache-id'
    */

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your thoughtful suggestion and for providing such a well-crafted JSDoc comment. We aim to maintain a consistent documentation style across all our Cloud Storage samples to offer a unified experience for our users.

Adopting a new format, even if it is an improvement, could impact the overall cohesiveness and clarity of the sample set.


function main(bucketName) {
// [START storage_control_list_anywhere_caches]
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: /**

  • Lists all Anywhere Cache instances for a Cloud Storage bucket.
  • This function helps you discover all active and pending caches associated with
  • a specific bucket, which is useful for auditing and management.
  • @param {string} bucketName The name of the bucket to list caches for.
  • Example: 'your-gcp-bucket-name'
    */

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your thoughtful suggestion and for providing such a well-crafted JSDoc comment. We aim to maintain a consistent documentation style across all our Cloud Storage samples to offer a unified experience for our users.

Adopting a new format, even if it is an improvement, could impact the overall cohesiveness and clarity of the sample set.

};

// Run request
const [response] = await controlClient.listAnywhereCaches(request);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might wrap the response in a try.. catch

if there are no Anywhere Caches found for the bucket versus errors listing Anywhere Caches

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, our code samples are designed to demonstrate the simplest, "happy path" usage of a feature. We intentionally omit error handling to keep the code concise and focused on the core API call. This approach ensures all Cloud Storage samples share a consistent, minimal style, making them easier to understand at a glance.


function main(bucketName, cacheName, admissionPolicy) {
// [START storage_control_update_anywhere_cache]
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

/**

  • Updates the Admission Policy of an Anywhere Cache instance.
  • @param {string} bucketName The name of the bucket where the cache resides.
  • Example: 'your-gcp-bucket-name'
  • @param {string} cacheName The unique identifier of the cache instance to update.
  • Example: 'my-anywhere-cache-id'
  • @param {string} admissionPolicy Determines when data is ingested into the cache
    */

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your thoughtful suggestion and for providing such a well-crafted JSDoc comment. We aim to maintain a consistent documentation style across all our Cloud Storage samples to offer a unified experience for our users.

Adopting a new format, even if it is an improvement, could impact the overall cohesiveness and clarity of the sample set.

Copy link
Contributor

@iennae iennae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mostly looks ok. I have a few questions. I did run this through our generation to see what kind of output I received and I've shared those headers for visibility. I think there are a few areas of improvements to make sure there is a try..catch to ensure folks get actionable feedback so they don't assume the code is broken depending on the order in which they run commands.

Thanks!

@thiyaguk09
Copy link
Author

This mostly looks ok. I have a few questions. I did run this through our generation to see what kind of output I received and I've shared those headers for visibility. I think there are a few areas of improvements to make sure there is a try..catch to ensure folks get actionable feedback so they don't assume the code is broken depending on the order in which they run commands.

Thanks!

Thank you for the suggestion. Our samples are designed to demonstrate the simplest "happy path" for a feature, focusing on the core API call. We intentionally omit try...catch blocks to keep the code concise and readable, which helps maintain a consistent style across all of our language samples. Furthermore, unhandled rejections are already handled at the application level to prevent the code from breaking, so the primary goal of our samples remains focused on positive-case demonstration.

@thiyaguk09 thiyaguk09 requested a review from iennae September 9, 2025 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants