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

Support keyword 'target' parameter when wrapping GRPC channels #946

Merged
merged 5 commits into from May 22, 2019

Conversation

asnr
Copy link
Contributor

@asnr asnr commented May 20, 2019

The target for a GRPC channel can be specified with a keyword argument instead of a positional argument in both the function grpc.insecure_channel and grpc.secure_channel. See, for example, this usage in the official google pubsub client.

Currently, the datadog patch only uses the positional argument to get the target parameter, which throws the following exception if the keyword argument is used by a client:

>       target = args[0]
E       IndexError: tuple index out of range

For a simple example of client code that reproduces this error, see this gist.

Testing

I wasn't sure what the best way of testing this behaviour was. I settled on changing two existing tests to specify target using a keyword argument, but there might be a better way. I'd be happy to hear any suggestions.

@asnr asnr requested a review from a team as a code owner May 20, 2019 01:57
@jd
Copy link
Contributor

jd commented May 20, 2019

@asnr For testing, can you factorize the test function and call it once with argv[0] and once with kwargs?

Copy link
Contributor

@jd jd left a comment

Choose a reason for hiding this comment

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

See my comment about testing both scenarios.

@asnr
Copy link
Contributor Author

asnr commented May 20, 2019

@jd I've factorised one insecure_channel test and one secure_channel test to use each of the calling methods. Let me know if you would like more of the tests to factorised similarly. (Or if you meant something else entirely!)

@jd
Copy link
Contributor

jd commented May 21, 2019

That's exactly what I meant, thanks @asnr

jd
jd previously approved these changes May 21, 2019
brettlangdon
brettlangdon previously approved these changes May 21, 2019
Copy link
Member

@brettlangdon brettlangdon left a comment

Choose a reason for hiding this comment

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

One suggestion, but otherwise looks good to me!

@@ -30,15 +30,25 @@ def unpatch():

def _insecure_channel_with_interceptor(wrapped, instance, args, kwargs):
channel = wrapped(*args, **kwargs)
target = args[0]

if kwargs.get('target'):
Copy link
Member

Choose a reason for hiding this comment

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

We might want to do if 'target' in kwargs: instead. In case kwargs['target'] is falsey.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, I'll make that change.

@asnr asnr dismissed stale reviews from brettlangdon and jd via 2df48e6 May 22, 2019 04:24
@jd jd merged commit af0e3a8 into DataDog:master May 22, 2019
@majorgreys majorgreys added this to the 0.26.0 milestone Jun 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants