Add HTTP proxy to datadog output (#9297)

This commit is contained in:
Alexander Krantz 2021-06-01 14:18:31 -07:00 committed by GitHub
parent aa837476d7
commit db0b6de140
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -16,6 +16,9 @@ This plugin writes to the [Datadog Metrics API][metrics] and requires an
## Write URL override; useful for debugging.
# url = "https://app.datadoghq.com/api/v1/series"
## Set http_proxy (telegraf uses the system wide proxy settings if it isn't set)
# http_proxy_url = "http://localhost:8888"
```
### Metrics

View File

@ -12,6 +12,7 @@ import (
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/plugins/common/proxy"
"github.com/influxdata/telegraf/plugins/outputs"
)
@ -22,6 +23,7 @@ type Datadog struct {
Log telegraf.Logger `toml:"-"`
client *http.Client
proxy.HTTPProxy
}
var sampleConfig = `
@ -33,6 +35,9 @@ var sampleConfig = `
## Write URL override; useful for debugging.
# url = "https://app.datadoghq.com/api/v1/series"
## Set http_proxy (telegraf uses the system wide proxy settings if it isn't set)
# http_proxy_url = "http://localhost:8888"
`
type TimeSeries struct {
@ -55,9 +60,14 @@ func (d *Datadog) Connect() error {
return fmt.Errorf("apikey is a required field for datadog output")
}
proxyFunc, err := d.Proxy()
if err != nil {
return err
}
d.client = &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
Proxy: proxyFunc,
},
Timeout: time.Duration(d.Timeout),
}