Skip to content

Commit

Permalink
refactor: reorder fault filter (envoyproxy#3059)
Browse files Browse the repository at this point in the history
Signed-off-by: ShyunnY <1147212064@qq.com>
  • Loading branch information
ShyunnY authored Apr 1, 2024
1 parent 69ffac8 commit a667f23
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions internal/xds/translator/httpfilters.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ type OrderedHTTPFilters []*OrderedHTTPFilter

// newOrderedHTTPFilter gives each HTTP filter a rational order.
// This is needed because the order of the filters is important.
// For example, the cors filter should be put at the first to avoid unnecessary
// For example, the fault filter should be placed in the first position because
// it doesn't rely on the functionality of other filters, and rejecting early can save computation costs
// for the remaining filters, the cors filter should be put at the second to avoid unnecessary
// processing of other filters for unauthorized cross-region access.
// The router filter must be the last one since it's a terminal filter.
//
Expand All @@ -86,18 +88,20 @@ func newOrderedHTTPFilter(filter *hcmv3.HttpFilter) *OrderedHTTPFilter {
order := 50

// Set a rational order for all the filters.
// When the fault filter is configured to be at the first, the computation of
// the remaining filters is skipped when rejected early
switch {
case filter.Name == wellknown.CORS:
case filter.Name == wellknown.Fault:
order = 1
case isFilterType(filter, extAuthFilter):
case filter.Name == wellknown.CORS:
order = 2
case isFilterType(filter, basicAuthFilter):
case isFilterType(filter, extAuthFilter):
order = 3
case isFilterType(filter, oauth2Filter):
case isFilterType(filter, basicAuthFilter):
order = 4
case filter.Name == jwtAuthn:
case isFilterType(filter, oauth2Filter):
order = 5
case filter.Name == wellknown.Fault:
case filter.Name == jwtAuthn:
order = 6
case filter.Name == localRateLimitFilter:
order = 7
Expand Down
2 changes: 1 addition & 1 deletion internal/xds/translator/httpfilters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ func Test_sortHTTPFilters(t *testing.T) {
httpFilterForTest(extAuthFilter + "-route1"),
},
want: []*hcmv3.HttpFilter{
httpFilterForTest(wellknown.Fault),
httpFilterForTest(wellknown.CORS),
httpFilterForTest(extAuthFilter + "-route1"),
httpFilterForTest(basicAuthFilter + "-route1"),
httpFilterForTest(oauth2Filter + "-route1"),
httpFilterForTest(jwtAuthn),
httpFilterForTest(wellknown.Fault),
httpFilterForTest(wellknown.HTTPRateLimit),
httpFilterForTest(wellknown.Router),
},
Expand Down

0 comments on commit a667f23

Please sign in to comment.