Plugins: Add cloudwatch support with the secure socks proxy (#65303)

* Plugins: enable secure socks proxy on cloudwatch with workaround
This commit is contained in:
Stephanie Hingtgen
2023-03-27 11:00:37 -05:00
committed by GitHub
parent 52a0f59706
commit fb5a7acc73
3 changed files with 27 additions and 6 deletions

View File

@@ -99,7 +99,12 @@ func NewInstanceSettings(httpClientProvider httpclient.Provider) datasource.Inst
return nil, fmt.Errorf("error reading settings: %w", err)
}
httpClient, err := httpClientProvider.New()
opts, err := settings.HTTPClientOptions()
if err != nil {
return nil, err
}
httpClient, err := httpClientProvider.New(opts)
if err != nil {
return nil, fmt.Errorf("error creating http client: %w", err)
}
@@ -245,9 +250,9 @@ func (e *cloudWatchExecutor) newSession(pluginCtx backend.PluginContext, region
region = instance.Settings.Region
}
return e.sessions.GetSession(awsds.SessionConfig{
sess, err := e.sessions.GetSession(awsds.SessionConfig{
// https://github.com/grafana/grafana/issues/46365
// HTTPClient: dsInfo.HTTPClient,
// HTTPClient: instance.HTTPClient,
Settings: awsds.AWSDatasourceSettings{
Profile: instance.Settings.Profile,
Region: region,
@@ -261,6 +266,17 @@ func (e *cloudWatchExecutor) newSession(pluginCtx backend.PluginContext, region
},
UserAgentName: aws.String("Cloudwatch"),
})
if err != nil {
return nil, err
}
// work around until https://github.com/grafana/grafana/issues/39089 is implemented
if e.cfg.SecureSocksDSProxy.Enabled && e.features.IsEnabled(featuremgmt.FlagSecureSocksDatasourceProxy) && instance.Settings.SecureSocksProxyEnabled {
// only update the transport to try to avoid the issue mentioned here https://github.com/grafana/grafana/issues/46365
sess.Config.HTTPClient.Transport = instance.HTTPClient.Transport
}
return sess, nil
}
func (e *cloudWatchExecutor) getInstance(pluginCtx backend.PluginContext) (*DataSource, error) {

View File

@@ -10,7 +10,8 @@ import (
type CloudWatchSettings struct {
awsds.AWSDatasourceSettings
Namespace string `json:"customMetricsNamespaces"`
Namespace string `json:"customMetricsNamespaces"`
SecureSocksProxyEnabled bool `json:"enableSecureSocksProxy"` // this can be removed when https://github.com/grafana/grafana/issues/39089 is implemented
}
func LoadCloudWatchSettings(config backend.DataSourceInstanceSettings) (CloudWatchSettings, error) {