Skip to content

Commit 2652007

Browse files
authored
Chore: Update grafana-plugin-sdk (grafana#84289)
1 parent e6150a7 commit 2652007

File tree

16 files changed

+67
-44
lines changed

16 files changed

+67
-44
lines changed

go.mod

+4-5
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ require (
6363
github.com/grafana/cuetsy v0.1.11 // @grafana/grafana-as-code
6464
github.com/grafana/grafana-aws-sdk v0.24.0 // @grafana/aws-datasources
6565
github.com/grafana/grafana-azure-sdk-go v1.12.0 // @grafana/partner-datasources
66-
github.com/grafana/grafana-plugin-sdk-go v0.214.0 // @grafana/plugins-platform-backend
66+
github.com/grafana/grafana-plugin-sdk-go v0.215.0 // @grafana/plugins-platform-backend
6767
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // @grafana/backend-platform
6868
github.com/hashicorp/go-hclog v1.6.2 // @grafana/plugins-platform-backend
6969
github.com/hashicorp/go-plugin v1.6.0 // @grafana/plugins-platform-backend
@@ -122,7 +122,7 @@ require (
122122
gopkg.in/mail.v2 v2.3.1 // @grafana/backend-platform
123123
gopkg.in/yaml.v2 v2.4.0 // indirect
124124
gopkg.in/yaml.v3 v3.0.1 // @grafana/alerting-squad-backend
125-
xorm.io/builder v0.3.6 // indirect; @grafana/backend-platform
125+
xorm.io/builder v0.3.6 // @grafana/backend-platform
126126
xorm.io/core v0.7.3 // @grafana/backend-platform
127127
xorm.io/xorm v0.8.2 // @grafana/alerting-squad-backend
128128
)
@@ -174,7 +174,7 @@ require (
174174
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.1-0.20191002090509-6af20e3a5340 // indirect
175175
github.com/hashicorp/errwrap v1.1.0 // indirect
176176
github.com/hashicorp/go-msgpack v0.5.5 // indirect
177-
github.com/hashicorp/go-multierror v1.1.1 // indirect; @grafana/alerting-squad
177+
github.com/hashicorp/go-multierror v1.1.1 // @grafana/alerting-squad
178178
github.com/hashicorp/go-sockaddr v1.0.6 // indirect
179179
github.com/hashicorp/golang-lru v0.6.0 // indirect
180180
github.com/hashicorp/yamux v0.1.1 // indirect
@@ -337,7 +337,7 @@ require (
337337
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
338338
github.com/grafana/regexp v0.0.0-20221123153739-15dc172cd2db // indirect
339339
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
340-
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect; @grafana/alerting-squad-backend
340+
github.com/hashicorp/golang-lru/v2 v2.0.7 // @grafana/alerting-squad-backend
341341
github.com/hashicorp/memberlist v0.5.0 // indirect
342342
github.com/inconshreveable/mousetrap v1.1.0 // indirect
343343
github.com/invopop/yaml v0.2.0 // indirect
@@ -518,4 +518,3 @@ exclude github.com/mattn/go-sqlite3 v2.0.3+incompatible
518518

519519
// Use our fork xorm. go.work currently overrides this and points to the local ./pkg/util/xorm directory.
520520
replace xorm.io/xorm => github.com/grafana/grafana/pkg/util/xorm v0.0.1
521-

go.sum

+7-2
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,7 @@ github.com/axiomhq/hyperloglog v0.0.0-20191112132149-a4c4c47bc57f h1:y06x6vGnFYf
14491449
github.com/axiomhq/hyperloglog v0.0.0-20191112132149-a4c4c47bc57f/go.mod h1:2stgcRjl6QmW+gU2h5E7BQXg4HU0gzxKWDuT5HviN9s=
14501450
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
14511451
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
1452+
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
14521453
github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
14531454
github.com/beevik/etree v1.2.0 h1:l7WETslUG/T+xOPs47dtd6jov2Ii/8/OjCldk5fYfQw=
14541455
github.com/beevik/etree v1.2.0/go.mod h1:aiPf89g/1k3AShMVAzriilpcE4R/Vuor90y83zVZWFc=
@@ -1501,6 +1502,7 @@ github.com/bufbuild/connect-go v1.10.0/go.mod h1:CAIePUgkDR5pAFaylSMtNK45ANQjp9J
15011502
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
15021503
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
15031504
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
1505+
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
15041506
github.com/buildkite/yaml v2.1.0+incompatible h1:xirI+ql5GzfikVNDmt+yeiXpf/v1Gt03qXTtT5WXdr8=
15051507
github.com/buildkite/yaml v2.1.0+incompatible/go.mod h1:UoU8vbcwu1+vjZq01+KrpSeLBgQQIjL/H7Y6KwikUrI=
15061508
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
@@ -2193,13 +2195,14 @@ github.com/grafana/grafana-google-sdk-go v0.1.0/go.mod h1:Vo2TKWfDVmNTELBUM+3lkr
21932195
github.com/grafana/grafana-openapi-client-go v0.0.0-20231213163343-bd475d63fb79 h1:r+mU5bGMzcXCRVAuOrTn54S80qbfVkvTdUJZfSfTNbs=
21942196
github.com/grafana/grafana-openapi-client-go v0.0.0-20231213163343-bd475d63fb79/go.mod h1:wc6Hbh3K2TgCUSfBC/BOzabItujtHMESZeFk5ZhdxhQ=
21952197
github.com/grafana/grafana-plugin-sdk-go v0.114.0/go.mod h1:D7x3ah+1d4phNXpbnOaxa/osSaZlwh9/ZUnGGzegRbk=
2196-
github.com/grafana/grafana-plugin-sdk-go v0.214.0 h1:09AoomxfsMdKmS4bc5tF81f7fvI9HjHckGFAmu/UQls=
2197-
github.com/grafana/grafana-plugin-sdk-go v0.214.0/go.mod h1:nBsh3jRItKQUXDF2BQkiQCPxqrsSQeb+7hiFyJTO1RE=
2198+
github.com/grafana/grafana-plugin-sdk-go v0.215.0 h1:02gwVsqYi1I+U48/MQR61eOMxiXE7KNKC8QsiMJ//qA=
2199+
github.com/grafana/grafana-plugin-sdk-go v0.215.0/go.mod h1:nBsh3jRItKQUXDF2BQkiQCPxqrsSQeb+7hiFyJTO1RE=
21982200
github.com/grafana/grafana/pkg/apimachinery v0.0.0-20240226124929-648abdbd0ea4 h1:hpyusz8c3yRFoJPlA0o34rWnsLbaOOBZleqRhFBi5Lg=
21992201
github.com/grafana/grafana/pkg/apimachinery v0.0.0-20240226124929-648abdbd0ea4/go.mod h1:vrRQJuNprTWqwm6JPxHf3BoTJhvO15QMEjQ7Q/YUOnI=
22002202
github.com/grafana/grafana/pkg/apiserver v0.0.0-20240226124929-648abdbd0ea4 h1:tIbI5zgos92vwJ8lV3zwHwuxkV03GR3FGLkFW9V5LxY=
22012203
github.com/grafana/grafana/pkg/apiserver v0.0.0-20240226124929-648abdbd0ea4/go.mod h1:vpYI6DHvFO595rpQGooUjcyicjt9rOevldDdW79peV0=
22022204
github.com/grafana/grafana/pkg/promlib v0.0.1 h1:R+z+xC4vhG3jgMjIJ2cbUjMQdc1HSJHFQWdIWUPCG4Q=
2205+
github.com/grafana/grafana/pkg/promlib v0.0.1/go.mod h1:zkmF4NeKJs/y65xc3/XXc53LY0J8E7YUsZnn+FSrcq4=
22032206
github.com/grafana/grafana/pkg/util/xorm v0.0.1 h1:72QZjxWIWpSeOF8ob4aMV058kfgZyeetkAB8dmeti2o=
22042207
github.com/grafana/grafana/pkg/util/xorm v0.0.1/go.mod h1:eNfbB9f2jM8o9RfwqwjY8SYm5tvowJ8Ly+iE4P9rXII=
22052208
github.com/grafana/kindsys v0.0.0-20230508162304-452481b63482 h1:1YNoeIhii4UIIQpCPU+EXidnqf449d0C3ZntAEt4KSo=
@@ -2355,6 +2358,7 @@ github.com/influxdata/influxdb1-client v0.0.0-20200827194710-b269163b24ab/go.mod
23552358
github.com/influxdata/line-protocol v0.0.0-20210311194329-9aa0e372d097 h1:vilfsDSy7TDxedi9gyBkMvAirat/oRcL0lFdJBf6tdM=
23562359
github.com/influxdata/line-protocol v0.0.0-20210311194329-9aa0e372d097/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo=
23572360
github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI=
2361+
github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
23582362
github.com/invopop/yaml v0.2.0 h1:7zky/qH+O0DwAyoobXUqvVBwgBFRxKoQ/3FjcVpjTMY=
23592363
github.com/invopop/yaml v0.2.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q=
23602364
github.com/ionos-cloud/sdk-go/v6 v6.1.10 h1:3815Q2Hw/wc4cJ8wD7bwfsmDsdfIEp80B7BQMj0YP2w=
@@ -3090,6 +3094,7 @@ github.com/vultr/govultr/v2 v2.17.2/go.mod h1:ZFOKGWmgjytfyjeyAdhQlSWwTjh2ig+X49
30903094
github.com/wk8/go-ordered-map v1.0.0 h1:BV7z+2PaK8LTSd/mWgY12HyMAo5CEgkHqbkVq2thqr8=
30913095
github.com/wk8/go-ordered-map v1.0.0/go.mod h1:9ZIbRunKbuvfPKyBP1SIKLcXNlv74YCOZ3t3VTS6gRk=
30923096
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
3097+
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
30933098
github.com/xanzy/go-gitlab v0.15.0/go.mod h1:8zdQa/ri1dfn8eS3Ir1SyfvOKlw7WBJ8DVThkpGiXrs=
30943099
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
30953100
github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs=

pkg/apiserver/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.21.0
55
require (
66
github.com/bwmarrin/snowflake v0.3.0
77
github.com/gorilla/mux v1.8.0
8-
github.com/grafana/grafana-plugin-sdk-go v0.214.0
8+
github.com/grafana/grafana-plugin-sdk-go v0.215.0
99
github.com/stretchr/testify v1.8.4
1010
golang.org/x/mod v0.14.0
1111
k8s.io/apimachinery v0.29.2

pkg/apiserver/go.sum

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e h1:JKmoR8x90Iww1
7777
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
7878
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
7979
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
80-
github.com/grafana/grafana-plugin-sdk-go v0.214.0 h1:09AoomxfsMdKmS4bc5tF81f7fvI9HjHckGFAmu/UQls=
80+
github.com/grafana/grafana-plugin-sdk-go v0.215.0 h1:02gwVsqYi1I+U48/MQR61eOMxiXE7KNKC8QsiMJ//qA=
8181
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI=
8282
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.1-0.20191002090509-6af20e3a5340 h1:uGoIog/wiQHI9GAxXO5TJbT0wWKH3O9HhOJW1F9c3fY=
8383
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=

pkg/promlib/client/transport_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package client
22

33
import (
44
"context"
5+
"net/http"
56
"testing"
67

78
"github.com/grafana/grafana-plugin-sdk-go/backend"
@@ -20,7 +21,7 @@ func TestCreateTransportOptions(t *testing.T) {
2021
}
2122
opts, err := CreateTransportOptions(context.Background(), settings, backend.NewLoggerWith("logger", "test"))
2223
require.NoError(t, err)
23-
require.Equal(t, map[string]string{"foo": "bar"}, opts.Headers)
24+
require.Equal(t, http.Header{"Foo": []string{"bar"}}, opts.Header)
2425
require.Equal(t, 2, len(opts.Middlewares))
2526
})
2627
}

pkg/promlib/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/grafana/grafana/pkg/promlib
33
go 1.21.0
44

55
require (
6-
github.com/grafana/grafana-plugin-sdk-go v0.214.0
6+
github.com/grafana/grafana-plugin-sdk-go v0.215.0
77
github.com/json-iterator/go v1.1.12
88
github.com/patrickmn/go-cache v2.1.0+incompatible
99
github.com/prometheus/client_golang v1.18.0

pkg/promlib/go.sum

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
3333
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
3434
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e h1:JKmoR8x90Iww1ks85zJ1lfDGgIiMDuIptTOhJq+zKyg=
3535
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
36-
github.com/grafana/grafana-plugin-sdk-go v0.214.0 h1:09AoomxfsMdKmS4bc5tF81f7fvI9HjHckGFAmu/UQls=
36+
github.com/grafana/grafana-plugin-sdk-go v0.215.0 h1:02gwVsqYi1I+U48/MQR61eOMxiXE7KNKC8QsiMJ//qA=
3737
github.com/grafana/regexp v0.0.0-20221123153739-15dc172cd2db h1:7aN5cccjIqCLTzedH7MZzRZt5/lsAHch6Z3L2ZGn5FA=
3838
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI=
3939
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.1-0.20191002090509-6af20e3a5340 h1:uGoIog/wiQHI9GAxXO5TJbT0wWKH3O9HhOJW1F9c3fY=

pkg/services/datasources/datasources.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type DataSourceService interface {
5858
// CustomHeaders returns a map of custom headers the user might have
5959
// configured for this Datasource. Not every datasource can has the option
6060
// to configure those.
61-
CustomHeaders(ctx context.Context, ds *DataSource) (map[string]string, error)
61+
CustomHeaders(ctx context.Context, ds *DataSource) (http.Header, error)
6262
}
6363

6464
// CacheService interface for retrieving a cached datasource.

pkg/services/datasources/fakes/fake_datasource_service.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,6 @@ func (s *FakeDataSourceService) DecryptedPassword(ctx context.Context, ds *datas
134134
return "", nil
135135
}
136136

137-
func (s *FakeDataSourceService) CustomHeaders(ctx context.Context, ds *datasources.DataSource) (map[string]string, error) {
137+
func (s *FakeDataSourceService) CustomHeaders(ctx context.Context, ds *datasources.DataSource) (http.Header, error) {
138138
return nil, nil
139139
}

pkg/services/datasources/service/datasource.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ func (s *Service) httpClientOptions(ctx context.Context, ds *datasources.DataSou
484484

485485
opts := &sdkhttpclient.Options{
486486
Timeouts: timeouts,
487-
Headers: s.getCustomHeaders(ds.JsonData, decryptedValues),
487+
Header: s.getCustomHeaders(ds.JsonData, decryptedValues),
488488
Labels: map[string]string{
489489
"datasource_type": ds.Type,
490490
"datasource_name": ds.Name,
@@ -654,8 +654,8 @@ func (s *Service) getTimeout(ds *datasources.DataSource) time.Duration {
654654

655655
// getCustomHeaders returns a map with all the to be set headers
656656
// The map key represents the HeaderName and the value represents this header's value
657-
func (s *Service) getCustomHeaders(jsonData *simplejson.Json, decryptedValues map[string]string) map[string]string {
658-
headers := make(map[string]string)
657+
func (s *Service) getCustomHeaders(jsonData *simplejson.Json, decryptedValues map[string]string) http.Header {
658+
headers := make(http.Header)
659659
if jsonData == nil {
660660
return headers
661661
}
@@ -680,7 +680,7 @@ func (s *Service) getCustomHeaders(jsonData *simplejson.Json, decryptedValues ma
680680
}
681681

682682
if val, ok := decryptedValues[headerValueSuffix]; ok {
683-
headers[key] = val
683+
headers.Add(key, val)
684684
}
685685
}
686686

@@ -769,7 +769,7 @@ func readQuotaConfig(cfg *setting.Cfg) (*quota.Map, error) {
769769
}
770770

771771
// CustomerHeaders returns the custom headers specified in the datasource. The context is used for the decryption operation that might use the store, so consider setting an acceptable timeout for your use case.
772-
func (s *Service) CustomHeaders(ctx context.Context, ds *datasources.DataSource) (map[string]string, error) {
772+
func (s *Service) CustomHeaders(ctx context.Context, ds *datasources.DataSource) (http.Header, error) {
773773
values, err := s.SecretsService.DecryptJsonData(ctx, ds.SecureJsonData)
774774
if err != nil {
775775
return nil, fmt.Errorf("failed to get custom headers: %w", err)

pkg/services/datasources/service/datasource_test.go

+21-7
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ func TestService_GetHttpTransport(t *testing.T) {
833833
require.NoError(t, err)
834834

835835
headers := dsService.getCustomHeaders(sjson, map[string]string{"httpHeaderValue1": "Bearer xf5yhfkpsnmgo"})
836-
require.Equal(t, "Bearer xf5yhfkpsnmgo", headers["Authorization"])
836+
require.Equal(t, "Bearer xf5yhfkpsnmgo", headers.Get("Authorization"))
837837

838838
// 1. Start HTTP test server which checks the request headers
839839
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -902,7 +902,7 @@ func TestService_GetHttpTransport(t *testing.T) {
902902
require.NoError(t, err)
903903

904904
headers := dsService.getCustomHeaders(sjson, map[string]string{"httpHeaderValue1": "example.com"})
905-
require.Equal(t, "example.com", headers["Host"])
905+
require.Equal(t, "example.com", headers.Get("Host"))
906906

907907
// 1. Start HTTP test server which checks the request headers
908908
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -1192,7 +1192,7 @@ func TestDataSource_CustomHeaders(t *testing.T) {
11921192
name string
11931193
jsonData *simplejson.Json
11941194
secureJsonData map[string][]byte
1195-
expectedHeaders map[string]string
1195+
expectedHeaders http.Header
11961196
expectedErrorMsg string
11971197
}{
11981198
{
@@ -1203,8 +1203,8 @@ func TestDataSource_CustomHeaders(t *testing.T) {
12031203
secureJsonData: map[string][]byte{
12041204
"httpHeaderValue1": encryptedValue,
12051205
},
1206-
expectedHeaders: map[string]string{
1207-
"X-Test-Header1": testValue,
1206+
expectedHeaders: http.Header{
1207+
"X-Test-Header1": []string{testValue},
12081208
},
12091209
},
12101210
{
@@ -1213,15 +1213,29 @@ func TestDataSource_CustomHeaders(t *testing.T) {
12131213
"httpHeaderName1": "X-Test-Header1",
12141214
}),
12151215
secureJsonData: map[string][]byte{},
1216-
expectedHeaders: map[string]string{},
1216+
expectedHeaders: http.Header{},
12171217
},
12181218
{
12191219
name: "non customer header value",
12201220
jsonData: simplejson.NewFromAny(map[string]any{
12211221
"someotherheader": "X-Test-Header1",
12221222
}),
12231223
secureJsonData: map[string][]byte{},
1224-
expectedHeaders: map[string]string{},
1224+
expectedHeaders: http.Header{},
1225+
},
1226+
{
1227+
name: "add multiple header value",
1228+
jsonData: simplejson.NewFromAny(map[string]any{
1229+
"httpHeaderName1": "X-Test-Header1",
1230+
"httpHeaderName2": "X-Test-Header1",
1231+
}),
1232+
secureJsonData: map[string][]byte{
1233+
"httpHeaderValue1": encryptedValue,
1234+
"httpHeaderValue2": encryptedValue,
1235+
},
1236+
expectedHeaders: http.Header{
1237+
"X-Test-Header1": []string{testValue, testValue},
1238+
},
12251239
},
12261240
}
12271241

pkg/services/ngalert/sender/notifier_ext.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
// ApplyConfig updates the status state as the new config requires.
2626
// Extension: add new parameter headers.
27-
func (n *Manager) ApplyConfig(conf *config.Config, headers map[string]map[string]string) error {
27+
func (n *Manager) ApplyConfig(conf *config.Config, headers map[string]http.Header) error {
2828
n.mtx.Lock()
2929
defer n.mtx.Unlock()
3030

@@ -57,7 +57,7 @@ type alertmanagerSet struct {
5757
client *http.Client
5858

5959
// Extension: headers that should be used for the http requests to the alertmanagers.
60-
headers map[string]string
60+
headers http.Header
6161

6262
metrics *alertMetrics
6363

@@ -144,7 +144,7 @@ func (n *Manager) sendAll(alerts ...*Alert) bool {
144144
defer cancel()
145145

146146
// Extension: added headers parameter.
147-
go func(client *http.Client, url string, headers map[string]string) {
147+
go func(client *http.Client, url string, headers http.Header) {
148148
if err := n.sendOne(ctx, client, url, payload, headers); err != nil {
149149
level.Error(n.logger).Log("alertmanager", url, "count", len(alerts), "msg", "Error sending alert", "err", err)
150150
n.metrics.errors.WithLabelValues(url).Inc()
@@ -167,7 +167,7 @@ func (n *Manager) sendAll(alerts ...*Alert) bool {
167167
}
168168

169169
// Extension: added headers parameter.
170-
func (n *Manager) sendOne(ctx context.Context, c *http.Client, url string, b []byte, headers map[string]string) error {
170+
func (n *Manager) sendOne(ctx context.Context, c *http.Client, url string, b []byte, headers http.Header) error {
171171
req, err := http.NewRequest("POST", url, bytes.NewReader(b))
172172
if err != nil {
173173
return err
@@ -176,7 +176,9 @@ func (n *Manager) sendOne(ctx context.Context, c *http.Client, url string, b []b
176176
req.Header.Set("Content-Type", contentTypeJSON)
177177
// Extension: set headers.
178178
for k, v := range headers {
179-
req.Header.Set(k, v)
179+
for _, vv := range v {
180+
req.Header.Set(k, vv)
181+
}
180182
}
181183
resp, err := n.opts.Do(ctx, c, req)
182184
if err != nil {

pkg/services/ngalert/sender/sender.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type ExternalAlertmanager struct {
4343

4444
type ExternalAMcfg struct {
4545
URL string
46-
Headers map[string]string
46+
Headers http.Header
4747
}
4848

4949
type Option func(*ExternalAlertmanager)
@@ -177,9 +177,9 @@ func (s *ExternalAlertmanager) DroppedAlertmanagers() []*url.URL {
177177
return s.manager.DroppedAlertmanagers()
178178
}
179179

180-
func buildNotifierConfig(alertmanagers []ExternalAMcfg) (*config.Config, map[string]map[string]string, error) {
180+
func buildNotifierConfig(alertmanagers []ExternalAMcfg) (*config.Config, map[string]http.Header, error) {
181181
amConfigs := make([]*config.AlertmanagerConfig, 0, len(alertmanagers))
182-
headers := map[string]map[string]string{}
182+
headers := map[string]http.Header{}
183183
for i, am := range alertmanagers {
184184
u, err := url.Parse(am.URL)
185185
if err != nil {

pkg/tsdb/azuremonitor/httpclient.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func newHTTPClient(ctx context.Context, route types.AzRoute, model types.Datasou
2828
}
2929

3030
for header, value := range route.Headers {
31-
clientOpts.Headers[header] = value
31+
clientOpts.Header.Add(header, value)
3232
}
3333

3434
// Use Azure credentials if the route has OAuth scopes configured

pkg/tsdb/azuremonitor/httpclient_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,18 @@ func TestHttpClient_AzureCredentials(t *testing.T) {
7272
},
7373
}
7474

75-
res := map[string]string{
76-
"GrafanaHeader": "GrafanaValue",
77-
"AzureHeader": "AzureValue",
75+
res := http.Header{
76+
"Grafanaheader": {"GrafanaValue"},
77+
"Azureheader": {"AzureValue"},
7878
}
7979
_, err := newHTTPClient(context.Background(), route, model, settings, azureSettings, provider)
8080
require.NoError(t, err)
8181

8282
assert.NotNil(t, provider.opts)
8383

84-
if provider.opts.Headers != nil {
85-
assert.Len(t, provider.opts.Headers, 2)
86-
assert.Equal(t, res, provider.opts.Headers)
84+
if provider.opts.Header != nil {
85+
assert.Len(t, provider.opts.Header, 2)
86+
assert.Equal(t, res, provider.opts.Header)
8787
}
8888
})
8989
}

pkg/tsdb/tempo/grpc.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@ func getDialOpts(settings backend.DataSourceInstanceSettings, opts httpclient.Op
8181
// to the CustomHeadersMiddleware in the HTTP client provider.
8282
func CustomHeadersStreamInterceptor(httpOpts httpclient.Options) grpc.StreamClientInterceptor {
8383
return func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error) {
84-
if len(httpOpts.Headers) != 0 {
85-
for key, value := range httpOpts.Headers {
86-
ctx = metadata.AppendToOutgoingContext(ctx, key, value)
84+
if len(httpOpts.Header) != 0 {
85+
for key, value := range httpOpts.Header {
86+
for _, v := range value {
87+
ctx = metadata.AppendToOutgoingContext(ctx, key, v)
88+
}
8789
}
8890
}
8991

0 commit comments

Comments
 (0)