Skip to content

Commit

Permalink
Add an option to specify a custom datadog URL (influxdata#4800)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinconaway authored and rgitzel committed Oct 17, 2018
1 parent a0bc566 commit 092d26a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
17 changes: 8 additions & 9 deletions plugins/outputs/datadog/datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ type Datadog struct {
Apikey string
Timeout internal.Duration

apiUrl string
URL string `toml:"url"`
client *http.Client
}

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"
`
Expand All @@ -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")
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
}
})
}
6 changes: 6 additions & 0 deletions plugins/outputs/datadog/datadog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 092d26a

Please sign in to comment.