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

Add grpc client and server plugin #547

Conversation

nunofgs
Copy link
Contributor

@nunofgs nunofgs commented Apr 29, 2019

Hi DataDog team!

This PR adds automatic instrumentation support for grpc, both client and server. The client plugin is implemented using client interceptors and should be pretty resilient to upstream changes.

The server plugin however, has no such support and I took a stab at implementing — finding any injection point as best I could. It is fully functional but I cannot guarantee that it'll be as resilient as grpc-node evolves.

dd-trace grpc

Let me know what you think!

Note: require-dir was removed since it doesn't support nested folders. There was already a file (src/plugins/index.js) with all of the supported plugins which I believe is even more appropriate to use.

@rochdev rochdev self-requested a review April 29, 2019 20:17
@rochdev rochdev added this to the 0.12.0 milestone Apr 29, 2019
Copy link
Member

@rochdev rochdev left a comment

Choose a reason for hiding this comment

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

A lot of constructs incompatible with Node 4 were used and should be refactored to support it. You can use https://node.green/ when not sure if a feature is supported or not.

scripts/install_plugin_modules.js Outdated Show resolved Hide resolved
scripts/install_plugin_modules.js Outdated Show resolved Hide resolved
test/plugins/agent.js Outdated Show resolved Hide resolved
src/plugins/grpc/client.js Outdated Show resolved Hide resolved
src/plugins/grpc/client.js Outdated Show resolved Hide resolved
src/plugins/grpc/server.js Outdated Show resolved Hide resolved
src/plugins/grpc/server.js Outdated Show resolved Hide resolved
src/plugins/grpc/server.js Outdated Show resolved Hide resolved
src/plugins/grpc/server.js Outdated Show resolved Hide resolved
src/plugins/grpc/server.js Outdated Show resolved Hide resolved
@rochdev
Copy link
Member

rochdev commented Apr 29, 2019

Thanks for the PR! I did a first pass of review but in general the instrumentation itself looks good.

I scheduled this for 0.12.0 since we don't plan to release it before at least a couple weeks, so we should be able to include this feature in the release.

@rochdev
Copy link
Member

rochdev commented Apr 29, 2019

It is fully functional but I cannot guarantee that it'll be as resilient as grpc-node evolves.

We have tests that run nightly so we should be able to find anything that breaks pretty quickly.

Copy link
Member

@rochdev rochdev left a comment

Choose a reason for hiding this comment

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

Just noticed that the tests are not running in CI and should be added to .circleci/config.yml

@nunofgs
Copy link
Contributor Author

nunofgs commented May 2, 2019

Thanks for the in-depth review @rochdev and willingness to accept the PR :) !

I'll update the branch with your comments addressed shortly.

@nunofgs
Copy link
Contributor Author

nunofgs commented May 2, 2019

Just noticed that the tests are not running in CI and should be added to .circleci/config.yml

Missed that, thank you. Added.

@nunofgs nunofgs force-pushed the enhancement/add-grpc-client-and-server-plugin branch from bffe55d to 273bc20 Compare May 3, 2019 00:42
src/plugins/grpc/client.js Outdated Show resolved Hide resolved
src/plugins/grpc/client.js Outdated Show resolved Hide resolved
@rochdev
Copy link
Member

rochdev commented May 3, 2019

Ignore the node-mongodb-core errors, it's just noise because of an issue we are having with CircleCI. Postgres will need to be fixed however, but I'm not sure why it's failing. It must be related to adding grpc to the list of native modules. If you can't figure it out let me know and I will take a look when the PR is otherwise ready to merge.

@nunofgs nunofgs force-pushed the enhancement/add-grpc-client-and-server-plugin branch 2 times, most recently from fba8a62 to 8ae25e1 Compare May 7, 2019 22:31
@nunofgs
Copy link
Contributor Author

nunofgs commented May 7, 2019

Postgres will need to be fixed however, but I'm not sure why it's failing. It must be related to adding grpc to the list of native modules. If you can't figure it out let me know and I will take a look when the PR is otherwise ready to merge.

Found it. prev wasn't being used here. I ended up changing the implementation a bit but I can go back to an Array.reduce() if you prefer.

@rochdev
Copy link
Member

rochdev commented May 8, 2019

Found it. prev wasn't being used here. I ended up changing the implementation a bit but I can go back to an Array.reduce() if you prefer.

Your implementation is a lot cleaner than Array.reduce so that's definitely fine. However, the leading and trailing slashes are no longer included for libpq. While this should not affect anything, I prefer to still have them to make it clear it's the actual name and not just part of a name. For example, what if some library would be called something-libpq? This also applies to grpc.

@nunofgs nunofgs force-pushed the enhancement/add-grpc-client-and-server-plugin branch from d1c4388 to 872bf59 Compare May 16, 2019 00:12
@nunofgs
Copy link
Contributor Author

