Skip to content

api: new field to the FilterConfig to disable a filter in specific route or vh #25927

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

Merged
merged 4 commits into from
Mar 16, 2023

Conversation

wbpcode
Copy link
Member

@wbpcode wbpcode commented Mar 6, 2023

Commit Message: api: new field to the FilterConfig to disable a filter in specific route or vh
Risk Level: low.
Testing: n/a.
Docs Changes: n/a.
Release Notes: n/a.
Platform Specific Features: n/a.

…ute or vh

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
@repokitteh-read-only
Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @markdroth
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #25927 was opened by wbpcode.

see: more, trace.

@wbpcode wbpcode assigned htuch and kyessenov and unassigned markdroth Mar 6, 2023
@wbpcode
Copy link
Member Author

wbpcode commented Mar 6, 2023

draft idea to the #20867

@htuch
Copy link
Member

htuch commented Mar 7, 2023

Is this just a generic filter disable at round config override level? Seems reasonable to me. CC @envoyproxy/api-shepherds

@wbpcode
Copy link
Member Author

wbpcode commented Mar 7, 2023

Is this just a generic filter disable at round config override level? Seems reasonable to me. CC @envoyproxy/api-shepherds

Yeap. By this way, we can disable any filter in a specific route and needn't change any API of the filter. It means that the different routes could execute complete different filter chains.

ideally, we can skip the disabled filters' creation when we create the filter chain. Then the disable filters will not bring any additional overhead at runtime.

@adisuissa
Copy link
Contributor

Thanks, this LGTM, and I like the idea of making it general across all filters.
One thing to note is what should happen to "Overridden" configs (some also have their own "disabled" flag) that have this flag set to true.
IMHO the config should be rejected, but not sure how to implement this in a better way other than looking at all filters adding this validation.

ideally, we can skip the disabled filters' creation when we create the filter chain. Then the disable filters will not bring any additional overhead at runtime.
That would be nice, but I'm not sure how this can be done for a per-route override. Some other route may need that filter, and so it is challenging to know which filters to instantiate a-priori.

@@ -2384,4 +2384,8 @@ message FilterConfig {
// not support the specified filter, it may ignore the map entry rather
// than rejecting the config.
bool is_optional = 2;

// If true, the filter is disabled in the route or virtual host and the
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the comment here should make it clear that the intent is to not even include the filter in the filter chain in the first place, as opposed to including the filter and having it be a no-op. Otherwise it's not clear why we need this, since most individual filters already have a way to turn themselves into a no-op.

I think we should also document the fact that the decision to exclude the filter is made when the route is initially chosen for the request, before the first filter is called. If one of the filters later changes attributes of the request and recomputes the route, it is too late at that point to change the set of filters that will be run for the request.

Copy link
Member Author

Choose a reason for hiding this comment

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

Wow, you got it. that's what I want completely. 👍

Although, in my original opinion, the behavior depend on the implementation so I initially intend to document it more detailedly in a seperated doc.

@kyessenov
Copy link
Contributor

This sounds reasonable to me too, as an alternative to composite filters for the typed_per_filter_configs, as a way to exempt some traffic from filters.

wbpcode added 2 commits March 8, 2023 07:02
Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
@wbpcode
Copy link
Member Author

wbpcode commented Mar 8, 2023

More detailed comment is added.

Advantages of this way:

  • Better performance. We can evaluate all these disable flag at config loading phase and skip unnecessary filter creations. And the disabled filters will skipped completely, no any decode*/encode* methods will be called.
  • Less memory overhead at runtime. Disabled filters will not be created.
  • Generic way to disable any filter and no any code/API change is necessary to the target filter.
  • Route level filter chain. Customize filter chain by enable/disable different filters set. (May be we can add a flag to tell envoy only add the explictly enabled filters to the filter chain in the future. 🤔 It will be helpful if there are lots of filters and most of routes only need one or two of these filters, for example enable cors for route A, enable ext_authz for route B, and enable cache for route C, etc.)

Disadvantages of this way:

  • Not friendly to the route refresh.
  • Some more memory to store the enable/disable flag.

@kyessenov
Copy link
Contributor

@wbpcode I don't recall - does this require that a filter explicitly implements "most specific filter config" in code, or is this automatic?

@wbpcode
Copy link
Member Author

wbpcode commented Mar 9, 2023

@wbpcode I don't recall - does this require that a filter explicitly implements "most specific filter config" in code, or is this automatic?

This is automatic and it affects the filter chain directly, acting outside the filter.

@wbpcode
Copy link
Member Author

wbpcode commented Mar 9, 2023

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Check envoy-presubmit didn't fail.

🐱

Caused by: a #25927 (comment) was created by @wbpcode.

see: more, trace.

Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: wbpcode <wangbaiping@corp.netease.com>
@wbpcode
Copy link
Member Author

wbpcode commented Mar 9, 2023

Seems there is no explict objection to the API and functions. I think we can merge it and then I can prepare a prototype of the implementation in the next days. 😄

@markdroth
Copy link
Contributor

/lgtm api

@wbpcode
Copy link
Member Author

wbpcode commented Mar 13, 2023

A stamp from maintainer is still necessary. Friendly ping @htuch 😺

// initial route will not be added back to the filter chain because the filter chain is already
// created and it is too late to change the chain.
//
// This field only make sense for the downstream HTTP filters for now.
Copy link
Member

@htuch htuch Mar 14, 2023

Choose a reason for hiding this comment

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

Should add a not-implemented-yet annotation or merge this into the implementation PR. Otherwise LGTM, thanks.

Copy link
Member Author

Choose a reason for hiding this comment

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

The FilterConfig message are annotated as not-implemented. So, it's unnecessary to add the annotation seperatedly for this field.

@kyessenov kyessenov removed their assignment Mar 14, 2023
Copy link
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

/lgtm api

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