[model-gateway] Add WASM support for middleware#12471
[model-gateway] Add WASM support for middleware#12471slin1237 merged 48 commits intosgl-project:mainfrom
Conversation
Summary of ChangesHello @tonyluj, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
2911de1 to
f06aade
Compare
There was a problem hiding this comment.
Code Review
This is a comprehensive and well-structured pull request that adds significant new functionality with WASM-based middleware. The implementation covers runtime integration, a management API, security sandboxing, and helpful examples. My feedback focuses on improving robustness by handling potential panics during startup, enhancing maintainability by suggesting refactoring to reduce code duplication, and promoting safer coding practices in the example modules by avoiding unsafe code. I have also identified some potentially unused code that could be removed.
4b28fb3 to
e866c28
Compare
e866c28 to
307ee57
Compare
e52a6a4 to
3dc0f3b
Compare
Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
…e clean (sgl-project#12471) Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
…MIT_SATE (sgl-project#12471) Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
…#12471) Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
…ct#12471) Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
e54f6df to
42df7e8
Compare
Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
codespell doesn't know WIT. Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
Signed-off-by: Tony Lu <tonylu@linux.alibaba.com>
Motivation
This PR implements WebAssembly-based extensibility for sgl-router, enabling dynamic, safe, and portable middleware execution without requiring router restarts or recompilation. This addresses the feature request in #10902 .
Modifications
Core Infrastructure
wasmtimeas the primary runtime with async support and WebAssembly Component Modelwit/spec.wit)/wasmfor dynamic module management:POST /wasm- Deploy modulesGET /wasm- List all modules and metricsDELETE /wasm/{uuid}- Remove a moduleMiddleware Support
OnRequestandOnResponselifecycle hooksContinue- Proceed to next middleware/upstreamReject(status)- Return error response immediatelyModify- Modify headers, body, or status codeSecurity & Resource Management
Configuration
enable_wasmflag toRouterConfigRouterConfigBuilder::enable_wasm(bool)methodExamples
Three complete example implementations:
wasm-guest-auth: API key authentication middleware
Authorizationheader orx-api-key401 Unauthorizedfor invalid/missing keyswasm-guest-logging: Request tracking and status conversion
x-request-id,x-wasm-processed, etc.)500errors to503wasm-guest-ratelimit: Rate limiting middleware
429 Too Many Requestswhen exceededMetrics
/wasmendpoint:Implementation Details
Architecture
WIT Interface
Uses WebAssembly Component Model with WIT for type-safe communication:
middleware-on-request::on-request(req: Request) -> Actionmiddleware-on-response::on-response(resp: Response) -> ActionExecution Flow
OnRequestAction(Continue/Reject/Modify)OnResponseprocess responseUsage
Enable WASM Support
Deploy a Module
List Modules
Testing
Checklist