Skip to content

Commit db0b6de

Browse files
authored
Add HTTP proxy to datadog output (#9297)
1 parent aa83747 commit db0b6de

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

plugins/outputs/datadog/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ This plugin writes to the [Datadog Metrics API][metrics] and requires an
1616

1717
## Write URL override; useful for debugging.
1818
# url = "https://app.datadoghq.com/api/v1/series"
19+
20+
## Set http_proxy (telegraf uses the system wide proxy settings if it isn't set)
21+
# http_proxy_url = "http://localhost:8888"
1922
```
2023

2124
### Metrics

plugins/outputs/datadog/datadog.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/influxdata/telegraf"
1414
"github.com/influxdata/telegraf/config"
15+
"github.com/influxdata/telegraf/plugins/common/proxy"
1516
"github.com/influxdata/telegraf/plugins/outputs"
1617
)
1718

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

2425
client *http.Client
26+
proxy.HTTPProxy
2527
}
2628

2729
var sampleConfig = `
@@ -33,6 +35,9 @@ var sampleConfig = `
3335
3436
## Write URL override; useful for debugging.
3537
# url = "https://app.datadoghq.com/api/v1/series"
38+
39+
## Set http_proxy (telegraf uses the system wide proxy settings if it isn't set)
40+
# http_proxy_url = "http://localhost:8888"
3641
`
3742

3843
type TimeSeries struct {
@@ -55,9 +60,14 @@ func (d *Datadog) Connect() error {
5560
return fmt.Errorf("apikey is a required field for datadog output")
5661
}
5762

63+
proxyFunc, err := d.Proxy()
64+
if err != nil {
65+
return err
66+
}
67+
5868
d.client = &http.Client{
5969
Transport: &http.Transport{
60-
Proxy: http.ProxyFromEnvironment,
70+
Proxy: proxyFunc,
6171
},
6272
Timeout: time.Duration(d.Timeout),
6373
}

0 commit comments

Comments
 (0)