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

filtermanager: skip method was broken when there are multi plugins #308

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pkg/filtermanager/filtermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,18 @@ func FilterManagerFactory(c interface{}, cb capi.FilterCallbackHandler) capi.Str
fm := conf.pool.Get().(*filterManager)
fm.callbacks.FilterCallbackHandler = cb

canSkipMethod := fm.canSkipMethod
if canSkipMethod == nil {
canSkipMethod = newSkipMethodsMap()
}

filters := make([]*filterWrapper, len(newConfig))
for i, fc := range newConfig {
factory := fc.Factory
config := fc.ParsedConfig
f := factory(config, fm.callbacks)
// Technically, the factory might create different f for different calls. We don't support this edge case for now.
if fm.canSkipMethod == nil {
canSkipMethod := newSkipMethodsMap()
for meth := range canSkipMethod {
ok, err := isMethodFromPassThroughFilter(f, meth)
if err != nil {
Expand All @@ -366,11 +370,13 @@ func FilterManagerFactory(c interface{}, cb capi.FilterCallbackHandler) capi.Str
}
canSkipMethod[meth] = canSkipMethod[meth] && ok
}
fm.canSkipMethod = canSkipMethod
}
filters[i] = newFilterWrapper(fc.Name, f)
}

if fm.canSkipMethod == nil {
fm.canSkipMethod = canSkipMethod
}
fm.filters = filters

if conf.consumerFiltersEndAt != 0 {
Expand Down
25 changes: 25 additions & 0 deletions pkg/filtermanager/filtermanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,31 @@ func (f *addReqFilter) DecodeHeaders(headers api.RequestHeaderMap, endStream boo
return api.Continue
}

func TestSkipMethodWhenThereAreMultiFilters(t *testing.T) {
cb := envoy.NewCAPIFilterCallbackHandler()
config := initFilterManagerConfig("ns")
config.current = []*model.ParsedFilterConfig{
{
Name: "add_req",
Factory: addReqFactory,
ParsedConfig: addReqConf{
hdrName: "x-htnn-route",
},
},
{
Name: "on_log",
Factory: onLogFactory,
},
}

for i := 0; i < 2; i++ {
m := FilterManagerFactory(config, cb).(*filterManager)
assert.Equal(t, false, m.canSkipOnLog)
assert.Equal(t, false, m.canSkipDecodeHeaders)
assert.Equal(t, true, m.canSkipDecodeData)
}
}

func TestFiltersFromConsumer(t *testing.T) {
cb := envoy.NewCAPIFilterCallbackHandler()
config := initFilterManagerConfig("ns")
Expand Down