Repository navigation
Description
Background
Envoy is an excellent Sidecar in the field of Service Mesh. The use of modern C++ guarantees its high performance, but also increases the difficulty for developers. Although Envoy also supports Lua and WASM to enhance its scalability, there are some shortcomings in some scenarios (as shown in the table below); With the growth of GoLang's cloud native language ecology and popularity, We introduce a proposal that allows Envoy to support GoLang extension capabilities.
Lua vs GoLang vs WASM Extension on Envoy
| Name | Advantage | Disadvantage |
|---|---|---|
| Lua Extension | easier to develop | fewer SDKs supports and smaller ecosystem |
| GoLang Extension | richer ecology and more SDKs than Lua, less memory copies and higher performance than WASM | Isolation is not as strong as WASM,go runtime may cause more performance overhead |
| WASM Extension | Cross-language language support (C/C++/Rust), isolation, security, agility, etc | In the experimental stage, performance loss is large, Can not re-use the existing golang sdk, need to transform the network io |
Design
By adding the Http GoLang extension filter extension to Envoy's HTTP filter, users can implement Envoy's http filter using GoLang via the GoLang L7 extension SDK.
Http Golang extension filter
GoLang http extension filter on the Envoy side implemented in C++, this module is used to call the http filter implemented by the developer through GoLang.
GoLang L7 extension SDK
GoLang L7 extension SDK exports some CGO APIs for interaction between the Http GoLang extension filter and the GoLang http filter.
The specific architecture is as follows:
Best practice
Improve Dapr gRPC performence by Envoy L7 GoLang extension
In some scenarios, we need to use Envoy (mesh) and Dapr (application runtime implemented in GoLang) simultaneously. In these cases, we plan to make Dapr as an envoy's http2 filter (enabled by our GoLang extension module), and re-use the existing component sdks (the reason that we do not use Wasm is GoLang's prematured support of wasm, and the requirement of non-blocking IO model brought by Envoy). The combination of Dapr and Envoy makes it more convenient for maintainance and management than two seperated productions. Let alone the improvement on the performance for Dapr.
Run MOSN stream filter on Envoy via Envoy L7 GoLang extension
In the MOSN project, we use GoLang through the Envoy GoLang extension module(experimental stage) to easily implement Envoy's dynamic routing capabilities: mosn/mosn#1563.
Looking forward to your ideas/comments on this proposal! @mattklein123 @htuch @alyssawilk @lizan thanks.

