Skip to content

Convert match_delegate and composite filter as dual filter (2nd approach)#33013

Merged
yanavlasov merged 19 commits intoenvoyproxy:mainfrom
yanjunxiang-google:match_delegate_specialcase
Apr 10, 2024
Merged

Convert match_delegate and composite filter as dual filter (2nd approach)#33013
yanavlasov merged 19 commits intoenvoyproxy:mainfrom
yanjunxiang-google:match_delegate_specialcase

Conversation

@yanjunxiang-google
Copy link
Copy Markdown
Contributor

@yanjunxiang-google yanjunxiang-google commented Mar 20, 2024

Convert match_delegate and composite filter as dual filter.

As match_delegate filter has downstream filter factory logic, treat it as special case. i.e, Having it inherit from
NamedHttpFilterConfigFactory, and UpstreamHttpFilterConfigFactory, kind like DualFactoryBase.

This PR is an alternative approach of #32777.

Commit Message:
Additional Description:
Risk Level:
Testing:
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]

…ach)

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

/assign @wbpcode @tyxia @juanmolle

@repokitteh-read-only
Copy link
Copy Markdown

@juanmolle cannot be assigned to this issue.

🐱

Caused by: a #33013 (comment) was created by @yanjunxiang-google.

see: more, trace.

@yanjunxiang-google yanjunxiang-google changed the title Convert match_delegate and composite filter as dual filter (2nd appro… Convert match_delegate and composite filter as dual filter (2nd approch) Mar 20, 2024
@yanjunxiang-google yanjunxiang-google changed the title Convert match_delegate and composite filter as dual filter (2nd approch) Convert match_delegate and composite filter as dual filter (2nd approach) Mar 20, 2024
Copy link
Copy Markdown
Contributor

@yanavlasov yanavlasov left a comment

Choose a reason for hiding this comment

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

/wait

Comment thread source/common/http/match_delegate/config.h
Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
@tyxia
Copy link
Copy Markdown
Member

tyxia commented Mar 21, 2024

/assign @tyxia

Copy link
Copy Markdown
Member

@tyxia tyxia 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 this!

This PR has made some good progress, but i think it is missing some changes for delegating to upstream filter. Please see my comments for more details.

Comment thread source/common/http/match_delegate/config.cc Outdated
Comment thread source/extensions/filters/http/composite/config.cc
Comment thread test/extensions/filters/http/composite/composite_filter_integration_test.cc Outdated
@tyxia
Copy link
Copy Markdown
Member

tyxia commented Mar 24, 2024

/wait

(label was removed by my comment...)

@juanmolle
Copy link
Copy Markdown
Contributor

juanmolle commented Mar 25, 2024

I have left a comment in the old PR, not an issue I guess but could need to verify

Just one comment, there are some concerns regarding accessing streamInfo at the moment to convert the filter into dual filter. this filter push data into filter_state https://github.com/envoyproxy/envoy/blob/main/source/extensions/filters/http/composite/filter.cc#L143 could that be a problem? if that is the case perhaps this logic could be skiped if it is an upstream config.

According to this document https://github.com/envoyproxy/envoy/blob/main/source/docs/upstream_filters.md upstream filters should access streamInfo in preference as const. It does not say it is a must and that was my question about.

ref
Either the filter does not access streamInfo in a non-const way, or you test and document how the filter interacts with hedging and retries. Note that for hedging, a single downstream StreamInfo is accessible in parallel to both instances of the upstream HTTP filter instance, so it must be resiliant to parallel access.

On the other hand as upstream filter that piece of code probably has no sens and could be skipped now and evaluate it later. (probably just keep the matched action is ok on retries to deduplicate it)
https://github.com/envoyproxy/envoy/blob/main/source/extensions/filters/http/common/factory_base.h#L135

From @yanjunxiang-google investigation:

I think updateFilterState() in composite filter is needed even the filter is in upstream filter chain.
A couple of reasons:

  • We probably want to setup the actions filter state for other filters to access.
  • The filter state has life time as FilterChain, so the filter state will get out-of-life during retries/hedging. So, it won't be an issue in those cases.

…ter test

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
@yanjunxiang-google yanjunxiang-google marked this pull request as draft March 26, 2024 14:47
Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
@repokitteh-read-only repokitteh-read-only Bot removed the api label Apr 3, 2024
Copy link
Copy Markdown
Member

@tyxia tyxia left a comment

Choose a reason for hiding this comment

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

Nice work!

Mostly LGTM, modulo some comments. Thanks!

Comment thread source/common/http/match_delegate/config.cc Outdated
Comment thread source/common/http/match_delegate/config.cc Outdated
Comment thread source/common/http/match_delegate/config.h
Comment thread source/common/http/match_delegate/config.cc
Comment thread test/integration/filters/set_response_code_filter.cc Outdated
Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
wbpcode
wbpcode previously approved these changes Apr 4, 2024
Copy link
Copy Markdown
Member

@wbpcode wbpcode left a comment

Choose a reason for hiding this comment

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

LGTM overall with nit comment. Thanks.

Comment thread envoy/server/filter_config.h
Comment thread source/extensions/filters/http/composite/config.cc
@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented Apr 4, 2024

/wait-any

@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

yanjunxiang-google commented Apr 4, 2024

The filter state has life time as FilterChain, so the filter state will get out-of-life during retries/hedging. So, it won't be an issue in those cases.

Are you sure to this point? Seem the composite filter set the state to the downstream stream info and which have almost same lifetime with the whole request (except the internal redirect).

I think the original concern is that if the filter is upstream filter chain, and in case of hedging or retries, how the filter state should behave? In that case, I guess the logic here can handle it:

. i.e, it always update the filter state to the latestion action_name.

You raised a good point that the composite filter might be configured in both downstream and upstream filter chain. Is your concern that as there is just one key:

constexpr absl::string_view MatchedActionsFilterStateKey =
, that will cause conflicts?

Anyway, I raised an issue #33343 to track this.

If the consensus is to skip writing the filter state if the composite filter is in upstream, I will create a separate PR to address it.

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
@yanjunxiang-google yanjunxiang-google marked this pull request as ready for review April 5, 2024 02:32
Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

Kind ping!

@yanavlasov
Copy link
Copy Markdown
Contributor

Would it work if you split this review in two, one for each filter, to make it easier to review?

/wait-any

@yanjunxiang-google
Copy link
Copy Markdown
Contributor Author

yanjunxiang-google commented Apr 8, 2024

Would it work if you split this review in two, one for each filter, to make it easier to review?

/wait-any

Thanks for the comments!
I thought about that. The problem is that match_delegate and composite filter have to work together to achieve dynamic filter chain selection feature. We need to convert them together to be able to write tests to verify they indeed work in the upstream filter chain.

@yanavlasov yanavlasov merged commit dffc5f1 into envoyproxy:main Apr 10, 2024
alyssawilk pushed a commit to alyssawilk/envoy that referenced this pull request Apr 29, 2024
…ach) (envoyproxy#33013)


---------

Signed-off-by: Yanjun Xiang <yanjunxiang@google.com>
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.

6 participants