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 reservation create shared #3832

Closed
wants to merge 10 commits into from

Conversation

gryczj
Copy link
Contributor

@gryczj gryczj commented Sep 6, 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 self-assigned this Sep 6, 2024
@gryczj gryczj requested review from a team as code owners September 6, 2024 09:35
Copy link

snippet-bot bot commented Sep 6, 2024

Here is the summary of changes.

You are about to add 1 region tag.

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

@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 Sep 6, 2024
@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 Sep 6, 2024
@kokoro-team kokoro-team removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Sep 6, 2024
@gryczj gryczj force-pushed the compute_reservation_create_shared branch from 9967e39 to c9810b2 Compare September 6, 2024 09:36
@gryczj gryczj changed the title Compute reservation create shared feat: compute reservation create shared Sep 6, 2024
@gryczj gryczj force-pushed the compute_reservation_create_shared branch 2 times, most recently from c903144 to 58e15ae Compare September 6, 2024 10:37
@gryczj
Copy link
Contributor Author

gryczj commented Sep 6, 2024

Please review #3868 first

@gryczj gryczj force-pushed the compute_reservation_create_shared branch 2 times, most recently from 5471bb3 to 993617b Compare September 10, 2024 13:03
* limitations under the License.
*/

/* eslint-disable no-dupe-keys */
Copy link
Contributor Author

@gryczj gryczj Sep 11, 2024

Choose a reason for hiding this comment

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

Reason for: /* eslint-disable no-dupe-keys */
According to the documentation: https://cloud.google.com/compute/docs/instances/reservations-modify#modifying-consumer-projects-shared-reservation. When we want to update consumer projects, we must define paths field for each consumer, e.g:

await reservationsClient.update({
      project: projectId,
      reservation: reservationName,
      paths: 'shareSettings.projectMap.consumerId1',
      paths: 'shareSettings.projectMap.consumerId2'
      zone,
      reservationResource: {
        name: reservationName,
        shareSettings: {
          projectMap: {
            consumerId1: {
              projectId: 'consumerId1',
            },
            consumerId2: {
              projectId: 'consumerId2',
            },
          },
        },
      },
    });

Copy link
Member

@subfuzion subfuzion left a comment

Choose a reason for hiding this comment

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

Really nice use of mocks, but overkill for a sample. Please simplify, per the comment I left. Thanks!


module.exports = main;

// TODO(developer): Uncomment below lines before running the sample.
Copy link
Member

Choose a reason for hiding this comment

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

Hi @gryczj. My comment here will apply to both modules and to the test. What really are we looking for to know if the sample did what it was intended? We are not unit testing production APIs, we simply expect that our call to an API will have the intended result. What is that? A resource ID? Not returning a failed status code or catching an exception, etc? If you were a developer using this API in production code, what would you expect -- that's the check you could demonstrate right here. The unit test probably doesn't really need mocks and all the extra complexity; isn't it enough, really, if main doesn't throw (the process doesn't exit with a non-zero exit code)? Our samples shouldn't themselves be APIs, so no need to export anything out of this module.

Copy link
Member

Choose a reason for hiding this comment

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

I just want to add your PRs have been great! To clarify here, the goal is that a sample should fully encapsulate the demonstration of what a developer needs to know to use our APIs successfully in their own production code. How is the API intended to be used? Our tests don't need to confirm that APIs work as expected, only that the sample works (we don't want broken samples in our docs for an unexpected reason, but we do expect that service teams have already exhaustively tested their services). Hope this helps!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@subfuzion thank you for your comments and review :) I introduced mocks here because to create shared reservation special permission are required and also another project, that we want to use as consumer and share this reservation with. I can test this sample locally with my credentials, but I have no knowledge about our test environment and projects, which I can use here as an example in tests and this sample will throw errors.
I understand your point. All new changes in the implementation were made to allow me to use mocks and fake clients in tests and on the other hand allow user to use real clients if they want to.

Copy link
Contributor

Choose a reason for hiding this comment

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

@subfuzion As @gryczj wrote, the shared reservation sample would require a separate project, with a change to organization policy to allow this project to share the reservation with other projects.

I made an "executive" call for the team that writes those samples for Python, Java, Go and Node to use mocks for those samples as a kind of an exception to the rule.

My arguments:

  • We don't really do tests that span multiple projects.
  • It'd be very easy to forget about this additional project and in a year or two we'd have to rediscover the whole thing.
  • I know that Python has separate projects for every version of the language - having tests that span multiple projects that require org policy updates would make it harder to start up a new project for new version.

We acknowledge the value of proper testing and that's why mocks were picked as a middle ground between skipping tests for those samples and writing fully functional tests that would make use of multiple projects.

Let me know if I managed to convince you or not :)

Copy link
Member

@subfuzion subfuzion Sep 12, 2024

Choose a reason for hiding this comment

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

Thanks for the added context. I still don't see the need to mock console or treat the sample like its library code and have it export a function for testing, and my points about overall test simplification still remain. I'd like to surface this up to the rest of our team for discussion, so can you please address the points I've raised specifically?

Also, overall test flakiness still seems to be a problem, such as the compute hyperdisk failures for #3834 (which I merged so we can consolidate efforts on a single PR).

Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

Please feel free to ping me directly on internal chat: tonypujals@

@subfuzion subfuzion mentioned this pull request Sep 12, 2024
10 tasks
subfuzion pushed a commit that referenced this pull request Sep 12, 2024
Overriding failed test because tests need to be fixed in PR #3832
@gryczj gryczj force-pushed the compute_reservation_create_shared branch 7 times, most recently from 23bf1b4 to bce6e24 Compare September 16, 2024 11:41
@gryczj gryczj force-pushed the compute_reservation_create_shared branch 3 times, most recently from 9c74595 to 35e5cf8 Compare September 17, 2024 13:59
@gryczj gryczj force-pushed the compute_reservation_create_shared branch from 7c4d943 to 55714fa Compare September 19, 2024 11:09
@gryczj gryczj removed their assignment Sep 24, 2024
@gryczj gryczj force-pushed the compute_reservation_create_shared branch from 55714fa to a5a85e1 Compare September 26, 2024 14:47
@gryczj gryczj force-pushed the compute_reservation_create_shared branch from a5a85e1 to 328d42d Compare October 3, 2024 13:27
@gryczj
Copy link
Contributor Author

gryczj commented Oct 3, 2024

To keep commit history clean I moved changes to new PR: #3894

@gryczj gryczj closed this Oct 3, 2024
@gryczj gryczj deleted the compute_reservation_create_shared branch October 3, 2024 14:38
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. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants