-
Notifications
You must be signed in to change notification settings - Fork 63
[DRAFT] feat: support routing cookie #1288
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
base: csm_2_instrumentation_advanced
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @daniel-sanche, 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 introduces foundational support for a routing cookie feature. It establishes a mechanism to capture routing cookie metadata from failed operation attempts and subsequently inject this information into future retry attempts. This aims to improve routing efficiency and consistency across retries by leveraging server-provided routing hints. Highlights
Changelog
Activity
Using Gemini Code AssistThe 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 by creating a comment using either
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 Limitations & Feedback Gemini Code Assist 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. 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
|
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 introduces support for routing cookies as a proof-of-concept. The changes add a routing_cookie field to ActiveOperationMetric, extract cookie information from failed request metadata, and include it in subsequent requests.
My review has identified a couple of areas for improvement:
- The implementation for adding the cookie to request metadata in
metrics_interceptor.pyis not compatible with the synchronous client and doesn't follow gRPC interceptor best practices. I've suggested a fix. - The logic for extracting the cookie from response metadata in
tracked_retry.pycould be refactored to avoid code duplication. I've recommended refactoring it into a shared helper function to improve maintainability and ensure consistency.
| for k,v in operation.routing_cookie.items(): | ||
| client_call_details.metadata.add(k, v) |
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 client_call_details object is immutable (it's a namedtuple). While metadata might be a mutable object in the async version, you should not modify it in place. The idiomatic way to add metadata in an interceptor is to create a new ClientCallDetails object with the updated metadata.
Furthermore, the add method does not exist on the metadata list in the synchronous version of the client, which will cause an AttributeError. The synchronous metadata is a list of tuples.
To fix this, you should create a copy of the metadata, append the new headers, and then create a new ClientCallDetails object using _replace. This new object will then be used in the continuation call.
| for k,v in operation.routing_cookie.items(): | |
| client_call_details.metadata.add(k, v) | |
| metadata = list(client_call_details.metadata or []) + list(operation.routing_cookie.items()) | |
| client_call_details = client_call_details._replace(metadata=metadata) |
| metadata_dict = {k: v for k, v in metadata} | ||
| operation.add_response_metadata(metadata_dict) | ||
| # check for routing cookie: | ||
| cookie_headers = {k:v for k,v in metadata_dict.items() if k.startswith("x-goog-cbt-cookie")} | ||
| if cookie_headers: | ||
| operation.routing_cookie = cookie_headers |
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.
Proof of concept of the routing cookie feature. Grab routing cookie metadata from ffailed attempts, and pass it in with future attempts
TODO: