Skip to content

rust: add Tonic version of generated Rust code#39

Merged
olix0r merged 14 commits intomasterfrom
eliza/tonic
Jun 16, 2020
Merged

rust: add Tonic version of generated Rust code#39
olix0r merged 14 commits intomasterfrom
eliza/tonic

Conversation

@hawkw
Copy link
Contributor

@hawkw hawkw commented Mar 26, 2020

Tonic (https://crates.io/crates/tonic) is, essentially, the Tokio 0.2
world's version of tower-grpc. Although the two libraries are similar
and share a common geneology, the code generated by tonic-build is not
compatible with the code generated by tower-grpc-build. In order to
implement the mock destination controller for linkerd/linkerd2#4158
using the Tokio 0.2 stack, we need a Tonic version of the generated Rust
bindings.

This branch adds a new linkerd2-proxy-api-tonic crate that contains
Tonic bindings generated from the proxy-api protos. Rather than putting
this code in the existing linkerd2-proxy-api crate under a feature
flag, I opted to create a separate crate. This is because tonic-build
and tower-grpc-build will generate code that depends on different
versions of libraries like tower, http, and prost. Although it
would be possible to rename those dependencies so we can depend on both
their Tokio 0.1 and Tokio 0.2 versions, it seems significantly more
difficult to convince the code generators to generate code that
references those dependencies by names like http_02 and so on.
Therefore, I created a separate crate for the Tonic version.

This may also be useful when we start updating the proxy itself to use
the Tokio 0.2 stack.

Signed-off-by: Eliza Weisman [email protected]

Tonic (https://crates.io/crates/tonic) is, essentially, the Tokio 0.2
world's version of `tower-grpc`. Although the two libraries are similar
and share a common geneology, the code generated by `tonic-build` is not
compatible with the code generated by `tower-grpc-build`. In order to
implement the mock destination controller for linkerd/linkerd2#4158
using the Tokio 0.2 stack, we need a Tonic version of the generated Rust
bindings.

This branch adds a new `linkerd2-proxy-api-tonic` crate that contains
Tonic bindings generated from the proxy-api protos. Rather than putting
this code in the existing `linkerd2-proxy-api` crate under a feature
flag, I opted to create a separate crate. This is because `tonic-build`
and `tower-grpc-build` will generate code that depends on different
versions of libraries like `tower`, `http`, and `prost`. Although it
would be possible to rename those dependencies so we can depend on both
their Tokio 0.1 and Tokio 0.2 versions, it seems significantly more
difficult to convince the code generators to generate code that
references those dependencies by names like `http_02` and so on.
Therefore, I created a separate crate for the Tonic version.

This may also be useful when we start updating the proxy itself to use
the Tokio 0.2 stack.

Signed-off-by: Eliza Weisman <[email protected]>
@hawkw hawkw requested a review from olix0r March 26, 2020 22:06
@hawkw hawkw self-assigned this Mar 26, 2020
Signed-off-by: Eliza Weisman <[email protected]>
Copy link
Member

@olix0r olix0r left a comment

Choose a reason for hiding this comment

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

Given that this copy/pastes a bunch of code... do we want to hold off on merging this until we switch the proxy over to tonic? What are the blockers to doing that? (presumably, porting our gRPC interfaces after the 0.2 upgrade? anything else?)

@olix0r
Copy link
Member

olix0r commented Apr 16, 2020

@hawkw there's no urgency on this, but what do you think about taking a branch-based approach for tokio-0.2 (as we did in the proxy repo)?

@hawkw
Copy link
Contributor Author

hawkw commented Apr 16, 2020

@olix0r sure, I'd be fine to change to that approach here.

hawkw added 2 commits May 18, 2020 16:58
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
Cargo.toml Outdated
members = [
"rs"
"rs",
"rs-tonic",
Copy link
Member

Choose a reason for hiding this comment

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

fwiw, I'm in favor of just replacing the rs crate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup, will do

hawkw added 2 commits May 19, 2020 09:42
hawkw added a commit to linkerd/linkerd2-proxy that referenced this pull request May 20, 2020
This branch updates the `linkerd2-proxy-api-resolve` crate to use
`std::future` and Tonic. Getting this to work required some upstream
changes to linkerd/linkerd2-proxy-api#39 to pass different feature flags
to Tonic, but the change here is pretty straigntforward.

Depends on #518 and will be rebased onto `master-tokio-02`
when that branch merges.

Signed-off-by: Eliza Weisman <[email protected]>
hawkw added 5 commits May 22, 2020 09:50
turns out reading the generated sources without this is *really bad*

Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
it's nice, but the proxy docker build shouldn't depend on rustfmt

Signed-off-by: Eliza Weisman <[email protected]>
@olix0r olix0r requested a review from kleimkuhler June 16, 2020 19:30
Co-authored-by: Oliver Gould <[email protected]>
Copy link
Contributor

@kleimkuhler kleimkuhler left a comment

Choose a reason for hiding this comment

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

Looks good!

@olix0r olix0r merged commit 433b31e into master Jun 16, 2020
@olix0r olix0r deleted the eliza/tonic branch June 16, 2020 21:05
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.

3 participants