Activity
snowp commentedon Feb 23, 2021
This essentially boils down to providing some stable C API for filter management, correct?
I think in the past we've been trying to avoid having to provide a C API for Envoy due to the heavy use of C++ features like polymorphism (which becomes non-trivial to map to C) and wanting to avoid yet another set of APIs to maintain, which would slow down our ability to iterate on the existing C++ APIs.
I believe Cilium did this for L4 filters (https://github.com/cilium/proxy/blob/master/proxylib/libcilium.h), but that has a substantially API surface area than L7 (e.g. it doesn't require mapping HeaderMap into C).
Do you have a sense of what the APIs would look like to make this a useful feature?
wangfakang commentedon Feb 23, 2021
No, in this scenario C++ calls GoLang, not GoLang calls C++/C, so there is no need to implement the C API in Envoy. BTW Http GoLang filter is a common extension filter of Envoy Http, and will not modify filter management, it's similar to the way that Envoy supports Lua extension (https://github.com/envoyproxy/envoy/tree/main/source/extensions/filters/http/lua).
Cilium L4 filter is a good extension, users can easily use GoLang to do some flow control (such as do some control on network policies) at L4. But L4 is not convenient to get some L7 information (such as request/response headers, trailers, etc.), which means that some of the best practices (such as dynamic routing based on request headers, etc.) mentioned above cannot be implemen via L4 extension filter, so we proposed to add the L7 GoLang extension to enhance Envoy's ability to extend the http filter through GoLang at L7.
mattklein123 commentedon Feb 23, 2021
In general I'm in favor of doing this as I think it would unlock a huge amount of extensibility within the existing cloud native ecosystem. A few high level comments:
I think the next steps here are to put together a more long form gdoc/design doc on this topic, and hopefully connect with the Cilum folks to come up with a shared plan. Feel free to email me if folks need help connecting. Thank you!
snowp commentedon Feb 23, 2021
The existing C++ filter API is heavily callback driven, so if we want to expose the full power of C++ filters we'd need to provide a way for the filter to interact with these callbacks, which would require a way to interact with this API through C.
If the scope of this is much smaller and more in line with what the Cilium L4 filter does, then the complexity of this is greatly reduced.
I guess my point is that it's not clear to me what the desired scope of this functionality is. Do we have a sense of what the API would have to look like in order to power the listed use cases?
lizan commentedon Feb 23, 2021
+1 In general this looks great. We've been thinking of using the WASM ABI as the stable C API, so that might hold here as well. We already have Null (native) WASM extension (which is not in WASM sandboxed but statically linked), so the CGO interface could be just based on that as well.
cc @mathetake working on WASM and Go WASM SDK as well.
erir910 commentedon Feb 23, 2021
Can I ask a stupid question? why not just introduce a gRPC API with an interface similar to https://github.com/proxy-wasm/proxy-wasm-rust-sdk/blob/master/examples/http_headers.rs? . I undestand that gRPC may imply huge latency penalty but when using Envoy as sidecar, the communication is usually done over localhost. Also I am not sure how this would work for wasm or golang or whatever for any case other than HTTP since Envoy understands HTTP. For example, what if I want to use this to authorize mysql traffic (e.g. allow
SELECTqueries but notUPDATEorDELETEqueries depending on the downstream IP for instance). This feature would be huge since this would make Envoy not just a typical TCP/HTTP proxy but extensible to any l7 protocolmathetake commentedon Feb 23, 2021
+1 in general, but we will definitely face tons of issues in GC and any other Go's language level runtime issues (e.g. When to run GC if an extension allocates inside Go?).
Would love to see the design doc so that we could discuss this down to the implementation detail.
+1
mandarjog commentedon Feb 24, 2021
@htuch how does this compare with grpc-remote filters proposal ?
https://github.com/gbrail/envoy/blob/master/api/envoy/extensions/filters/http/ext_proc/v3alpha/ext_proc.proto
@gbrail
htuch commentedon Feb 24, 2021
@mandarjog the
ext_procwork now has landed API, which is at https://github.com/envoyproxy/envoy/tree/main/api/envoy/extensions/filters/http/ext_proc/v3alpha and implementation is happening. @gbrail is the best contact here.IMHO, if we wanted to go out-of-process, something like
ext_procis desirable. If we want to stay in process, I think this CGO API is interesting for Go, but it would behoove us to try understand how the Go filter chains described and runtime environment relate to the Wasm one. We have already built out new things like shared queues and cross-extension state for Wasm. I'm a bit wary that we're building multiple runtimes/ecosystems that don't share much in common. To the extent that the Go efforts can build on some of the runtime environment features that have arisen in the Wasm context it would be neat.wangfakang commentedon Feb 24, 2021
I think it is not necessary for GoLang extension to expose full the API of C++ filter's callback. In addition, the callback of Envoy C++ filter don't necessary to be called API through C, we can design a call description between C++ and GoLang filter; For example, if set
C.struct_GolangResponse.direct_response = 1and Golang passes the description to Envoy via the API, and then Envoy GoLang extension C++ filter will calleddecoder_callbacks->sendLocalReply()orencoder_callbacks->sendLocalReply()functions.The L4 is not convenient to get some L7 request infomation (such as request/response headers, trailers, etc.) which means that some of the best practices (such as dynamic routing based on request headers or improve Dapr gRPC performence by Envoy L7 GoLang extension, etc.) mentioned above cannot be implement via L4 extension filter.
As @mattklein123 suggested, the next step we'll put a long form design doc on this topics. Then we could discuss the design details. Thank you!
19 remaining items
PiotrSikora commentedon Mar 10, 2021
Could you elaborate on what exactly didn't work for you, so that we can improve it in the future? Is your issue primarly with the Proxy-Wasm sandbox (i.e. lack of wide-open access to the host environment and the outside world) or with the limitations of the TinyGo runtime?
Also, is there a reason why
ext_procis not a viable solution and why you need those extensions to run in-process?Basically, I'm trying to find a proper justification for adding the 4th option, and that includes understanding why the existing options don't work.
If the primary reason is indeed "we need a full Go runtime" and not "Proxy-Wasm is too slow", then I think we should evaluate performance against a
ext_proc-based solution, since there is a lot of discussion about "high-performance" in this thread, but there are no numbers backing this claim.mattklein123 commentedon Mar 10, 2021
Just to reiterate, @PiotrSikora is doing an excellent job in being really clear about what should be in the design doc / proposal. This is similar to what myself and @htuch are saying, just more fully formed. I think we are all on the same page on what we would like to see before we decide to move forward (or not).
daixiang0 commentedon Jul 20, 2021
What is the current progress? I really like to see Envoy support Golang Extension, it would make Envoy more flexible as more and more application runtime or other type of runtime occur, my team as well.
wangfakang commentedon Jul 20, 2021
Currently, the proposal is in the review stage, and here is a draft about Envoy’s GoLang extension proposal.
cc @mattklein123 @htuch @lizan @PiotrSikora @jrajahalme @bkgs
Looking forward to your ideas/comments on this proposal! thanks.
mattklein123 commentedon Jul 20, 2021
I think this will be a good candidate for the contrib/ proposal once that lands: https://docs.google.com/document/d/1yl7GOZK1TDm_7vxQvt8UQEAu07UQFru1uEKXM6ZZg_g/edit#heading=h.e31y5myyfztx
dobegor commentedon Dec 9, 2021
@PiotrSikora so we have a use case where neither
ext_procnor tinygo + wasm sdk help us - we want to validate requests according to the supplied OpenAPI schema.ext_procjust murders the performance andtinygodoesn't support a lot of things that are required to parse json/yaml/xml, just as @bkgs has said.So we'd be very happy to have a first-class Go extension API to solve these problems. Are there any formal points that need to be added to the proposal doc?
Thank you.
gbrail commentedon Dec 9, 2021
dobegor commentedon Dec 13, 2021
@gbrail sorry for a bit out-of-context (and probably hyperbolic) comment on
ext_procperformance. What I meant was actually the latency that would be much higher if we use this approach instead of in-process request validation. Not that it matters for all use cases (it would add no more than ~40ms tops), but some use cases may not enjoy this.Currently we decided to go with
ext_procapproach for our use case, but latency-critical applications would much more benefit from in-process validation on proxy side.gbrail commentedon Dec 13, 2021
mattklein123 commentedon Jan 4, 2022
I would be interested in seeing this land. As we have contrib now can we just start out with a contrib extension and go from there?
wangfakang commentedon Jan 5, 2022
hi @mattklein123 We have used this proposal of Envoy’s GoLang extension in our internal gateway scenario in 2021 and have achieved good results. We are currently using it to land in the ServiceMesh scenario, and there is still some work to be done, such as goLang plugins managed by Istio, stability, usability, etc. We will compile the documentation and code for submission after we have verified and landing in the ServiceMesh scenario.
Patrick0308 commentedon Jul 28, 2022
@wangfakang How's it going? Waiting for this feature.
wangfakang commentedon Aug 14, 2022
@Patrick0308 Thank you. Here's a PR #22573 about Envoy's L7 Go extension API, and thanks to @mattklein123 is helping to review it.
wbpcode commentedon Aug 2, 2023
I think this should be done.