From 48774c53063d3425961f4ccc45c4f91c349edc02 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Tue, 6 Feb 2018 11:21:15 -0500 Subject: [PATCH] Add tags option to datadog telemtry Expose an global tags option in telemtry config for dogstatsd, for purposes of distinguishing between multiple nomad cluster metrics. This is close in spirit to https://github.com/hashicorp/consul/pull/1293 --- command/agent/command.go | 1 + command/agent/config.go | 4 ++++ command/agent/config_test.go | 2 ++ website/source/api/agent.html.md | 1 + website/source/docs/agent/configuration/telemetry.html.md | 6 ++++++ 5 files changed, 14 insertions(+) diff --git a/command/agent/command.go b/command/agent/command.go index 74bbf96149e2..89ecc58ea24a 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -748,6 +748,7 @@ func (c *Command) setupTelemetry(config *Config) (*metrics.InmemSink, error) { if err != nil { return inm, err } + sink.SetTags(telConfig.DataDogTags) fanout = append(fanout, sink) } diff --git a/command/agent/config.go b/command/agent/config.go index 6eb1fad06e49..5cd1ebf1736d 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -355,6 +355,7 @@ type Telemetry struct { StatsiteAddr string `mapstructure:"statsite_address"` StatsdAddr string `mapstructure:"statsd_address"` DataDogAddr string `mapstructure:"datadog_address"` + DataDogTags []string `mapstructure:"datadog_tags"` PrometheusMetrics bool `mapstructure:"prometheus_metrics"` DisableHostname bool `mapstructure:"disable_hostname"` UseNodeName bool `mapstructure:"use_node_name"` @@ -1170,6 +1171,9 @@ func (a *Telemetry) Merge(b *Telemetry) *Telemetry { if b.DataDogAddr != "" { result.DataDogAddr = b.DataDogAddr } + if b.DataDogTags != nil { + result.DataDogTags = b.DataDogTags + } if b.PrometheusMetrics { result.PrometheusMetrics = b.PrometheusMetrics } diff --git a/command/agent/config_test.go b/command/agent/config_test.go index 3ed05bd46320..35a6b59e2dd7 100644 --- a/command/agent/config_test.go +++ b/command/agent/config_test.go @@ -56,6 +56,7 @@ func TestConfig_Merge(t *testing.T) { StatsiteAddr: "127.0.0.1:8125", StatsdAddr: "127.0.0.1:8125", DataDogAddr: "127.0.0.1:8125", + DataDogTags: []string{"cat1:tag1", "cat2:tag2"}, PrometheusMetrics: true, DisableHostname: false, DisableTaggedMetrics: true, @@ -191,6 +192,7 @@ func TestConfig_Merge(t *testing.T) { StatsiteAddr: "127.0.0.2:8125", StatsdAddr: "127.0.0.2:8125", DataDogAddr: "127.0.0.1:8125", + DataDogTags: []string{"cat1:tag1", "cat2:tag2"}, PrometheusMetrics: true, DisableHostname: true, PublishNodeMetrics: true, diff --git a/website/source/api/agent.html.md b/website/source/api/agent.html.md index 6172d2e0231e..b8b390fa6833 100644 --- a/website/source/api/agent.html.md +++ b/website/source/api/agent.html.md @@ -279,6 +279,7 @@ $ curl \ "CirconusSubmissionInterval": "", "CollectionInterval": "1s", "DataDogAddr": "", + "DataDogTags": [], "DisableHostname": false, "PublishAllocationMetrics": false, "PublishNodeMetrics": false, diff --git a/website/source/docs/agent/configuration/telemetry.html.md b/website/source/docs/agent/configuration/telemetry.html.md index b32af1e8173c..bf5b486e3a24 100644 --- a/website/source/docs/agent/configuration/telemetry.html.md +++ b/website/source/docs/agent/configuration/telemetry.html.md @@ -108,9 +108,15 @@ These `telemetry` parameters apply to - `datadog_address` `(string: "")` - Specifies the address of a DataDog statsd server to forward metrics to. +- `datadog_tags` `(list: [])` - Specifies a list of global tags that will be + added to all telemetry packets sent to DogStatsD. It is a list of strings, + where each string looks like "my_tag_name:my_tag_value". + + ```hcl telemetry { datadog_address = "dogstatsd.company.local:8125" + datadog_tags = ["my_tag_name:my_tag_value"] } ```