参考
- https://github.com/higress-group/proxy-wasm-go-sdk/tree/main/proxywasm
- https://github.com/tetratelabs/proxy-wasm-go-sdk
- https://github.com/alibaba/higress/blob/main/plugins/wasm-go/pkg/wrapper
- https://tinygo.org/docs/reference/
- https://tinygo.org/docs/reference/lang-support/stdlib/
mse网关及插件的测试
网关转发到上游服务
istio中加载wasm插件
go语言通过tinygo编译wasm文件
TinyGo 是一个 Go 编译器,旨在用于微控制器,WebAssembly(WASM)和命令行工具等小型场景。它重用了 Go 语言工具和 LLVM 一起使用的库,以提供编译用 Go 编程语言编写的程序的另一种方法。
tinygo build -o main.wasm -scheduler=none -target=wasi -gc=custom -tags='custommalloc nottinygc_finalizer' ./main.go
本地测试wasm具体步骤
Here is a brief explanation of the effective mechanism of the plugin:(下面对插件的有效机制作简要说明:)
- The user compiles the code into a Wasm file(用户编译代码为wasm文件)
- The user builds the Wasm file into a Docker image(用户将wasm文件构建为Docker镜像)
- The user pushes the Docker image to the image registry(用户将Docker镜像推送到镜像仓库)
- The user creates the WasmPlugin resource(用户创建WasmPlugin资源)
- Istio watches changes of the WasmPlugin resource(Istio监听WasmPlugin资源的变化)
- The xDS proxy process in Higress Gateway obtains the configuration from Istio and finds the image address of the plugin.(Higress Gateway中的xDS代理进程从Istio获取配置,并找到插件的镜像地址)
- xDS proxy pulls images from the image registry.(xDS代理从镜像仓库拉取镜像)
- xDS proxy extracts the Wasm file from the image.(xDS代理从镜像中提取wasm文件)
- The envoy process in the Higress Gateway obtains the configuration from the xDS proxy and discovers the local path of the Wasm file.(Higress Gateway中的envoy进程从xDS代理获取配置,并发现wasm文件的本地路径)
- Envoy loads the Wasm file from the local file.(Envoy从本地文件加载wasm文件)
Here, Envoy uses the Extension Config Discovery Service (ECDS) mechanism to obtain the configuration and load the Wasm file, which realizes the update of the Wasm file and direct hot loading without causing any connection interruption, and the business traffic is completely lossless.(这里Envoy使用Extension Config Discovery Service(ECDS)机制获取配置并加载wasm文件,实现了wasm文件的更新和直接热加载,不会造成任何连接中断,业务流量完全无损。)
xDS代理是一种用于管理服务发现和负载均衡的代理程序。在微服务架构中,服务之间需要相互通信,而xDS代理则可以帮助实现这种通信。xDS代理通过与服务注册中心进行交互,获取当前可用的服务实例信息,并根据负载均衡策略将请求分发到合适的服务实例上。同时,xDS代理还能够监控服务实例的健康状态,及时更新服务列表,确保服务的高可用性和稳定性。常见的xDS代理有Envoy、Nginx等。
TinyGo 是一个 Go 编译器,旨在用于微控制器,WebAssembly(WASM)和命令行工具等小型场景。它重用了 Go 语言工具和 LLVM 一起使用的库,以提供编译用 Go 编程语言编写的程序的另一种方法。