Skip to content

A proposal of high-performance L7 network GoLang extension for Envoy. #15152

Closed

Description

@wangfakang

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:

image

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

  1. added
    triage
    on Feb 23, 2021
  2. snowp commented on Feb 23, 2021

    @snowp
    Contributor

    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?

  3. wangfakang commented on Feb 23, 2021

    @wangfakang
    MemberAuthor

    This essentially boils down to providing some stable C API for filter management, correct?

    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).

    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?

    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.

  4. mattklein123 commented on Feb 23, 2021

    @mattklein123
    Member

    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:

    • Cross referencing Does Envoy intend to evolve to an application runtime? #15113 which talks about using Envoy as an application platform (cc @nobodyiam). There is a lot of related concepts here, but in particular I really like the idea of allowing the embedding of Dapr style programs within Envoy that all exist out of the primary tree.
    • I really want to figure out how to intersect this work with the work that the Cilium folks have done (cc @jrajahalme @tgraf). IMO we should upstream the Cilium L4 extension also and figure out how to make things consistent between L4 and L7 as much as possible.

    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!

  5. added
    design proposal
    help wanted
    and removed
    triage
    on Feb 23, 2021
  6. snowp commented on Feb 23, 2021

    @snowp
    Contributor

    No, in this scenario C++ calls GoLang, not GoLang calls C++/C, so there is no need to implement the C API in Envoy.

    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?

  7. lizan commented on Feb 23, 2021

    @lizan
    Member

    +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.

  8. erir910 commented on Feb 23, 2021

    @erir910

    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 SELECT queries but not UPDATE or DELETE queries 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 protocol

  9. mathetake commented on Feb 23, 2021

    @mathetake
    Member

    +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.

    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?

    +1

  10. htuch commented on Feb 24, 2021

    @htuch
    Member

    @mandarjog the ext_proc work 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_proc is 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.

  11. wangfakang commented on Feb 24, 2021

    @wangfakang
    MemberAuthor

    No, in this scenario C++ calls GoLang, not GoLang calls C++/C, so there is no need to implement the C API in Envoy.

    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.

    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 = 1 and Golang passes the description to Envoy via the API, and then Envoy GoLang extension C++ filter will called decoder_callbacks->sendLocalReply() or encoder_callbacks->sendLocalReply() functions.

    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?

    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!

  12. 19 remaining items

  13. PiotrSikora commented on Mar 10, 2021

    @PiotrSikora
    Contributor

    maximum reusability of existing Go code did matter to us. We tried TinyGo, and it's simply not an alternative.

    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_proc is 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.

  14. mattklein123 commented on Mar 10, 2021

    @mattklein123
    Member

    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).

  15. daixiang0 commented on Jul 20, 2021

    @daixiang0
    Member

    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.

  16. wangfakang commented on Jul 20, 2021

    @wangfakang
    MemberAuthor

    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.

    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.

  17. mattklein123 commented on Jul 20, 2021

    @mattklein123
    Member
  18. dobegor commented on Dec 9, 2021

    @dobegor

    @PiotrSikora so we have a use case where neither ext_proc nor tinygo + wasm sdk help us - we want to validate requests according to the supplied OpenAPI schema.

    ext_proc just murders the performance and tinygo doesn'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.

  19. gbrail commented on Dec 9, 2021

    @gbrail
    Contributor
  20. dobegor commented on Dec 13, 2021

    @dobegor

    @gbrail sorry for a bit out-of-context (and probably hyperbolic) comment on ext_proc performance. 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_proc approach for our use case, but latency-critical applications would much more benefit from in-process validation on proxy side.

  21. gbrail commented on Dec 13, 2021

    @gbrail
    Contributor
  22. mattklein123 commented on Jan 4, 2022

    @mattklein123
    Member

    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?

  23. wangfakang commented on Jan 5, 2022

    @wangfakang
    MemberAuthor

    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?

    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.

  24. Patrick0308 commented on Jul 28, 2022

    @Patrick0308
    Contributor

    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.

    @wangfakang How's it going? Waiting for this feature.

  25. wangfakang commented on Aug 14, 2022

    @wangfakang
    MemberAuthor

    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.

    @wangfakang How's it going? Waiting for this feature.

    @Patrick0308 Thank you. Here's a PR #22573 about Envoy's L7 Go extension API, and thanks to @mattklein123 is helping to review it.

  26. wbpcode commented on Aug 2, 2023

    @wbpcode
    Member

    I think this should be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/godesign proposalhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions