-
Notifications
You must be signed in to change notification settings - Fork 420
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
Allow extending ServerContext and/or ServerRequest with additional information #2159
Comments
Perhaps something like |
That's awesome! Is this available somewhere?
Possibly. I don't think we have a clear position on this yet. We'd like to hold off on adding a grab-bag style context in which you can stick anything, but we're open to the possibility of adding more things to the existing client/server contexts. What objects from Vapor's Request object would you like to see in gRPC? We are also still figuring out where to draw the line between adding to the context vs. making things available via task locals. Part of me wonders whether task locals should entirely replace that grab-bag style of context. |
For now just my private repo haha, but could clean it up a little and offer it up to OSS. I took this transport approach since it felt like the easiest way to hook in without modifying the grpc-swift sources, but ideally I would like to be able to use
For my particular scenario, I would like to forward Vapor's Without being able to forward the request instance to access the db and authenticated user, I'm forced to keep a reference of Vapor's app in the service implementations (to access the db from the RPC methods, along with other context relative references like logging), and to reload the user from the db for every RPC call (tracing/audit purposes of my product). Those are the most important in my opinion, but I foresee wanting to use other things from Request that are specific to that invocation. Again I realize this is not the intended use case of grpc-swift, but it's sooo close to being really easy to hook into Vapor. |
Just as FYI, decided to see what changes I would need for what I want to do, and got this: sergiocampama@8f0dec9 And my implementation of the gRPC-web middleware is here: https://gist.github.com/sergiocampama/bddf5a92c56cf6204660c1263593d5ea |
Fair enough, it was more out of curiosity.
The transport is the right abstraction here (this is the kind of use case we had in mind for it). The router will change slightly in the next beta (it'll become generic over a transport) so you'll need to continue using the transport I'm afraid. (The reason for this is so that we can avoid copying between
Did you consider using a task local here instead? |
yeah, the ergonomics of using transport are just a bit cumbersome, since it requires keeping a grpc server instance waiting, which also means having to deal with cancellation correctly (in the transport layer and the group task that keeps the server looping)... being able to pass in some bytes and having the router process that and return the result makes it much easier... I wasn't familiar with TaskLocal, but was able to use it correctly to avoid the service context layer, thanks for that pointer! I'll look at the next beta to figure out how I can make it easier on myself to support this frankenstein of a project |
The lifecycle of your transport is tied to Vapor, so that run loop for the transport is effectively "don't return until the Vapor server shuts down". I assume you can get that info from Vapor and then just emit that as an event on an Also wondering whether you can run the transport via Vapor's lifecycle mechanism? (I'm not too familiar with Vapor.) |
I'm implementing a Vapor server where I can process grpc-web and regular API routes. While I have the entire request/response flow working (custom transport implementation specific for grpc-web), I'm missing passing in more context into the gRPC services in relation to the request itself. Vapor's Request object is fairly complete with much context needed to process any kind of request, while ServerRequest from grpc-swift doesn't have much going on other than metadata.
Would it align with this project to extend these objects so that we can pass arbitrary contexts into the requests themselves, so that they can be injected along the request path into the GRPCService itself?
The text was updated successfully, but these errors were encountered: