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: support custom HTTP filter ordering #3273

Merged
merged 8 commits into from
May 7, 2024

Conversation

zhaohuabing
Copy link
Member

@zhaohuabing zhaohuabing commented Apr 25, 2024

This PR allows users to adjust HTTP filter orders to suit their specific use cases.
It also:

  • adds a constraint limiting each EnvoyExtensionPolicy to have a maximum of 16 wasm/extproc extensions.
  • Fixes the JSON tag in FilterPosition API

Note: this PR doesn't handle the ordering of individual wasm/extproc extensions. This will be addressed in a follow-up PR, as it involves API change and may need more discussion.

Related: #2571 #2993

@zhaohuabing zhaohuabing requested a review from a team as a code owner April 25, 2024 14:12
@zhaohuabing zhaohuabing marked this pull request as draft April 25, 2024 14:12
@zhaohuabing zhaohuabing force-pushed the filter-order-impl branch 3 times, most recently from 884326f to 61586ce Compare April 25, 2024 14:38
@alexwo
Copy link
Contributor

alexwo commented Apr 25, 2024

/retest

@zhaohuabing zhaohuabing force-pushed the filter-order-impl branch 3 times, most recently from 6aff883 to 42c3626 Compare April 25, 2024 19:13
Copy link

codecov bot commented Apr 25, 2024

Codecov Report

Attention: Patch coverage is 94.66667% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 66.94%. Comparing base (29946b0) to head (42c3626).
Report is 134 commits behind head on main.

❗ Current head 42c3626 differs from pull request most recent head e4f6a93. Consider uploading reports for the commit e4f6a93 to get more accurate results

Files Patch % Lines
internal/xds/translator/httpfilters.go 93.54% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3273      +/-   ##
==========================================
+ Coverage   66.51%   66.94%   +0.42%     
==========================================
  Files         161      163       +2     
  Lines       22673    23370     +697     
==========================================
+ Hits        15080    15644     +564     
- Misses       6720     6816      +96     
- Partials      873      910      +37     

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

@zhaohuabing zhaohuabing marked this pull request as ready for review April 25, 2024 19:38
@zhaohuabing zhaohuabing requested review from arkodg and guydc April 25, 2024 19:38
Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
@zhaohuabing zhaohuabing force-pushed the filter-order-impl branch 2 times, most recently from e46dd33 to e7b276c Compare May 1, 2024 21:21
Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
}

// Sort the filters in the custom order.
for i := 0; i < len(filterOrder); i++ {
Copy link
Contributor

@guydc guydc May 3, 2024

Choose a reason for hiding this comment

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

Is this a topological sorting problem? Can we use/reference an established algorithm (and possibly library) to create this sort? It would make it a bit easier to be convinced in the functional correctness.

Copy link
Contributor

Choose a reason for hiding this comment

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

this logic could be simplified

  1. init - ordered list
  2. loop across filterOrder (overrideList)
  3. find name, and delete it from list
  4. find before or after and insert it before/after in list

Its still m (orig list)*n (override list) with both sizes being fairly small, but easier to comprehend

Copy link
Member Author

@zhaohuabing zhaohuabing May 3, 2024

Choose a reason for hiding this comment

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

Is this a topological sorting problem? Can we use/reference an established algorithm (and possibly library) to create this sort? It would make it a bit easier to be convinced in the functional correctness.

I didn't find a good way to combine two DAGs: the original one and the custom one. Since we have checked the cycle dependencies in the Gateway API reconciler, would the current implementation be sufficient?

Copy link
Contributor

@guydc guydc left a comment

Choose a reason for hiding this comment

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

Do we need to validate that we don't have cycles like:

  spec:
    filterOrder:
      - name: envoy.filters.http.jwt_authn
        before: envoy.filters.http.cors
      - name: envoy.filters.http.cors
        before: envoy.filters.http.jwt_authn

@arkodg
Copy link
Contributor

arkodg commented May 3, 2024

Do we need to validate that we don't have cycles like:

  spec:
    filterOrder:
      - name: envoy.filters.http.jwt_authn
        before: envoy.filters.http.cors
      - name: envoy.filters.http.cors
        before: envoy.filters.http.jwt_authn

imo if we apply in order, we wont hit this issue, right ?

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
@zhaohuabing
Copy link
Member Author

zhaohuabing commented May 3, 2024

Do we need to validate that we don't have cycles like:

  spec:
    filterOrder:
      - name: envoy.filters.http.jwt_authn
        before: envoy.filters.http.cors
      - name: envoy.filters.http.cors
        before: envoy.filters.http.jwt_authn

imo if we apply in order, we wont hit this issue, right ?

Added a check for a more friendly UI.

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
@zhaohuabing zhaohuabing requested review from guydc and arkodg May 6, 2024 17:34
Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
@zhaohuabing zhaohuabing requested a review from arkodg May 6, 2024 23:21
@zhaohuabing zhaohuabing force-pushed the filter-order-impl branch from 6f69b50 to e4f6a93 Compare May 6, 2024 23:38
Copy link
Contributor

@arkodg arkodg left a comment

Choose a reason for hiding this comment

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

LGTM thanks
thanks for adding those extra comments which will help the next dev looking at the code !

@arkodg arkodg requested review from a team May 6, 2024 23:43
@zirain zirain merged commit d048a9f into envoyproxy:main May 7, 2024
25 checks passed
@zirain zirain mentioned this pull request May 9, 2024
This was referenced May 23, 2024
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.

5 participants