Skip to content

thrift: add support for case-sensitive header keys#20893

Merged
mattklein123 merged 35 commits intoenvoyproxy:mainfrom
rgs1:lowercase-thrift-headers
May 24, 2022
Merged

thrift: add support for case-sensitive header keys#20893
mattklein123 merged 35 commits intoenvoyproxy:mainfrom
rgs1:lowercase-thrift-headers

Conversation

@rgs1
Copy link
Member

@rgs1 rgs1 commented Apr 19, 2022

Based off #20596, this preserves the current behavior by default.

Signed-off-by: Raul Gutierrez Segales rgs@pinterest.com
Co-authored-by: fishy

Based off envoyproxy#20596, this preserves the current behavior by default.

Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Co-authored-by: fishy
@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 @lizan
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #20893 was opened by rgs1.

see: more, trace.

@rgs1
Copy link
Member Author

rgs1 commented Apr 19, 2022

cc: @fishcakez @JuniorHsu

@rgs1
Copy link
Member Author

rgs1 commented Apr 19, 2022

cc: @davinci26 @fishy

Raul Gutierrez Segales added 6 commits April 20, 2022 10:57
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
@rgs1
Copy link
Member Author

rgs1 commented Apr 21, 2022

@htuch mind taking a look at API please?

@zuercher this is ready for general review too.

Thanks!

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

@wbpcode
Copy link
Member

wbpcode commented Apr 22, 2022

Altough, by this way we can insert some case insensitive header key to the Http::HeaderMap, here are some other problems.

The headers will be used in the header matching or getting cluster with cluster_header or some other scenes.
And the keys in these config will always be convert to lower case. Because the get API of Http::HeaderMap only accept key of type Http::LowerCaseString. This will result in some weird results.
For example, if we set cluster_header to "Key", and there is related "Key" and "Value" in the headers. If we set header_keys_case_sensitive to true, we can never get the valid header value.

I think the key point is that we shouldn't use the Http::HeaderMap as the header map type of thrift. The Http::HeaderMap is designed for HTTP (lower case key, multiple value for same key), and headers of thrift should be a normal string map (ref https://github.com/apache/thrift/blob/master/lib/cpp/src/thrift/transport/THeaderTransport.h).

(Dubbo has the similar problem.)

@wbpcode
Copy link
Member

wbpcode commented Apr 22, 2022

/assign

@wbpcode
Copy link
Member

wbpcode commented Apr 25, 2022

/wait-any

@rgs1
Copy link
Member Author

rgs1 commented Apr 25, 2022

Altough, by this way we can insert some case insensitive header key to the Http::HeaderMap, here are some other problems.

The headers will be used in the header matching or getting cluster with cluster_header or some other scenes. And the keys in these config will always be convert to lower case. Because the get API of Http::HeaderMap only accept key of type Http::LowerCaseString. This will result in some weird results. For example, if we set cluster_header to "Key", and there is related "Key" and "Value" in the headers. If we set header_keys_case_sensitive to true, we can never get the valid header value.

I think the key point is that we shouldn't use the Http::HeaderMap as the header map type of thrift. The Http::HeaderMap is designed for HTTP (lower case key, multiple value for same key), and headers of thrift should be a normal string map (ref https://github.com/apache/thrift/blob/master/lib/cpp/src/thrift/transport/THeaderTransport.h).

(Dubbo has the similar problem.)

I think we can document all of these limitations and still move forward with this. Speaking of HTTP, we do support case preservation there (see #15619).

cc: @fishy

@wbpcode
Copy link
Member

wbpcode commented Apr 26, 2022

I think we can document all of these limitations and still move forward with this. Speaking of HTTP, we do support case preservation there (see #15619).

Yeah, but the seaching of header key will no be influenced by this preservation (#15619). And the approach in this PR does.

IMO, I think it would be better to replace Http::HeaderMap in the thrift proxy with absl::flat_hash_map<std::strinig, std::string>.
Or we can use the approach in the #15619 to preserve the case-sensitive key.

@rgs1
Copy link
Member Author

rgs1 commented Apr 26, 2022

I think we can document all of these limitations and still move forward with this. Speaking of HTTP, we do support case preservation there (see #15619).

Yeah, but the seaching of header key will no be influenced by this preservation (#15619). And the approach in this PR does.

IMO, I think it would be better to replace Http::HeaderMap in the thrift proxy with absl::flat_hash_map<std::strinig, std::string>. Or we can use the approach in the #15619 to preserve the case-sensitive key.

Replacing Http::HeaderMap might sound tempting, but we rely on it for some things:

https://github.com/envoyproxy/envoy/blob/main/source/extensions/filters/network/thrift_proxy/router/router_impl.cc#L117

So it sounds like the proper way of doing this would be the approach in #15619 (at the cost of using more memory).

@wbpcode
Copy link
Member

wbpcode commented Apr 27, 2022

Yeah, the approach in the #15619 is best way for now.

(FWIW, may be we can try to make the http header match utility a template, then it can be easily reused by other type headers (e.g. absl::flat_hash_map<std::strinig, std::string>. I will have a try. Because the dubbo also need this.)

Raul Gutierrez Segales added 2 commits April 29, 2022 17:16
@rgs1
Copy link
Member Author

rgs1 commented Apr 30, 2022

@wbpcode ok I pushed something similar to #15619 but less complex (e.g.: the formatter is hard coded because, at least right now, we don't need a whole new plugging system for headers formatting in Thrift). Let me know what you think, thanks!

@rgs1
Copy link
Member Author

rgs1 commented May 16, 2022

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Check envoy-presubmit isn't fully completed, but will still attempt retrying.
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #20893 (comment) was created by @rgs1.

see: more, trace.

@rgs1
Copy link
Member Author

rgs1 commented May 16, 2022

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #20893 (comment) was created by @rgs1.

see: more, trace.

wbpcode
wbpcode previously approved these changes May 17, 2022
Copy link
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. Thanks for your great work. cc @zuercher for final pass or merge.

@wbpcode
Copy link
Member

wbpcode commented May 17, 2022

cc @htuch could your give another lgtm for the API? Thanks.

@htuch
Copy link
Member

htuch commented May 17, 2022

/lgtm api

Raul Gutierrez Segales added 4 commits May 19, 2022 17:29
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Raul Gutierrez Segales added 5 commits May 23, 2022 14:23
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Fix
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Fix
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
@rgs1
Copy link
Member Author

rgs1 commented May 24, 2022

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Check envoy-presubmit isn't fully completed, but will still attempt retrying.
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #20893 (comment) was created by @rgs1.

see: more, trace.

@rgs1
Copy link
Member Author

rgs1 commented May 24, 2022

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Check envoy-presubmit isn't fully completed, but will still attempt retrying.
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #20893 (comment) was created by @rgs1.

see: more, trace.

@rgs1
Copy link
Member Author

rgs1 commented May 24, 2022

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #20893 (comment) was created by @rgs1.

see: more, trace.

@rgs1
Copy link
Member Author

rgs1 commented May 24, 2022

@zuercher this is ready for another pass (the macos failure was something else, possibly transient).

Copy link
Member

@zuercher zuercher left a comment

Choose a reason for hiding this comment

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

Looks good!

@mattklein123 mattklein123 merged commit 53867ab into envoyproxy:main May 24, 2022
ravenblackx pushed a commit to ravenblackx/envoy that referenced this pull request Jun 8, 2022
Based off envoyproxy#20596, this preserves the current behavior by default.

Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
Co-authored-by: fishy
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.

9 participants