nunofgs commented May 16, 2019

@rochdev sorry for taking so long to get back to this. Had a busy week.

I've updated the PR with support for cancellation and bidi streams (as well as tests of course). I believe all actionable comments should be addressed.

Mind doing another review?

src/plugins/grpc/client.js Outdated Show resolved Hide resolved
src/plugins/grpc/server.js Outdated Show resolved Hide resolved
Copy link
Member

@rochdev rochdev left a comment

Choose a reason for hiding this comment

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

Overall looks good. I'll do one last pass when everything is resolved.

@rochdev
Copy link
Member

rochdev commented May 16, 2019

@nunofgs One thing I'm wondering is about the context propagation. We are currently working on an HTTP2 integration which will handle context propagation, but right now you are doing it directly in gRPC. What do you think should be the expected behavior? Should we just drop propagation from gRPC at that point or is there still value to have it there?

@nunofgs nunofgs force-pushed the enhancement/add-grpc-client-and-server-plugin branch from 872bf59 to e134834 Compare May 21, 2019 23:50
@nunofgs
Copy link
Contributor Author

nunofgs commented May 21, 2019

@nunofgs One thing I'm wondering is about the context propagation. We are currently working on an HTTP2 integration which will handle context propagation, but right now you are doing it directly in gRPC. What do you think should be the expected behavior? Should we just drop propagation from gRPC at that point or is there still value to have it there?

🤔 gRPC uses http2 as transport protocol but it supports others and it's also possible to write your own. It might be useful to keep the gRPC context propagation for those cases.

src/plugins/grpc/server.js Outdated Show resolved Hide resolved
@nunofgs nunofgs force-pushed the enhancement/add-grpc-client-and-server-plugin branch 2 times, most recently from 83bd64f to fd1c54e Compare May 22, 2019 22:34
Copy link
Contributor

@rishabh rishabh left a comment

Choose a reason for hiding this comment

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

Let's also go through the plugin checklist and make sure we got everything.

packages/datadog-plugin-grpc/test/test.proto Outdated Show resolved Hide resolved
scripts/install_plugin_modules.js Show resolved Hide resolved
packages/datadog-plugin-grpc/src/client.js Outdated Show resolved Hide resolved
packages/datadog-plugin-grpc/src/server.js Outdated Show resolved Hide resolved
packages/datadog-plugin-grpc/src/server.js Show resolved Hide resolved
packages/datadog-plugin-grpc/src/server.js Outdated Show resolved Hide resolved
packages/datadog-plugin-grpc/src/server.js Outdated Show resolved Hide resolved
packages/datadog-plugin-grpc/src/client.js Show resolved Hide resolved
@rochdev
Copy link
Member

rochdev commented Jul 31, 2019

Plugin Checklist

@rishabh
Copy link
Contributor

rishabh commented Jul 31, 2019

Let's add some tests to ensure that we aren't modifying any metadata (except for the context propagation).

@rishabh rishabh modified the milestones: 0.14.0, 0.15.0 Aug 15, 2019
packages/datadog-plugin-grpc/src/client.js Show resolved Hide resolved
packages/datadog-plugin-grpc/src/client.js Outdated Show resolved Hide resolved
packages/datadog-plugin-grpc/src/util.js Show resolved Hide resolved
Copy link
Contributor

@rishabh rishabh left a comment

Choose a reason for hiding this comment

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

I think we also need to add tests to check if the listener runs in the parent context for stream requests.

packages/datadog-plugin-grpc/src/client.js Outdated Show resolved Hide resolved
packages/datadog-plugin-grpc/src/client.js Outdated Show resolved Hide resolved
packages/datadog-plugin-grpc/src/client.js Outdated Show resolved Hide resolved
packages/datadog-plugin-grpc/src/client.js Outdated Show resolved Hide resolved
packages/datadog-plugin-grpc/src/client.js Outdated Show resolved Hide resolved
packages/datadog-plugin-grpc/src/client.js Outdated Show resolved Hide resolved
packages/datadog-plugin-grpc/src/server.js Outdated Show resolved Hide resolved
packages/datadog-plugin-grpc/src/server.js Outdated Show resolved Hide resolved
packages/datadog-plugin-grpc/src/server.js Outdated Show resolved Hide resolved
packages/datadog-plugin-grpc/src/server.js Show resolved Hide resolved
packages/datadog-plugin-grpc/src/server.js Outdated Show resolved Hide resolved
packages/datadog-plugin-grpc/src/server.js Outdated Show resolved Hide resolved
packages/datadog-plugin-grpc/src/server.js Show resolved Hide resolved
@rochdev rochdev dismissed their stale review August 28, 2019 21:39

took ownership of the PR

@rochdev rochdev merged commit c037e7f into DataDog:master Aug 28, 2019
@ebenoist
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for gRPC
4 participants