-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
There was a problem hiding this 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.
Here is the summary of changes. You are about to add 4 region tags.
This comment is generated by snippet-bot.
|
ce1a1f9
to
6ef0f82
Compare
@gemini review |
There was a problem hiding this 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:
/** | ||
* TODO(developer): Update/uncomment these variables before running the sample. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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."
/** | |
* 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. | |
*/ |
/** | ||
* TODO(developer): Update/uncomment these variables before running the sample. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the create script, this TODO should be more specific about what needs to be updated.
/** | |
* 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', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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.`) | |
); | |
}); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iennae fixed
6ef0f82
to
7a34d18
Compare
d9a802a
to
a25a842
Compare
a25a842
to
f820f27
Compare
f820f27
to
eda0d22
Compare
}), | ||
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
eda0d22
to
0ea7aa5
Compare
0ea7aa5
to
a7112b7
Compare
Description
Fixes #
Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.
Checklist
npm test
(see Testing)npm run lint
(see Style)GoogleCloudPlatform/nodejs-docs-samples
. Not a fork.