CloudWatch: Fix http client handling + assume role bug (#107893)

pull/107896/head
Nathan Vērzemnieks 2 weeks ago committed by GitHub
parent c5fbf6217c
commit f34a9fc0c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 18
      pkg/tsdb/cloudwatch/cloudwatch.go

@ -16,9 +16,9 @@ import (
"github.com/grafana/grafana-aws-sdk/pkg/awsauth"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
"github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt"
"github.com/grafana/grafana-plugin-sdk-go/backend/log"
"github.com/grafana/grafana-plugin-sdk-go/backend/proxy"
"github.com/grafana/grafana-plugin-sdk-go/backend/resource/httpadapter"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/clients"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/kinds/dataquery"
@ -50,7 +50,7 @@ type DataQueryJson struct {
type DataSource struct {
Settings models.CloudWatchSettings
HTTPClient *http.Client
ProxyOpts *proxy.Options
AWSConfigProvider awsauth.ConfigProvider
logger log.Logger
@ -74,7 +74,10 @@ func (ds *DataSource) newAWSConfig(ctx context.Context, region string) (aws.Conf
Region: region,
AccessKey: ds.Settings.AccessKey,
SecretKey: ds.Settings.SecretKey,
HTTPClient: ds.HTTPClient,
HTTPClient: &http.Client{},
}
if ds.Settings.GrafanaSettings.SecureSocksDSProxyEnabled && ds.Settings.SecureSocksProxyEnabled {
authSettings.ProxyOptions = ds.ProxyOpts
}
cfg, err := ds.AWSConfigProvider.GetConfig(ctx, authSettings)
if err != nil {
@ -93,14 +96,11 @@ func NewDatasource(ctx context.Context, settings backend.DataSourceInstanceSetti
if err != nil {
return nil, err
}
httpClient, err := httpclient.New(opts)
if err != nil {
return nil, err
}
ds := &DataSource{
Settings: instanceSettings,
HTTPClient: httpClient,
Settings: instanceSettings,
// this is used to build a custom dialer when secure socks proxy is enabled
ProxyOpts: opts.ProxyOptions,
AWSConfigProvider: awsauth.NewConfigProvider(),
logger: backend.NewLoggerWith("logger", "grafana-cloudwatch-datasource"),
tagValueCache: cache.New(tagValueCacheExpiration, tagValueCacheExpiration*5),

Loading…
Cancel
Save