From fd3c1e49eb1abe57c59cc8f5a45633e66f52f2ba Mon Sep 17 00:00:00 2001 From: Kevin Conaway Date: Fri, 5 Oct 2018 16:51:16 -0400 Subject: [PATCH] Add an option to specify a custom datadog URL (#4800) --- plugins/outputs/datadog/datadog.go | 17 ++++++++--------- plugins/outputs/datadog/datadog_test.go | 6 ++++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/plugins/outputs/datadog/datadog.go b/plugins/outputs/datadog/datadog.go index 2ef03a7b241e7..62e73f11548a6 100644 --- a/plugins/outputs/datadog/datadog.go +++ b/plugins/outputs/datadog/datadog.go @@ -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, + } }) } diff --git a/plugins/outputs/datadog/datadog_test.go b/plugins/outputs/datadog/datadog_test.go index f21ecc5887a9a..7c5e3cc1f0b4a 100644 --- a/plugins/outputs/datadog/datadog_test.go +++ b/plugins/outputs/datadog/datadog_test.go @@ -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