Chore: Update grafana-plugin-sdk (#84289)
This commit is contained in:
@@ -5,7 +5,7 @@ go 1.21.0
|
||||
require (
|
||||
github.com/bwmarrin/snowflake v0.3.0
|
||||
github.com/gorilla/mux v1.8.0
|
||||
github.com/grafana/grafana-plugin-sdk-go v0.214.0
|
||||
github.com/grafana/grafana-plugin-sdk-go v0.215.0
|
||||
github.com/stretchr/testify v1.8.4
|
||||
golang.org/x/mod v0.14.0
|
||||
k8s.io/apimachinery v0.29.2
|
||||
|
||||
@@ -77,7 +77,7 @@ github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e h1:JKmoR8x90Iww1
|
||||
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/grafana/grafana-plugin-sdk-go v0.214.0 h1:09AoomxfsMdKmS4bc5tF81f7fvI9HjHckGFAmu/UQls=
|
||||
github.com/grafana/grafana-plugin-sdk-go v0.215.0 h1:02gwVsqYi1I+U48/MQR61eOMxiXE7KNKC8QsiMJ//qA=
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI=
|
||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.1-0.20191002090509-6af20e3a5340 h1:uGoIog/wiQHI9GAxXO5TJbT0wWKH3O9HhOJW1F9c3fY=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
|
||||
|
||||
@@ -2,6 +2,7 @@ package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
@@ -20,7 +21,7 @@ func TestCreateTransportOptions(t *testing.T) {
|
||||
}
|
||||
opts, err := CreateTransportOptions(context.Background(), settings, backend.NewLoggerWith("logger", "test"))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, map[string]string{"foo": "bar"}, opts.Headers)
|
||||
require.Equal(t, http.Header{"Foo": []string{"bar"}}, opts.Header)
|
||||
require.Equal(t, 2, len(opts.Middlewares))
|
||||
})
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ module github.com/grafana/grafana/pkg/promlib
|
||||
go 1.21.0
|
||||
|
||||
require (
|
||||
github.com/grafana/grafana-plugin-sdk-go v0.214.0
|
||||
github.com/grafana/grafana-plugin-sdk-go v0.215.0
|
||||
github.com/json-iterator/go v1.1.12
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||
github.com/prometheus/client_golang v1.18.0
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e h1:JKmoR8x90Iww1ks85zJ1lfDGgIiMDuIptTOhJq+zKyg=
|
||||
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
||||
github.com/grafana/grafana-plugin-sdk-go v0.214.0 h1:09AoomxfsMdKmS4bc5tF81f7fvI9HjHckGFAmu/UQls=
|
||||
github.com/grafana/grafana-plugin-sdk-go v0.215.0 h1:02gwVsqYi1I+U48/MQR61eOMxiXE7KNKC8QsiMJ//qA=
|
||||
github.com/grafana/regexp v0.0.0-20221123153739-15dc172cd2db h1:7aN5cccjIqCLTzedH7MZzRZt5/lsAHch6Z3L2ZGn5FA=
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI=
|
||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.1-0.20191002090509-6af20e3a5340 h1:uGoIog/wiQHI9GAxXO5TJbT0wWKH3O9HhOJW1F9c3fY=
|
||||
|
||||
@@ -58,7 +58,7 @@ type DataSourceService interface {
|
||||
// CustomHeaders returns a map of custom headers the user might have
|
||||
// configured for this Datasource. Not every datasource can has the option
|
||||
// to configure those.
|
||||
CustomHeaders(ctx context.Context, ds *DataSource) (map[string]string, error)
|
||||
CustomHeaders(ctx context.Context, ds *DataSource) (http.Header, error)
|
||||
}
|
||||
|
||||
// CacheService interface for retrieving a cached datasource.
|
||||
|
||||
@@ -134,6 +134,6 @@ func (s *FakeDataSourceService) DecryptedPassword(ctx context.Context, ds *datas
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (s *FakeDataSourceService) CustomHeaders(ctx context.Context, ds *datasources.DataSource) (map[string]string, error) {
|
||||
func (s *FakeDataSourceService) CustomHeaders(ctx context.Context, ds *datasources.DataSource) (http.Header, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -484,7 +484,7 @@ func (s *Service) httpClientOptions(ctx context.Context, ds *datasources.DataSou
|
||||
|
||||
opts := &sdkhttpclient.Options{
|
||||
Timeouts: timeouts,
|
||||
Headers: s.getCustomHeaders(ds.JsonData, decryptedValues),
|
||||
Header: s.getCustomHeaders(ds.JsonData, decryptedValues),
|
||||
Labels: map[string]string{
|
||||
"datasource_type": ds.Type,
|
||||
"datasource_name": ds.Name,
|
||||
@@ -654,8 +654,8 @@ func (s *Service) getTimeout(ds *datasources.DataSource) time.Duration {
|
||||
|
||||
// getCustomHeaders returns a map with all the to be set headers
|
||||
// The map key represents the HeaderName and the value represents this header's value
|
||||
func (s *Service) getCustomHeaders(jsonData *simplejson.Json, decryptedValues map[string]string) map[string]string {
|
||||
headers := make(map[string]string)
|
||||
func (s *Service) getCustomHeaders(jsonData *simplejson.Json, decryptedValues map[string]string) http.Header {
|
||||
headers := make(http.Header)
|
||||
if jsonData == nil {
|
||||
return headers
|
||||
}
|
||||
@@ -680,7 +680,7 @@ func (s *Service) getCustomHeaders(jsonData *simplejson.Json, decryptedValues ma
|
||||
}
|
||||
|
||||
if val, ok := decryptedValues[headerValueSuffix]; ok {
|
||||
headers[key] = val
|
||||
headers.Add(key, val)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -769,7 +769,7 @@ func readQuotaConfig(cfg *setting.Cfg) (*quota.Map, error) {
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (s *Service) CustomHeaders(ctx context.Context, ds *datasources.DataSource) (map[string]string, error) {
|
||||
func (s *Service) CustomHeaders(ctx context.Context, ds *datasources.DataSource) (http.Header, error) {
|
||||
values, err := s.SecretsService.DecryptJsonData(ctx, ds.SecureJsonData)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get custom headers: %w", err)
|
||||
|
||||
@@ -833,7 +833,7 @@ func TestService_GetHttpTransport(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
headers := dsService.getCustomHeaders(sjson, map[string]string{"httpHeaderValue1": "Bearer xf5yhfkpsnmgo"})
|
||||
require.Equal(t, "Bearer xf5yhfkpsnmgo", headers["Authorization"])
|
||||
require.Equal(t, "Bearer xf5yhfkpsnmgo", headers.Get("Authorization"))
|
||||
|
||||
// 1. Start HTTP test server which checks the request headers
|
||||
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -902,7 +902,7 @@ func TestService_GetHttpTransport(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
headers := dsService.getCustomHeaders(sjson, map[string]string{"httpHeaderValue1": "example.com"})
|
||||
require.Equal(t, "example.com", headers["Host"])
|
||||
require.Equal(t, "example.com", headers.Get("Host"))
|
||||
|
||||
// 1. Start HTTP test server which checks the request headers
|
||||
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -1192,7 +1192,7 @@ func TestDataSource_CustomHeaders(t *testing.T) {
|
||||
name string
|
||||
jsonData *simplejson.Json
|
||||
secureJsonData map[string][]byte
|
||||
expectedHeaders map[string]string
|
||||
expectedHeaders http.Header
|
||||
expectedErrorMsg string
|
||||
}{
|
||||
{
|
||||
@@ -1203,8 +1203,8 @@ func TestDataSource_CustomHeaders(t *testing.T) {
|
||||
secureJsonData: map[string][]byte{
|
||||
"httpHeaderValue1": encryptedValue,
|
||||
},
|
||||
expectedHeaders: map[string]string{
|
||||
"X-Test-Header1": testValue,
|
||||
expectedHeaders: http.Header{
|
||||
"X-Test-Header1": []string{testValue},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -1213,7 +1213,7 @@ func TestDataSource_CustomHeaders(t *testing.T) {
|
||||
"httpHeaderName1": "X-Test-Header1",
|
||||
}),
|
||||
secureJsonData: map[string][]byte{},
|
||||
expectedHeaders: map[string]string{},
|
||||
expectedHeaders: http.Header{},
|
||||
},
|
||||
{
|
||||
name: "non customer header value",
|
||||
@@ -1221,7 +1221,21 @@ func TestDataSource_CustomHeaders(t *testing.T) {
|
||||
"someotherheader": "X-Test-Header1",
|
||||
}),
|
||||
secureJsonData: map[string][]byte{},
|
||||
expectedHeaders: map[string]string{},
|
||||
expectedHeaders: http.Header{},
|
||||
},
|
||||
{
|
||||
name: "add multiple header value",
|
||||
jsonData: simplejson.NewFromAny(map[string]any{
|
||||
"httpHeaderName1": "X-Test-Header1",
|
||||
"httpHeaderName2": "X-Test-Header1",
|
||||
}),
|
||||
secureJsonData: map[string][]byte{
|
||||
"httpHeaderValue1": encryptedValue,
|
||||
"httpHeaderValue2": encryptedValue,
|
||||
},
|
||||
expectedHeaders: http.Header{
|
||||
"X-Test-Header1": []string{testValue, testValue},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
|
||||
// ApplyConfig updates the status state as the new config requires.
|
||||
// Extension: add new parameter headers.
|
||||
func (n *Manager) ApplyConfig(conf *config.Config, headers map[string]map[string]string) error {
|
||||
func (n *Manager) ApplyConfig(conf *config.Config, headers map[string]http.Header) error {
|
||||
n.mtx.Lock()
|
||||
defer n.mtx.Unlock()
|
||||
|
||||
@@ -57,7 +57,7 @@ type alertmanagerSet struct {
|
||||
client *http.Client
|
||||
|
||||
// Extension: headers that should be used for the http requests to the alertmanagers.
|
||||
headers map[string]string
|
||||
headers http.Header
|
||||
|
||||
metrics *alertMetrics
|
||||
|
||||
@@ -144,7 +144,7 @@ func (n *Manager) sendAll(alerts ...*Alert) bool {
|
||||
defer cancel()
|
||||
|
||||
// Extension: added headers parameter.
|
||||
go func(client *http.Client, url string, headers map[string]string) {
|
||||
go func(client *http.Client, url string, headers http.Header) {
|
||||
if err := n.sendOne(ctx, client, url, payload, headers); err != nil {
|
||||
level.Error(n.logger).Log("alertmanager", url, "count", len(alerts), "msg", "Error sending alert", "err", err)
|
||||
n.metrics.errors.WithLabelValues(url).Inc()
|
||||
@@ -167,7 +167,7 @@ func (n *Manager) sendAll(alerts ...*Alert) bool {
|
||||
}
|
||||
|
||||
// Extension: added headers parameter.
|
||||
func (n *Manager) sendOne(ctx context.Context, c *http.Client, url string, b []byte, headers map[string]string) error {
|
||||
func (n *Manager) sendOne(ctx context.Context, c *http.Client, url string, b []byte, headers http.Header) error {
|
||||
req, err := http.NewRequest("POST", url, bytes.NewReader(b))
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -176,7 +176,9 @@ func (n *Manager) sendOne(ctx context.Context, c *http.Client, url string, b []b
|
||||
req.Header.Set("Content-Type", contentTypeJSON)
|
||||
// Extension: set headers.
|
||||
for k, v := range headers {
|
||||
req.Header.Set(k, v)
|
||||
for _, vv := range v {
|
||||
req.Header.Set(k, vv)
|
||||
}
|
||||
}
|
||||
resp, err := n.opts.Do(ctx, c, req)
|
||||
if err != nil {
|
||||
|
||||
@@ -43,7 +43,7 @@ type ExternalAlertmanager struct {
|
||||
|
||||
type ExternalAMcfg struct {
|
||||
URL string
|
||||
Headers map[string]string
|
||||
Headers http.Header
|
||||
}
|
||||
|
||||
type Option func(*ExternalAlertmanager)
|
||||
@@ -177,9 +177,9 @@ func (s *ExternalAlertmanager) DroppedAlertmanagers() []*url.URL {
|
||||
return s.manager.DroppedAlertmanagers()
|
||||
}
|
||||
|
||||
func buildNotifierConfig(alertmanagers []ExternalAMcfg) (*config.Config, map[string]map[string]string, error) {
|
||||
func buildNotifierConfig(alertmanagers []ExternalAMcfg) (*config.Config, map[string]http.Header, error) {
|
||||
amConfigs := make([]*config.AlertmanagerConfig, 0, len(alertmanagers))
|
||||
headers := map[string]map[string]string{}
|
||||
headers := map[string]http.Header{}
|
||||
for i, am := range alertmanagers {
|
||||
u, err := url.Parse(am.URL)
|
||||
if err != nil {
|
||||
|
||||
@@ -28,7 +28,7 @@ func newHTTPClient(ctx context.Context, route types.AzRoute, model types.Datasou
|
||||
}
|
||||
|
||||
for header, value := range route.Headers {
|
||||
clientOpts.Headers[header] = value
|
||||
clientOpts.Header.Add(header, value)
|
||||
}
|
||||
|
||||
// Use Azure credentials if the route has OAuth scopes configured
|
||||
|
||||
@@ -72,18 +72,18 @@ func TestHttpClient_AzureCredentials(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
res := map[string]string{
|
||||
"GrafanaHeader": "GrafanaValue",
|
||||
"AzureHeader": "AzureValue",
|
||||
res := http.Header{
|
||||
"Grafanaheader": {"GrafanaValue"},
|
||||
"Azureheader": {"AzureValue"},
|
||||
}
|
||||
_, err := newHTTPClient(context.Background(), route, model, settings, azureSettings, provider)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.NotNil(t, provider.opts)
|
||||
|
||||
if provider.opts.Headers != nil {
|
||||
assert.Len(t, provider.opts.Headers, 2)
|
||||
assert.Equal(t, res, provider.opts.Headers)
|
||||
if provider.opts.Header != nil {
|
||||
assert.Len(t, provider.opts.Header, 2)
|
||||
assert.Equal(t, res, provider.opts.Header)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -81,9 +81,11 @@ func getDialOpts(settings backend.DataSourceInstanceSettings, opts httpclient.Op
|
||||
// to the CustomHeadersMiddleware in the HTTP client provider.
|
||||
func CustomHeadersStreamInterceptor(httpOpts httpclient.Options) grpc.StreamClientInterceptor {
|
||||
return func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error) {
|
||||
if len(httpOpts.Headers) != 0 {
|
||||
for key, value := range httpOpts.Headers {
|
||||
ctx = metadata.AppendToOutgoingContext(ctx, key, value)
|
||||
if len(httpOpts.Header) != 0 {
|
||||
for key, value := range httpOpts.Header {
|
||||
for _, v := range value {
|
||||
ctx = metadata.AppendToOutgoingContext(ctx, key, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user