-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Change metadata lookup to be case insensitive #5646
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
f0962c5
to
23eda18
Compare
There was a problem hiding this 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
@TylerHelmuth The RFC is very prescriptive about this: https://www.rfc-editor.org/rfc/rfc9110.html#section-5.1 Therefore, I'd rather avoid any support for case-sentitive usage |
There was a problem hiding this 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? |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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]>
23eda18
to
cdefedb
Compare
@codeboten, I believe this is ready to be merged |
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]