Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement Lua EnvoyExtensionPolicy #5171

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

rudrakhp
Copy link
Member

What type of PR is this?

feat: implement Lua feature in EnvoyExtensionPolicy

What this PR does / why we need it:
Implement API introduced in #4932

Which issue(s) this PR fixes:

Related #4627

Release Notes: No

@rudrakhp rudrakhp requested a review from a team as a code owner January 28, 2025 18:54
@rudrakhp
Copy link
Member Author

@arkodg @zhaohuabing Wanted to get an initial buy in regarding the approach while I add more unit tests and E2E, please do review. Thanks!

Copy link

codecov bot commented Jan 28, 2025

Codecov Report

Attention: Patch coverage is 67.18750% with 63 lines in your changes missing coverage. Please review.

Project coverage is 66.95%. Comparing base (c1e18b2) to head (330e1d8).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
internal/xds/translator/lua.go 60.27% 19 Missing and 10 partials ⚠️
internal/provider/kubernetes/controller.go 0.00% 18 Missing and 1 partial ⚠️
internal/gatewayapi/envoyextensionpolicy.go 81.81% 10 Missing and 2 partials ⚠️
internal/gatewayapi/luavalidator/lua_validator.go 87.50% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #5171    +/-   ##
========================================
  Coverage   66.94%   66.95%            
========================================
  Files         211      213     +2     
  Lines       33176    33360   +184     
========================================
+ Hits        22210    22336   +126     
- Misses       9620     9664    +44     
- Partials     1346     1360    +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@arkodg
Copy link
Contributor

arkodg commented Jan 28, 2025

hey @rudrakhp the code looks great !

please feel free to continue with unit tests and e2e

@rudrakhp rudrakhp force-pushed the feat_lua_extension branch 24 times, most recently from b256946 to 9e01f0e Compare February 3, 2025 04:59
@rudrakhp rudrakhp force-pushed the feat_lua_extension branch 14 times, most recently from 3bce57a to 79bb214 Compare February 7, 2025 03:51
@arkodg arkodg requested a review from zhaohuabing February 8, 2025 00:51
Copy link
Member

@zhaohuabing zhaohuabing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rudrakhp we need to set the default order for the Lua filters in the filter chain, similart to what have been done to the Wasm and other filters.

case isFilterType(filter, egv1a1.EnvoyFilterWasm):

internal/ir/xds.go Outdated Show resolved Hide resolved
Copy link
Member

@zhaohuabing zhaohuabing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lua filter has built-in perRoute support, so we won't need to create a seperate lua filter for each route.

I think it's fine to keep the current implmentation as it's a generic approach to support configuration per route. If we find any issues with the multple-filter approach, we can then switch to the built-in perRoute approach.

https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/filters/http/lua/v3/lua.proto#envoy-v3-api-msg-extensions-filters-http-lua-v3-luaperroute

@rudrakhp
Copy link
Member Author

rudrakhp commented Feb 11, 2025

gateway/internal/xds/translator/httpfilters.go

Thanks for the comments @zhaohuabing , wanted to understand the rationale behind the ordering of the filters. Although the comments explained the high level thought process, didn't get why there is a huge gap of order between ExtProc and WASM, considering these two (along with Lua) are similar filters this is to give room for multiple ExtProc and WASM filters I guess. IMO it makes sense to execute Lua first as they are light weight compared to ExtProc or WASM, WDYT?

@rudrakhp
Copy link
Member Author

rudrakhp commented Feb 11, 2025

Lua filter has built-in perRoute support, so we won't need to create a seperate lua filter for each route.

Yes I started with LuaPerRoute filter but finally followed the generic framework we have for WASM and ExtProc, adding all Lua filters and enabling them as required per route.

Reason is that without a Lua filter, LuaPerRoute doesn't work. So if we want to define a LuaPerRoute filter with name envoy.filters.http.lua/envoyextensionpolicy/default/policy-for-http-route/lua/0, a Lua filter with same name needs to be present with no op code in HCM, that per route filter will eventually override. I preferred the current implementation because it was cleaner than this.

@zhaohuabing
Copy link
Member

zhaohuabing commented Feb 12, 2025

IMO it makes sense to execute Lua first as they are light weight compared to ExtProc or WASM, WDYT?

I'm fine with putting Lua infront of ExtProc and Wasm. The order is adjustable if users want to change the default filter order in the filter chain.

Copy link
Member

@zhaohuabing zhaohuabing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signed-off-by: Rudrakh Panigrahi <[email protected]>
@rudrakhp
Copy link
Member Author

Can you please also inclue lua filter to the EnvoyFilter API CEL rule and update the API doc for FilterOrder ? Thanks!

@zhaohuabing done!

Copy link
Member

@Xunzhuo Xunzhuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on it! Hope to have a user-guide docs for a following PR.

@arkodg arkodg merged commit 6022624 into envoyproxy:main Feb 12, 2025
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants