-
Notifications
You must be signed in to change notification settings - Fork 90
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: Bidi uses metadata from start_rpc #205
Conversation
Allow Bidi to use metadata from start_rpc when no other metadata is provided.
No region tags are edited in this PR.This comment is generated by snippet-bot.
|
call = self._start_rpc(iter(request_generator), metadata=self._rpc_metadata) | ||
# use metadata from self._start_rpc if no other metadata is specified | ||
else: | ||
call = self._start_rpc(iter(request_generator)) |
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.
When I set up BidiRPC with LoggingV2Transport().tail_log_entries
, that's the unwrapped method, not the wrapped method. Will this still get the metadata from the wrapped 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.
also, I tried passing in LoggingServiceV2Client().tail_log_entries and it didn't seem to work.
I'm actually not sure how pubsub passes in the wrapped method successfully.
https://github.com/googleapis/python-pubsub/blob/e907f6e05f59f64a3b08df3304e92ec960997be6/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py#L524
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.
When I set up BidiRPC with LoggingV2Transport().tail_log_entries, that's the unwrapped method, not the wrapped method. Will this still get the metadata from the wrapped method?
I believe the wrapped one has to be passed in (the wrapper adds the metadata to the call)
also, I tried passing in LoggingServiceV2Client().tail_log_entries and it didn't seem to work.
I'm actually not sure how pubsub passes in the wrapped method successfully.
Hmm I'll go back and poke at what is actually expected to be passed in to Bidi.
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.
Overall, LGTM. I'll let @plamut comment on possible Pub/sub interactions.
Looking at Firestore vs. Pub/Sub, I see Firestore is passing the method in the gRPC transport and Pub/Sub is passing the method in the GAPIC client. I wonder if that contributed to the behavior difference between the two that requires this workaround? (Also see: googleapis/python-pubsub#93 (comment) and #30) @jameslynnwu For it "not working" when |
Great find! However, if I use the same workaround, it works.
|
The Pub/Sub client passes the The subscriber client does not pass any metadata on its own to As for the changes in this PR - since no metadata is passed to Before the PR, call = self._start_rpc(iter(request_generator), metadata=self._rpc_metadata) With the changes in this PR, however, that changes: if self._rpc_metadata:
call = self._start_rpc(iter(request_generator), metadata=self._rpc_metadata)
# use metadata from self._start_rpc if no other metadata is specified
else:
call = self._start_rpc(iter(request_generator)) Since metadata is call = self._start_rpc(iter(request_generator)) No explicit When the (wrapped) method is eventually called, the following logic in if self._metadata is not None:
metadata = kwargs.get("metadata", [])
# Due to the nature of invocation, None should be treated the same
# as not specified.
if metadata is None:
metadata = []
metadata = list(metadata)
... If I traced this correctly, there should be no difference between passing Does this answer the question? As for passing in a wrapped vs. un-wrapepd method - the regression caused by a Firestore fix back then seems to only affect the wrapped methods, yes, as the key change lives in in the We had to introduce a flag that changes how |
One more thing to note, though we probably not want to address all of this at once. Passing in the If we can ensure that only Also, it's interesting that |
@plamut Thank you for the detailed analysis. 🙏 I'm OOO the rest of the week so I'll come back and look at this next week. |
As @plamut explained above, this PR is a no-op, if you pass the wrapped method the metadata will get added (which is why Pub/Sub doesn't pass I had a bit of trouble tracing this through but was able to confirm the expected headers in the gRPC logs:
|
Allow Bidi to use metadata from start_rpc when no other metadata
is provided.
This allows
client_info
on wrapped client methods will be passed through toBidiRpc
.Fixes #202 🦕
Not expected to impact Firestore, as metadata is explicitly passed: https://github.com/googleapis/python-firestore/blob/e57258c51e4b4aa664cc927454056412756fc7ac/google/cloud/firestore_v1/watch.py#L220-L226
Pub/Sub does not seem to pass
metadata
and may be impacted: https://github.com/googleapis/python-pubsub/blob/e907f6e05f59f64a3b08df3304e92ec960997be6/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py#L523-L528