-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
query-frontend: Extract org id from from request headers (#3245)
* query-frontend: Extract org id from from request headers Signed-off-by: Neil Fordyce <neil.fordyce@skyscanner.net> * docs: regenerate docs Signed-off-by: Neil Fordyce <neil.fordyce@skyscanner.net> * query-frontend: gofmt Signed-off-by: Neil Fordyce <neil.fordyce@skyscanner.net> * query-frontend: inline function header Signed-off-by: Neil Fordyce <neil.fordyce@skyscanner.net> * docs: rebuild query-frontend docs Signed-off-by: Neil Fordyce <neil.fordyce@skyscanner.net> * docs: clarify usage of org-id-header flag Signed-off-by: Neil Fordyce <neil.fordyce@skyscanner.net>
- Loading branch information
1 parent
b0af765
commit 713ff65
Showing
4 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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,46 @@ | ||
// Copyright (c) The Thanos Authors. | ||
// Licensed under the Apache License 2.0. | ||
|
||
package main | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/thanos-io/thanos/pkg/testutil" | ||
) | ||
|
||
func Test_extractOrgId(t *testing.T) { | ||
var testData = []struct { | ||
configuredHeaders []string | ||
requestHeaders map[string]string | ||
expectOrgId string | ||
}{ | ||
{ | ||
configuredHeaders: []string{"x-grafana-user", "x-server-id"}, | ||
requestHeaders: map[string]string{"x-grafana-user": "imagrafanauser", "x-server-id": "iamserverid"}, | ||
expectOrgId: "imagrafanauser", | ||
}, | ||
{ | ||
configuredHeaders: []string{"x-server-id", "x-grafana-user"}, | ||
requestHeaders: map[string]string{"x-grafana-user": "imagrafanauser", "x-server-id": "iamserverid"}, | ||
expectOrgId: "iamserverid", | ||
}, | ||
{ | ||
configuredHeaders: []string{}, | ||
requestHeaders: map[string]string{"another-header": "another"}, | ||
expectOrgId: "anonymous", | ||
}, | ||
} | ||
for _, data := range testData { | ||
config := queryFrontendConfig{ | ||
orgIdHeaders: data.configuredHeaders, | ||
} | ||
req, _ := http.NewRequest("", "", nil) | ||
for k, v := range data.requestHeaders { | ||
req.Header.Set(k, v) | ||
} | ||
id := extractOrgId(&config, req) | ||
testutil.Equals(t, data.expectOrgId, id) | ||
} | ||
} |
This file contains 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