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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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) {

View File

@ -8,8 +8,9 @@ import {
onUpdateDatasourceJsonDataOption,
updateDatasourcePluginJsonDataOption,
} from '@grafana/data';
import { Input, InlineField, FieldProps } from '@grafana/ui';
import { Input, InlineField, FieldProps, SecureSocksProxySettings } from '@grafana/ui';
import { notifyApp } from 'app/core/actions';
import { config } from 'app/core/config';
import { createWarningNotification } from 'app/core/copy/appNotification';
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
import { store } from 'app/store/store';
@ -66,6 +67,10 @@ export const ConfigEditor = (props: Props) => {
</InlineField>
</ConnectionConfig>
{config.featureToggles.secureSocksDatasourceProxy && (
<SecureSocksProxySettings options={options} onOptionsChange={onOptionsChange} />
)}
<h3 className="page-heading">CloudWatch Logs</h3>
<div className="gf-form-group">
<InlineField
@ -124,7 +129,6 @@ export const ConfigEditor = (props: Props) => {
/>
</InlineField>
</div>
<XrayLinkConfig
onChange={(uid) => updateDatasourcePluginJsonDataOption(props, 'tracingDatasourceUid', uid)}
datasourceUid={options.jsonData.tracingDatasourceUid}