lua: Add per route config#9279
lua: Add per route config#9279dio wants to merge 6 commits intoenvoyproxy:masterfrom dio:per-route-lua-filter
Conversation
This patch adds Lua HTTP filter per route config. Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
|
@mattklein123 I'm not sure if this is the right approach to implement this. WDYT? |
mattklein123
left a comment
There was a problem hiding this comment.
Nice, this is cool. A few API comments to get started.
/wait
| // strings so complex scripts can be easily expressed inline in the configuration. | ||
| string inline_code = 1 [(validate.rules).string = {min_bytes: 1}]; | ||
|
|
||
| // The Lua source codes that Envoy will execute based on name. Key is Lua source code name, e.g. |
There was a problem hiding this comment.
nit: s/source codes/source code
| // The Lua source codes that Envoy will execute based on name. Key is Lua source code name, e.g. | ||
| // ``foo.lua``, this name can be referenced by | ||
| // :ref:`LuaPerRoute <envoy_api_msg_config.filter.http.lua.v2.LuaPerRoute>`. | ||
| map<string, api.v2.core.DataSource> source_codes = 2; |
There was a problem hiding this comment.
nit: s/source_codes/source_code
| @@ -18,4 +20,23 @@ message Lua { | |||
| // be properly escaped. YAML configuration may be easier to read since YAML supports multi-line | |||
| // strings so complex scripts can be easily expressed inline in the configuration. | |||
| string inline_code = 1 [(validate.rules).string = {min_bytes: 1}]; | |||
There was a problem hiding this comment.
From an API standpoint, it's kind of strange that we still require inline code if we now support named code. Should we now potentially relax requiring inline_code and deprecate it, and optionally allow a root/global code by name?
|
|
||
| // The name of a Lua source code defined in | ||
| // :ref:`Lua.source_codes <envoy_api_field_config.filter.http.lua.v2.Lua.source_codes>`. | ||
| string name = 2 [(validate.rules).string = {min_bytes: 1}]; |
There was a problem hiding this comment.
I get that you might want to lookup the code by name for performance/de-dup reasons, but wouldn't you also potentially want to allow the code to be delivered via RDS? I think this would block that? Should this be a oneof that allows either lookup by name or direct inline code?
There was a problem hiding this comment.
To clarify, "direct inline code" here is to open the possibility to "compile" code on the fly (when the route is being called)?
There was a problem hiding this comment.
Yeah that's what I meant, or at least have some type of facility to see if we already have a thread local Lua context ready for a per-route code? I'm not sure if we would then need some type of callback to clean this up. I would need to look into all of the ownership stuff in more detail to advise. But I think this is optimally how it would work and we should optimally make sure the API works for that? WDYT?
There was a problem hiding this comment.
SGTM. I'll update the PR to accommodate that first then.
|
@dio Thanks for implementing this! I just gave docker.io/dio123/envoy-lua a try with the following configuration: A few observations:
(To comment on Matt's remark: yes I'd love to deliver all of this via xDS) |
|
Played with it a bit more:
Adding an empty non-route specific envoy_on_request() ensures route1.lua's envoy_on_response() does run.. (hm.. how is possible that these two influence each other?)
Found the reason: this was caused by setting a non-valid header "Global catchall" with a space in it, my bad.
With 2 fixed it appears it falls back to running the non-route specific lua in case the per-route function does not exist. And I just noticed a per-route lua function followed by a for-all-routes lua function can be defined by having multiple "envoy.lua" filters in sequence. Nice 👍 |
|
@erikbos Thanks for testing the sketch.
I'll try to add this one. |
|
Re your issue on 1, I'll try to check it out and do some tests. |
|
This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions! |
|
This pull request has been automatically closed because it has not had activity in the last 14 days. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions! |
|
Is there any progress in this work? |
|
@wbpcode yes, I've been working on something else. I'll try to update this week. |
| ThreadLocal::SlotPtr tls_slot_; | ||
| uint64_t current_global_slot_{}; | ||
| absl::flat_hash_map<std::string, ThreadLocal::SlotPtr> tls_slot_map_; | ||
| absl::flat_hash_map<std::string, uint64_t> current_global_slot_map_; |
There was a problem hiding this comment.
Why not keep ThreadLocalState unchanged, but maintain a map in FilterConfig to manage different Lua scripts?
|
Thanks. I am very much looking forward to the completion of this function, because I just need this function recently. |
|
@dio I implemented a new version based on your commit and it seems to work fine. If you are too busy recently, maybe I can continue to complete this function based on your work. |
|
I'd like to see this functionality included as well :-) I am available for testing if you need a review. |
Description: This patch adds Lua HTTP filter per route config.
Risk Level: Low
Testing: unit test, integration test
Docs Changes: Added
Release Notes: Added
Fixes #3124
Signed-off-by: Dhi Aurrahman dio@tetrate.io