Add an option to specify a custom datadog URL (#4800)

This commit is contained in:
Kevin Conaway 2018-10-05 16:51:16 -04:00 committed by Daniel Nelson
parent 422c142463
commit 34caf12db5
2 changed files with 14 additions and 9 deletions

View File

@ -18,7 +18,7 @@ type Datadog struct {
Apikey string
Timeout internal.Duration
apiUrl string
URL string `toml:"url"`
client *http.Client
}
@ -26,6 +26,9 @@ var sampleConfig = `
## Datadog API key
apikey = "my-secret-key" # required.
# The base endpoint URL can optionally be specified but it defaults to:
#url = "https://app.datadoghq.com/api/v1/series"
## Connection timeout.
# timeout = "5s"
`
@ -45,12 +48,6 @@ type Point [2]float64
const datadog_api = "https://app.datadoghq.com/api/v1/series"
func NewDatadog(apiUrl string) *Datadog {
return &Datadog{
apiUrl: apiUrl,
}
}
func (d *Datadog) Connect() error {
if d.Apikey == "" {
return fmt.Errorf("apikey is a required field for datadog output")
@ -139,7 +136,7 @@ func (d *Datadog) authenticatedUrl() string {
q := url.Values{
"api_key": []string{d.Apikey},
}
return fmt.Sprintf("%s?%s", d.apiUrl, q.Encode())
return fmt.Sprintf("%s?%s", d.URL, q.Encode())
}
func buildMetrics(m telegraf.Metric) (map[string]Point, error) {
@ -201,6 +198,8 @@ func (d *Datadog) Close() error {
func init() {
outputs.Add("datadog", func() telegraf.Output {
return NewDatadog(datadog_api)
return &Datadog{
URL: datadog_api,
}
})
}

View File

@ -21,6 +21,12 @@ var (
fakeApiKey = "123456"
)
func NewDatadog(url string) *Datadog {
return &Datadog{
URL: url,
}
}
func fakeDatadog() *Datadog {
d := NewDatadog(fakeUrl)
d.Apikey = fakeApiKey