Skip to content
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

feat: compute_snapshot_schedule_create/delete/get/edit #3925

Merged
merged 3 commits into from
Dec 5, 2024

Conversation

gryczj
Copy link
Contributor

@gryczj gryczj commented Nov 26, 2024

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)
  • 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

@gryczj gryczj requested review from a team as code owners November 26, 2024 14:56
Copy link
Contributor

@code-review-assist-experimental code-review-assist-experimental bot left a comment

Choose a reason for hiding this comment

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

Hi @gryczj and reviewers,

I'm currently reviewing this pull request and will post my detailed review in a few minutes. In the meantime, here's a quick summary to help everyone get up to speed:

This pull request adds functionality to create and delete Compute Engine snapshot schedules. It introduces two new JavaScript files: createSnapshotSchedule.js and deleteSnapshotSchedule.js. createSnapshotSchedule.js creates a snapshot schedule with configurable parameters like retention policy, schedule (daily in this example, but supports weekly and monthly), and snapshot properties (including labels and guest flush). deleteSnapshotSchedule.js deletes an existing snapshot schedule. The changes also include a new test file, snapshotSchedule.test.js, which verifies the functionality of both the creation and deletion operations. The intent is to provide comprehensive examples for managing snapshot schedules in the Google Cloud Compute Engine using Node.js.

If there's any missing information or context needed, please let me know.


And now, a little haiku to lighten the mood:

Code flows like a stream,
Tests run green, a joyful sight,
Clouds part, code takes flight.

@product-auto-label product-auto-label bot added samples Issues that are directly related to samples. api: compute Issues related to the Compute Engine API. labels Nov 26, 2024
Copy link

snippet-bot bot commented Nov 26, 2024

Here is the summary of changes.

You are about to add 4 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

@gryczj gryczj added kokoro:force-run Add this label to force Kokoro to re-run the tests. kokoro:run Add this label to force Kokoro to re-run the tests. labels Nov 26, 2024
@gryczj gryczj force-pushed the compute_snapshot_schedule_create branch from ce1a1f9 to 6ef0f82 Compare November 26, 2024 14:57
@iennae
Copy link
Contributor

iennae commented Nov 27, 2024

@gemini review

Copy link
Contributor

@code-review-assist-experimental code-review-assist-experimental bot left a comment

Choose a reason for hiding this comment

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

This pull request introduces the ability to create and delete snapshot schedules. The implementation looks good, and the tests cover the basic functionality. Here are a few suggestions for improvement:

Comment on lines +30 to +32
/**
* TODO(developer): Update/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.

low

The TODO should be more specific. Instead of just saying "Update/uncomment", it should specify what values need to be updated and why. For example, it could say "Update these variables to reflect your project and desired schedule configuration."

Suggested change
/**
* TODO(developer): Update/uncomment these variables before running the sample.
*/
/**
* TODO(developer): Update these variables before running the sample:
* - projectId: The ID of the project where you want to create the snapshot schedule.
* - region: The region where you want to create the snapshot schedule.
* - snapshotScheduleName: The name of the snapshot schedule.
*/

Comment on lines +29 to +31
/**
* TODO(developer): Update/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.

low

Similar to the create script, this TODO should be more specific about what needs to be updated.

Suggested change
/**
* TODO(developer): Update/uncomment these variables before running the sample.
*/
/**
* TODO(developer): Update these variables before running the sample:
* - projectId: The ID of the project where the snapshot schedule exists.
* - region: The region where the snapshot schedule exists.
* - snapshotScheduleName: The name of the snapshot schedule to delete.
*/

);
});

