-
Notifications
You must be signed in to change notification settings - Fork 833
feat: Added support for logging of HTTP Headers #4803
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
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
7c93a11
feat: Added support for logging of HTTP Headers
zspeaks 0926efb
Fixed test failing due to namespace overlap
zspeaks 8ada6b0
Updates to reflect PR feedback
zspeaks dfa9443
Merge remote-tracking branch 'origin/HTTPHeaderLogging' into HTTPHead…
zspeaks 2943504
Rough draft propogation to ingester + logging in ingester
zspeaks d9b1907
Merge branch 'cortexproject:master' into HTTPHeaderLogging
zspeaks 81a1d95
Merge branch 'cortexproject:master' into HTTPHeaderLogging
zspeaks d404f94
Added Header Propogation to Ingester and Querier
zspeaks 6429d04
Addressed whitespace and linting issues
zspeaks a61937c
Additional linting fixes
zspeaks dc22472
Fixed failing DCO check
zspeaks 0b9fa31
Removed outdated line from prior test design
zspeaks ddd90b9
Updates to reflect PR feedback
zspeaks f183fda
Additional Updates to reflect feedback
zspeaks a10aefc
Improved string comparison when decoding
zspeaks f617e45
Added header decoding to frontend_processor.go for when scheduler ser…
zspeaks 65effc7
Merge branch 'cortexproject:master' into HTTPHeaderLogging
zspeaks 8e5c3ba
Added encoding/decoding interceptors for streams and updated changelog
zspeaks 0e37794
Undo accidental updates to single-process-config-block.yaml file
zspeaks 5800d4c
Whitespace updates
zspeaks 162ca7f
Refactored encode/decode headers to inject/extract to better align wi…
zspeaks d238040
Fixed failing linter
zspeaks 58bc638
Switched extraction to being done by a middleware on the querier API
zspeaks af7c250
Linting
zspeaks 2507235
Changes to reflect PR feedback
zspeaks 1ebee10
Updates to tests to match go conventions
zspeaks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
util_log "github.com/cortexproject/cortex/pkg/util/log" | ||
) | ||
|
||
var HTTPTestMiddleware = HTTPHeaderMiddleware{TargetHeaders: []string{"TestHeader1", "TestHeader2", "Test3"}} | ||
|
||
func TestHeaderInjection(t *testing.T) { | ||
ctx := context.Background() | ||
h := http.Header{} | ||
contentsMap := make(map[string]string) | ||
contentsMap["TestHeader1"] = "RequestID" | ||
contentsMap["TestHeader2"] = "ContentsOfTestHeader2" | ||
contentsMap["Test3"] = "SomeInformation" | ||
|
||
h.Add("TestHeader1", contentsMap["TestHeader1"]) | ||
h.Add("TestHeader2", contentsMap["TestHeader2"]) | ||
h.Add("Test3", contentsMap["Test3"]) | ||
|
||
req := &http.Request{ | ||
Method: "GET", | ||
RequestURI: "/HTTPHeaderTest", | ||
Body: http.NoBody, | ||
Header: h, | ||
} | ||
|
||
req = req.WithContext(ctx) | ||
ctx = HTTPTestMiddleware.InjectTargetHeadersIntoHTTPRequest(req) | ||
|
||
headerMap := util_log.HeaderMapFromContext(ctx) | ||
require.NotNil(t, headerMap) | ||
|
||
for _, header := range HTTPTestMiddleware.TargetHeaders { | ||
require.Equal(t, contentsMap[header], headerMap[header]) | ||
} | ||
for header, contents := range contentsMap { | ||
require.Equal(t, contents, headerMap[header]) | ||
} | ||
} | ||
|
||
func TestExistingHeaderInContextIsNotOverridden(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
h := http.Header{} | ||
contentsMap := make(map[string]string) | ||
contentsMap["TestHeader1"] = "RequestID" | ||
contentsMap["TestHeader2"] = "ContentsOfTestHeader2" | ||
contentsMap["Test3"] = "SomeInformation" | ||
|
||
h.Add("TestHeader1", "Fail1") | ||
h.Add("TestHeader2", "Fail2") | ||
h.Add("Test3", "Fail3") | ||
|
||
ctx = util_log.ContextWithHeaderMap(ctx, contentsMap) | ||
req := &http.Request{ | ||
Method: "GET", | ||
RequestURI: "/HTTPHeaderTest", | ||
Body: http.NoBody, | ||
Header: h, | ||
} | ||
|
||
req = req.WithContext(ctx) | ||
ctx = HTTPTestMiddleware.InjectTargetHeadersIntoHTTPRequest(req) | ||
|
||
require.Equal(t, contentsMap, util_log.HeaderMapFromContext(ctx)) | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.