grpc / grpc/grpc-rust

Restore methods to transform into tower service

Open
#2,127 0 comments 13 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
12.5k
Forks
1.3k
Avg merge
4d 7h
Merged PRs (30d)
24

Description

## Feature Request

Restore the methods that allow to turn tonic servers into tower services and expose the tower crates at least to some degree again, to allow for interoperability with other tower-based crates.

### Crates

Only the tonic crate itself as far as I'm aware, but it might extend to the extra crates to some degree.

### Motivation

At work we use the tonic crate in several projects, and it's a crucial crate for us. As there have been many changes since the last 0.12.3 release I was trying out the very latest version from Git and saw that the tower conversion methods are gone (namely `into_service`).

I saw in the commit history that these have been considered deprecated and later removed, and further changes have been done to internalize the tower crate, which is understandable from the point of hiding some details behind the public API to gain more freedom in internal changess and reduce breaking changes.

However, this is a big deal breaker for us, as it basically strips tonic of the neat feature of inter-operating with other crates that build on top of tower, which is a key feature of tower.

We use a mix of `hyper`, `axum` and `tonic` and often we have to glue them together or do some pre/post-processing before things arrive at the tonic level or after leaving it.

For example, we do some processing of requests in `hyper` on the HTTP-level, and only later pass it on to tonic to handle the actual request on the gRPC level. So in our setup we often call tonic instead of tonic calling us, meaning that we use it as a tower service where we call it per TCP stream or per request and do all sorts of custom stuff with TLS and other details around it.

So without any way in the upcoming version of turning a tonic server back into a tower service, we have no obvious path to upgrade.

### Proposal

Re-instate the previous APIs (still present in 0.12.3) or introduce new ones, which allow to transform from a tonic server into a tower service/make-service.

### Alternatives

I have tried to get it to work through some of the components in the `service` module instead of the `transport::server` module, in the hopes I can somehow turn it into an axum router and get it to work.

However, that only worked until I tried to apply the grpc-web layer, which requires different types on the request and response and I found no good way of gluing those together.

Also, the new APIs feel very defensive in general and not really open to combining tonic with anything else but itself (in contrast to axum for example, which feels very extensible). For example, the tonic interceptors are too limited and we really need the tower middlewares like `map_result` or `map_request` here, to just name a few.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.