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

Change metadata lookup to be case insensitive #5646

Merged
merged 2 commits into from
Jul 13, 2022

Conversation

jpkrohling
Copy link
Member

Before this change, users would make references to headers such as "authorization" and "X-CloudFront-Viewer-Latitude", which would potentially fail, as they would be stored in the context as "X-Cloudfront-Viewer-Latitude" or "Authorization".

This PR changes this behavior, to attempt a case insensitive lookup to the backing map in case the key wasn't found under the requested casing. Under the assumption that the lookup key specified by users won't change, on a subsequent lookup, we proactively copy the value to the looked up key, to make the next lookup faster.

Fixes #5610
Fixes open-telemetry/opentelemetry-collector-contrib#8994

Signed-off-by: Juraci Paixão Kröhling [email protected]

@jpkrohling jpkrohling requested review from a team and mx-psi July 7, 2022 14:37
@codecov
Copy link

codecov bot commented Jul 7, 2022

Codecov Report

Merging #5646 (cdefedb) into main (feab949) will decrease coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #5646      +/-   ##
==========================================
- Coverage   91.33%   91.30%   -0.03%     
==========================================
  Files         191      191              
  Lines       11384    11392       +8     
==========================================
+ Hits        10398    10402       +4     
- Misses        786      789       +3     
- Partials      200      201       +1     
Impacted Files Coverage Δ
client/client.go 100.00% <100.00%> (ø)
pdata/internal/common.go 91.85% <0.00%> (-0.75%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update feab949...cdefedb. Read the comment docs.

@jpkrohling jpkrohling force-pushed the jpkrohling/issue5610 branch from f0962c5 to 23eda18 Compare July 7, 2022 14:45
Copy link
Member

@TylerHelmuth TylerHelmuth left a comment

Choose a reason for hiding this comment

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

Should case sensitivity/insensitivity be optional? Can you think of any real-life situations where someone might currently be relying on the current case sensitivity of this lookup? (I cant).

Assuming there isn't any reason to make this optional, LGTM

@alessandro-tucci-visiontech

@TylerHelmuth The RFC is very prescriptive about this: https://www.rfc-editor.org/rfc/rfc9110.html#section-5.1
Field names are case-insensitive

Therefore, I'd rather avoid any support for case-sentitive usage

Copy link
Member

@TylerHelmuth TylerHelmuth left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -160,7 +161,19 @@ func NewMetadata(md map[string][]string) Metadata {
func (m Metadata) Get(key string) []string {
vals := m.data[key]
if len(vals) == 0 {
return nil
// we didn't find the key, but perhaps it just has different cases?
Copy link
Member

@mx-psi mx-psi Jul 8, 2022

Choose a reason for hiding this comment

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

Have you explored the possibility of making keys lowercase on NewMetadata? I am not sure how this API is used, so there may be performance implications, but it would make the code much simpler

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but given this is on the hot path, I didn't want to incur extra processing when not absolutely needed. I expect the typical case to still hit the old code path, as users would likely use the same case as the header.

Before this change, users would make references to headers such as "authorization" and "X-CloudFront-Viewer-Latitude", which would potentially fail, as they would be stored in the context as "X-Cloudfront-Viewer-Latitude" or "Authorization".

This PR changes this behavior, to attempt a case insensitive lookup to the backing map in case the key wasn't found under the requested casing. Under the assumption that the lookup key specified by users won't change, on a subsequent lookup, we proactively copy the value to the looked up key, to make the next lookup faster.

Fixes open-telemetry#5610
Fixes open-telemetry/opentelemetry-collector-contrib#8994

Signed-off-by: Juraci Paixão Kröhling <[email protected]>
Signed-off-by: Juraci Paixão Kröhling <[email protected]>
@jpkrohling jpkrohling force-pushed the jpkrohling/issue5610 branch from 23eda18 to cdefedb Compare July 8, 2022 13:22
@jpkrohling
Copy link
Member Author

@codeboten, I believe this is ready to be merged

@mx-psi mx-psi added the ready-to-merge Code review completed; ready to merge by maintainers label Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge Code review completed; ready to merge by maintainers
Projects
None yet
5 participants