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 initial scaffolding #1

Merged
merged 2 commits into from
Jul 11, 2024
Merged

Add initial scaffolding #1

merged 2 commits into from
Jul 11, 2024

Conversation

junr03
Copy link
Collaborator

@junr03 junr03 commented Jul 10, 2024

This PR adds the initial scaffolding for an Envoy filter using the WASM runtime written in rust. The filter shows quite a few of Envoy's capabilities relevant for the katanemo gateway:

  • interacting with the HTTP request and response flow
  • modifying http requests and responses
  • making out of band HTTP requests that affect the original client's HTTP request
  • logging
  • interacting with config values

Important callout: the only piece of functionality that is critical for the gateway that I have not explored yet is interacting with Envoy's stats objects. i.e, are we able to create and manipulate counters/gauges/histograms from the rust code? I am not sure yet. Figuring this out will be my next priority

In the event that that functionality is lacking we will need to either:

  1. Evaluate what the workload would be to extend the ABI
  2. Evaluate if writing the code natively (c++) would be more expedient.

Tests will come in a separate PR -- usually I would write tests in the same PR, but I wanted to get the scaffolding working and out so that @adilhafeez could start taking a look.

Signed-off-by: José Ulises Niño Rivera <junr03@users.noreply.github.com>
@junr03 junr03 requested a review from adilhafeez July 10, 2024 17:11
Copy link
Contributor

@adilhafeez adilhafeez left a comment

Choose a reason for hiding this comment

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

This is good @junr03. Few minor comments and questions.

For the envoy stats access this would be an issue. I also didn't find a way to interact with envoy stats from proxy-wasm interface. To add stats in ABI it would require change on proxy-wasm, envoy (as host) and getting buy-off from open-source community.

@@ -4,4 +4,9 @@ version = "0.1.0"
authors = ["Katanemo Inc <info@katanemo.com>"]
edition = "2018"
Copy link
Contributor

Choose a reason for hiding this comment

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

should be 2024

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

2021 is the last stable edition


## Building

```sh
Copy link
Contributor

Choose a reason for hiding this comment

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

Also need to add support for runtime wasm32-wasi before cross-compiling

$ rustup target add wasm32-wasi

Comment on lines +69 to +72
info!("Access granted.");
// This call allows the filter to continue operating on the HTTP request sent by the user.
// In Katanemo's use case the call would continue after the LLM host has responded with routing
// decisions.
Copy link
Contributor

Choose a reason for hiding this comment

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

At this point we need to look at response from llm and log additional metrics

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Exactly

// This call allows the filter to continue operating on the HTTP request sent by the user.
// In Katanemo's use case the call would continue after the LLM host has responded with routing
// decisions.
self.resume_http_request();
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Figuratively: yes
Literally: no, Envoy is event driven, not blocking. So that means that the filter has paused processing the http request until there is an event that initiates processing again. i.e it's not the case that execution stopped on line 73. The next line of execution would be on_http_request_body or similar. Does that make sense?

// RootContext allows the Rust code to reach into the Envoy Config
impl RootContext for HttpHeaderRoot {
fn on_configure(&mut self, _: usize) -> bool {
if let Some(config_bytes) = self.get_plugin_configuration() {
Copy link
Contributor

Choose a reason for hiding this comment

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

In upcoming PRs this would be converted to yaml file and verified according to schema spec.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It already comes to us converted and verified. However, it looks like the WASM filter schema is dynamic. I need to see if there is a way to define a structured schema via our own protobuf, so we can rely on Envoy's protobuf parser to verify for us.

Copy link
Contributor

Choose a reason for hiding this comment

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

that would be nice if we could use protbuf for validation etc.

@adilhafeez
Copy link
Contributor

@junr03 I did see that c++ wasm filter does support interaction with stats sink https://github.com/proxy-wasm/proxy-wasm-cpp-sdk/blob/3c7f786bf1e8bdd9537a640eeff1558e18bc9855/docs/wasm_filter.md#stats-api

@junr03
Copy link
Collaborator Author

junr03 commented Jul 10, 2024

@junr03 I did see that c++ wasm filter does support interaction with stats sink https://github.com/proxy-wasm/proxy-wasm-cpp-sdk/blob/3c7f786bf1e8bdd9537a640eeff1558e18bc9855/docs/wasm_filter.md#stats-api

Nice -- I don't mean to say that it is supported or not. Just a callout that of all the functionality we discussed using, the only immediate one I did not find (not that I looked too hard yet) was stats manipulation.

Lmk if my responses make sense and you feel comfortable landing this so we can work off of it.

Signed-off-by: José Ulises Niño Rivera <junr03@users.noreply.github.com>
@adilhafeez
Copy link
Contributor

Nice -- I don't mean to say that it is supported or not. Just a callout that of all the functionality we discussed using, the only immediate one I did not find (not that I looked too hard yet) was stats manipulation.

Sure let's keep exploring and see if we can find a way to create metrics inside envoy using proxy-wasm

@junr03 junr03 merged commit d3ddbd8 into main Jul 11, 2024
@junr03 junr03 deleted the initial-scaffolding branch September 5, 2024 00:30
@adilhafeez adilhafeez mentioned this pull request Oct 9, 2024
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.

2 participants