it('should delete snapshot schedule', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The delete test should be run before the create test, or there should be a setup step that creates a snapshot schedule before running any tests, since the delete test depends on a snapshot schedule existing.

Copy link
Contributor

Choose a reason for hiding this comment

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

isn't there a create snapshot schedule right before this? can you explain more what you are suggesting here?

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right to point out the dependency. The delete test relies on a snapshot schedule already existing. While there's a create test preceding it, there's no guarantee that the create test will always succeed before the delete test runs. To make the tests more robust and independent, I suggest either reordering the tests (running delete after create) or adding a setup function that creates a snapshot schedule before the tests begin and tears it down afterward. Reordering is simpler in this case.

Copy link
Contributor

Choose a reason for hiding this comment

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

@gryczj this is a good point (see last comment) can you identify a path forwards to resolve this?

Copy link
Contributor

Choose a reason for hiding this comment

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

To resolve this, the simplest approach is to reorder the tests within the describe block in snapshotSchedule.test.js. The create test should run before the delete test to ensure the snapshot schedule exists before attempting to delete it. This avoids the need for a more complex setup/teardown function.

Here's how you can modify the test file:

describe('Snapshot schedule', async () => {
  // ... (rest of your code)

  it('should create snapshot schedule', () => { ... });

  it('should delete snapshot schedule', () => { ... });
});

This ensures the tests are executed in the correct order, making the test suite more reliable.

Suggested change
it('should delete snapshot schedule', () => {
it('should create snapshot schedule', () => {
const response = execSync(
`node ./snapshotSchedule/createSnapshotSchedule.js ${snapshotScheduleName} ${region}`,
{
cwd,
}
);
assert(
response.includes(`Snapshot schedule: ${snapshotScheduleName} created.`)
);
});
it('should delete snapshot schedule', () => {
const response = execSync(
`node ./snapshotSchedule/deleteSnapshotSchedule.js ${snapshotScheduleName} ${region}`,
{
cwd,
}
);
assert(
response.includes(`Snapshot schedule: ${snapshotScheduleName} deleted.`)
);
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but this solution is already in the code. create-snapshot-test is called before delete-snapshot-test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@iennae fixed

@gryczj gryczj force-pushed the compute_snapshot_schedule_create branch from 6ef0f82 to 7a34d18 Compare November 28, 2024 10:56
@gryczj gryczj requested a review from iennae November 28, 2024 10:57
@gryczj gryczj force-pushed the compute_snapshot_schedule_create branch 3 times, most recently from d9a802a to a25a842 Compare November 29, 2024 11:10
@gryczj gryczj changed the title feat: compute_snapshot_schedule_create/delete feat: compute_snapshot_schedule_create/delete/get Nov 29, 2024
@gryczj gryczj force-pushed the compute_snapshot_schedule_create branch from a25a842 to f820f27 Compare November 29, 2024 13:44
@gryczj gryczj changed the title feat: compute_snapshot_schedule_create/delete/get feat: compute_snapshot_schedule_create/delete/get/edit Dec 2, 2024
@gryczj gryczj force-pushed the compute_snapshot_schedule_create branch from f820f27 to eda0d22 Compare December 3, 2024 09:23
}),
schedule: new compute.ResourcePolicySnapshotSchedulePolicySchedule({
// Similarly, you can create a weekly or monthly schedule.
// Review the resourcePolicies.insert method for details specific to setting a weekly or monthly schedule.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a link, so it's easier for users to review that method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@m-strzelczyk link to the docuemntation added

@gryczj gryczj force-pushed the compute_snapshot_schedule_create branch from eda0d22 to 0ea7aa5 Compare December 3, 2024 17:21
@gryczj gryczj force-pushed the compute_snapshot_schedule_create branch from 0ea7aa5 to a7112b7 Compare December 4, 2024 13:45
@gryczj gryczj requested a review from m-strzelczyk December 4, 2024 13:45
@BigBlackWolf BigBlackWolf self-requested a review December 5, 2024 11:55
@m-strzelczyk m-strzelczyk merged commit 960fee3 into main Dec 5, 2024
136 of 137 checks passed
@m-strzelczyk m-strzelczyk deleted the compute_snapshot_schedule_create branch December 5, 2024 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: compute Issues related to the Compute Engine API. kokoro:force-run Add this label to force Kokoro to re-run the tests. kokoro:run Add this label to force Kokoro to re-run the tests. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants