-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(pubsub): add v2 subscription samples #5339
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(pubsub): add v2 subscription samples #5339
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.
Summary of Changes
Hello @hongalex, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request represents the second phase of migrating the Go Pub/Sub samples to the new v2
client library. It encompasses a comprehensive update of all subscription and message reception examples, adapting them to the v2
client's API patterns, which includes a shift to protobuf-based interactions and refined client interfaces. The changes also involve a substantial refactoring of the corresponding integration tests to validate the updated samples.
Highlights
- Pub/Sub v2 Migration: All existing Go Pub/Sub subscription and receive samples have been updated to use the new
cloud.google.com/go/pubsub/v2
client library. This is part of a larger effort to migrate samples to the latest client versions. - API Surface Changes: The samples now leverage the
v2
client's distinct admin and subscriber clients (e.g.,client.SubscriptionAdminClient
,client.Subscriber
) and utilize protobuf messages (e.g.,pubsubpb.Subscription
,iampb.GetIamPolicyRequest
) for configuring and interacting with Pub/Sub resources, replacing the older Go struct-based configurations. - Function Signature Updates: Many sample functions have updated signatures to accept fully qualified resource names (e.g.,
projects/my-project/subscriptions/my-sub
) instead of just resource IDs, and now commonly accept anio.Writer
for output. - Test Suite Refactoring: The associated test suite (
subscription_test.go
) has been significantly refactored to align with thev2
client's API, including changes to test setup, resource creation/deletion, and assertions, ensuring compatibility and correctness with the new library.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request updates the Go Pub/Sub samples to use the new v2 library, focusing on subscription and receive samples. The changes involve migrating from the v1 client to the v2 AdminClient
patterns. While the migration is largely successful, several test assertions have been lost, weakening their ability to verify correctness. There's also a critical bug in one test and potential resource leaks due to changes in test setup and cleanup logic. Additionally, some sample functions exhibit subtle, possibly unintentional, behavior changes like altered default AckDeadline
values.
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 comment goes beyond the scope of these examples to question the client API design:
Given that the admin surface now uses full resource names (projects/%s/subscriptions/%s
), it seems jarring and inconsistent that the new (Subscription
-> Subscriber
) data plane functions still use short names (subID := "my-sub"
).
Can the entire surface be normalized on full resource names? If not, comments clarifying the situation should be added to data plane samples.
Are you suggesting something like |
Clarify that client.Subscriber accepts either a resource ID or a fully qualified name for the subscription. If a resource ID is used, the project ID from the client is assumed.
Add doc comments to client.Subscriber calls
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.
LGTM
05c9f5e
into
GoogleCloudPlatform:pubsub-v2-samples-trunk
This is part 2 of 3 PRs that will be updating our existing Go Pub/Sub samples to use the new v2 library. This PR focuses on updating subscription and receive samples and the tests associated with them.
We are merging these PRs into pubsub-v2-samples-trunk since the v2 library isn't fully released yet.