Skip to content

Commit

Permalink
Add HTTP proxy to datadog output (influxdata#9297)
Browse files Browse the repository at this point in the history
  • Loading branch information
akrantz01 authored Jun 1, 2021
1 parent aa83747 commit db0b6de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions plugins/outputs/datadog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion plugins/outputs/datadog/datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -22,6 +23,7 @@ type Datadog struct {
Log telegraf.Logger `toml:"-"`

client *http.Client
proxy.HTTPProxy
}

var sampleConfig = `
Expand All @@ -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 {
Expand All @@ -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),
}
Expand Down

0 comments on commit db0b6de

Please sign in to comment.