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

Envoy http filters have the *same* order in decode and encode methods #4599

Closed
qiannawang opened this issue Oct 4, 2018 · 18 comments
Closed
Assignees
Labels
Milestone

Comments

@qiannawang
Copy link
Contributor

qiannawang commented Oct 4, 2018

Issue Template

Title: Request and response go through the same http filter order in the chain

Description:
We've found that, in the http filter chain, the request and response (to and from the upstream end point) go through the same filter order.

Filters are added to decode and encode in the same order:

void addStreamFilter(StreamFilterSharedPtr filter) override {

and the encode filter chain goes through in that order:

std::list<ActiveStreamEncoderFilterPtr>::iterator entry = commonEncodePrefix(filter, end_stream);

This seems unexpected, as we thought the decode and encode had the reverse order of the http filters. For example, we config in bootstrap yaml file in the http_filters:
X
Y
Z

The decode order is X, Y, Z, and we thought the encode order was Z, Y, X. but turned out this is not true.

This unexpectation introduces problems to our system, e.g., by measuring the rrt of the request in some filter, header stripping, gzip, etc.

Should we consider to fix the order and make it reverse in encode chain?

@stevenzzzz
Copy link
Contributor

this is surprising and yet true.
I think the straightforward solution is when adding to encode_filters_, use moveIntoList instead of moveIntoListLast().

@mattklein123
Copy link
Member

This is an unfortunate oversight that I'm kicking myself for right now. Oops! 😢

The code fix itself is easy, and I agree should be done. The problem here is whether anyone is depending on this odd behavior. I suspect not since no one has complained about it before, but I think we probably have to make this behavior opt-in with some type of deprecation period in which we would do the switch. Though I guess we can send email and solicit feedback on just changing it.

@qiannawang
Copy link
Contributor Author

I would like to contribute to the fix. Opt-in feature sounds a better solution for me because:

  1. it can avoid to break anyone;
  2. it help a faster release.

What do you think?

@mattklein123
Copy link
Member

Yes I think that's the way to go. I think it should be straightforward. The only tests I can think of that might break are the conn_manager_impl multiple filter tests, but you will need to add some new tests anyway.

@qiannawang qiannawang changed the title Envoy http filters has the *same* order in decode and encode methods Envoy http filters have the *same* order in decode and encode methods Oct 4, 2018
@htuch
Copy link
Member

htuch commented Oct 4, 2018

@mattklein123 would a HCM filter config field to control behavior make sense, with eventual deprecation? I think we want to have folks experience the correct behavior by default as soon as is reasonable.

@mattklein123
Copy link
Member

@mattklein123 would a HCM filter config field to control behavior make sense, with eventual deprecation? I think we want to have folks experience the correct behavior by default as soon as is reasonable.

Yeah that's what I suggested above.

@htuch
Copy link
Member

htuch commented Oct 4, 2018

@mattklein123 just wanted to validate we're talking about filter config vs. CLI.

@htuch htuch removed the help wanted Needs help! label Oct 4, 2018
@mattklein123
Copy link
Member

Oh yes I meant config, not CLI.

@curiouserrandy
Copy link
Contributor

Have we looked at this behavior for network (L4) filters? Glancing at the code without experience, it seems like the same problem (both read and write filters put on the end of the chain, both executed in start-to-end order.)

@mattklein123
Copy link
Member

@curiouserrandy yes we need to fix in both places.

@mattklein123 mattklein123 added this to the 1.9.0 milestone Oct 5, 2018
@qiannawang
Copy link
Contributor Author

is FilterManagerImpl::addWriteFilter the place adding the write filters to the network filter chain?

downstream_filters_.emplace_back(filter);

I believe the change is to replace emplace_back with emplace_front when adding the write filters.

@mattklein123
Copy link
Member

@qiannawang yes that's right.

@qiannawang
Copy link
Contributor Author

Which proto is a good place to add a field to config the order of write filters?

@htuch suggested http_connection_manager.proto for http filters, what about tcp ones?

@htuch
Copy link
Member

htuch commented Oct 15, 2018

@qiannawang you want the HCM proto for L7 filters and the Listener FilterChain for L4.

htuch pushed a commit that referenced this issue Oct 18, 2018
… HTTP encoder filters. (#4721)

Added a field in HCM proto to be able to reverse the order of HTTP encoder filters. The field is set false by default, indicating HTTP encoder filters have the same order as configured in the filter
chain. If true, their order will be reversed.

Risk Level: low
Testing: bazel test //test/...
Part of #4599

Signed-off-by: Qi (Anna) Wang <[email protected]>
soya3129 pushed a commit to soya3129/envoy that referenced this issue Oct 19, 2018
… HTTP encoder filters. (envoyproxy#4721)

Added a field in HCM proto to be able to reverse the order of HTTP encoder filters. The field is set false by default, indicating HTTP encoder filters have the same order as configured in the filter
chain. If true, their order will be reversed.

Risk Level: low
Testing: bazel test //test/...
Part of envoyproxy#4599

Signed-off-by: Qi (Anna) Wang <[email protected]>

Signed-off-by: Yang Song <[email protected]>
@mattklein123
Copy link
Member

@qiannawang are you planning on doing another PR for network filters as well?

@qiannawang
Copy link
Contributor Author

Yes. Do you have any suggestion of the change to network filters?

@mattklein123
Copy link
Member

I would put a similar deprecated boolean field here: https://github.com/envoyproxy/envoy/blob/master/api/envoy/api/v2/listener/listener.proto#L157 to go along with the filters?

htuch pushed a commit that referenced this issue Nov 12, 2018
… TCP write filters (#4889)

Add a field in listener proto to be able to reverse the order of TCP write filters. The field is set false by default, indicating write filters have the same order as configured in the filter chain. If true, their order will be reversed.

Risk Level: Low
Testing: bazel test //test/...
Part of #4599

Signed-off-by: Qi (Anna) Wang <[email protected]>
@qiannawang
Copy link
Contributor Author

Close this issue as the fixes have been enabled (by default). The cleanup will be tracked by a new ticket, as explained in #4889 (comment)

fredlas pushed a commit to fredlas/envoy that referenced this issue Mar 5, 2019
… TCP write filters (envoyproxy#4889)

Add a field in listener proto to be able to reverse the order of TCP write filters. The field is set false by default, indicating write filters have the same order as configured in the filter chain. If true, their order will be reversed.

Risk Level: Low
Testing: bazel test //test/...
Part of envoyproxy#4599

Signed-off-by: Qi (Anna) Wang <[email protected]>
Signed-off-by: Fred Douglas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants