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

New format for custom HTTP headers #147

Merged
merged 2 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pkg/remotewrite/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,19 @@ func parseEnvs(env map[string]string) (Config, error) {
c.Headers[k] = v
}

if headers, headersDefined := env["K6_PROMETHEUS_RW_HTTP_HEADERS"]; headersDefined {
if c.Headers == nil {
c.Headers = make(map[string]string)
olegbespalov marked this conversation as resolved.
Show resolved Hide resolved
}
for _, kvPair := range strings.Split(headers, ",") {
header := strings.Split(kvPair, ":")
if len(header) != 2 {
continue
olegbespalov marked this conversation as resolved.
Show resolved Hide resolved
}
c.Headers[header[0]] = header[1]
}
}

if b, err := getEnvBool(env, "K6_PROMETHEUS_RW_TREND_AS_NATIVE_HISTOGRAM"); err != nil {
return c, err
} else if b.Valid {
Expand Down
17 changes: 13 additions & 4 deletions pkg/remotewrite/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,15 @@ func TestOptionHeaders(t *testing.T) {
env map[string]string
jsonRaw json.RawMessage
}{
"JSON": {jsonRaw: json.RawMessage(`{"headers":{"X-MY-HEADER1":"hval1","X-MY-HEADER2":"hval2"}}`)},
"Env": {env: map[string]string{"K6_PROMETHEUS_RW_HEADERS_X-MY-HEADER1": "hval1", "K6_PROMETHEUS_RW_HEADERS_X-MY-HEADER2": "hval2"}},
"JSON": {jsonRaw: json.RawMessage(
`{"headers":{"X-MY-HEADER1":"hval1","X-MY-HEADER2":"hval2","X-Scope-OrgID":"my-org-id","another-header":"true"}}`)},
"Env": {env: map[string]string{
"K6_PROMETHEUS_RW_HEADERS_X-MY-HEADER1": "hval1",
"K6_PROMETHEUS_RW_HEADERS_X-MY-HEADER2": "hval2",
// it assert that the new method using HTTP_HEADERS overwrites it
"K6_PROMETHEUS_RW_HEADERS_X-Scope-OrgID": "my-org-id-old-method",
"K6_PROMETHEUS_RW_HTTP_HEADERS": "X-Scope-OrgID:my-org-id,another-header:true",
}},
//nolint:gocritic
//"Arg": {arg: "headers.X-MY-HEADER1=hval1,headers.X-MY-HEADER2=hval2"},
}
Expand All @@ -266,8 +273,10 @@ func TestOptionHeaders(t *testing.T) {
InsecureSkipTLSVerify: null.BoolFrom(false),
PushInterval: types.NullDurationFrom(5 * time.Second),
Headers: map[string]string{
"X-MY-HEADER1": "hval1",
"X-MY-HEADER2": "hval2",
"X-MY-HEADER1": "hval1",
"X-MY-HEADER2": "hval2",
"X-Scope-OrgID": "my-org-id",
"another-header": "true",
},
TrendStats: []string{"p(99)"},
StaleMarkers: null.BoolFrom(false),
Expand Down