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

Question about managing state across multiple phases calls in ext-proc for a HTTP request lifecycle #35317

Closed
xr opened this issue Jul 22, 2024 · 4 comments
Labels
area/ext_proc question Questions that are neither investigations, bugs, nor enhancements

Comments

@xr
Copy link

xr commented Jul 22, 2024

Hi, It seems like ext-proc will call the process over gRPC with multiple stages as soon as it can. In case I need to maintain some state per HTTP request on the external server, I'm curious if there's anything we could leverage in ext-proc.

In the WASM filter, each httpContext corresponds to a single HTTP request lifecycle (request/response), meaning the application does not need to manage its own state. I'm wondering if there's a similar mechanism in ext-proc.

For example, how can we check whether an incoming onResponseHeaders is part of the same HTTP request stream as a previous onRequestHeaders call without maintaining the state ourselves?

Some custom solutions I could come up with:

  1. Whenever I receive ProcessingRequest_RequestHeaders, generate a unique contextId or leverage the envoy requestId attribute.
  2. Keep the state based on the contextId in our own logic.
  3. Whenever I receive ProcessingRequest_ResponseHeaders, use the contextId to retrieve the proper state.

It would be great if we have a way to abstract away the above custom logic for maintaining the state, or it might be better to keep the logic externally from envoy, appreciate any insight!

@xr xr added the triage Issue requires triage label Jul 22, 2024
@xr xr changed the title Question about the state across multiple phases calls in ext-proc for a HTTP request lifecycle Question about managing state across multiple phases calls in ext-proc for a HTTP request lifecycle Jul 22, 2024
@yanavlasov yanavlasov added question Questions that are neither investigations, bugs, nor enhancements area/ext_proc and removed triage Issue requires triage labels Jul 22, 2024
@yanavlasov
Copy link
Contributor

Adding @tyxia @yanjunxiang-google for comments.

@yanjunxiang-google
Copy link
Contributor

yanjunxiang-google commented Jul 22, 2024

HI, @xr
One way I can think of is to have the ext_proc server to track the gRPC stream open/close events, as Envoy starts a new gRPC stream to communicate with ext_proc server for each HTTP stream.

@tyxia
Copy link
Member

tyxia commented Jul 22, 2024

@xr No additional work is required from ext_proc filter side as such an affinity model has already been maintained in ext_proc's gRPC callout.

This can be purely your external server logic: On the first event (e.g., request header), server has a unique ID per stream and maintain it throughout HTTP lifecycle (request/response).
We actually have an internal product that is doing something similar. And it has been working well.

@xr
Copy link
Author

xr commented Jul 23, 2024

@yanjunxiang-google @tyxia thanks for the info! good to hear that you are doing sth similar, if each http stream is corresponding with one grpcStream then I could also store the http state inside grpc stream.

@xr xr closed this as completed Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ext_proc question Questions that are neither investigations, bugs, nor enhancements
Projects
None yet
Development

No branches or pull requests

4 participants