feat: add proxy support for outputs/cloudwatch (#11399)

This commit is contained in:
Markus Scholz 2022-07-13 21:04:02 +02:00 committed by GitHub
parent a5bc5b5974
commit 20acbf7090
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 6 deletions

View File

@ -59,6 +59,10 @@ The IAM user needs only the `cloudwatch:PutMetricData` permission.
## ex: endpoint_url = "http://localhost:8000"
# endpoint_url = ""
## Set http_proxy
# use_system_proxy = false
# http_proxy_url = "http://localhost:8888"
## Namespace for the CloudWatch MetricDatums
namespace = "InfluxData/Telegraf"

View File

@ -15,6 +15,9 @@ import (
"github.com/influxdata/telegraf"
internalaws "github.com/influxdata/telegraf/config/aws"
httpconfig "github.com/influxdata/telegraf/plugins/common/http"
"github.com/influxdata/telegraf/plugins/outputs"
)
@ -26,12 +29,10 @@ type CloudWatch struct {
Namespace string `toml:"namespace"` // CloudWatch Metrics Namespace
HighResolutionMetrics bool `toml:"high_resolution_metrics"`
svc *cloudwatch.Client
WriteStatistics bool `toml:"write_statistics"`
Log telegraf.Logger `toml:"-"`
WriteStatistics bool `toml:"write_statistics"`
Log telegraf.Logger `toml:"-"`
internalaws.CredentialConfig
httpconfig.HTTPClientConfig
}
type statisticType int
@ -159,12 +160,24 @@ func (*CloudWatch) SampleConfig() string {
}
func (c *CloudWatch) Connect() error {
cfg, err := c.CredentialConfig.Credentials()
if err != nil {
return err
}
c.svc = cloudwatch.NewFromConfig(cfg)
ctx := context.Background()
client, err := c.HTTPClientConfig.CreateClient(ctx, c.Log)
if err != nil {
return err
}
c.svc = cloudwatch.NewFromConfig(cfg, func(options *cloudwatch.Options) {
options.HTTPClient = client
})
return nil
}

View File

@ -27,6 +27,10 @@
## ex: endpoint_url = "http://localhost:8000"
# endpoint_url = ""
## Set http_proxy
# use_system_proxy = false
# http_proxy_url = "http://localhost:8888"
## Namespace for the CloudWatch MetricDatums
namespace = "InfluxData/Telegraf"