Add tags option to datadog telemetry

Expose an global tags option in telemetry config for dogstatsd, for
purposes of distinguishing between multiple nomad cluster metrics.
This commit is contained in:
Mahmood Ali 2018-02-06 11:21:15 -05:00
parent b5c7c5f3ce
commit bebafb5234
6 changed files with 15 additions and 0 deletions

View File

@ -748,6 +748,7 @@ func (c *Command) setupTelemetry(config *Config) (*metrics.InmemSink, error) {
if err != nil { if err != nil {
return inm, err return inm, err
} }
sink.SetTags(telConfig.DataDogTags)
fanout = append(fanout, sink) fanout = append(fanout, sink)
} }

View File

@ -355,6 +355,7 @@ type Telemetry struct {
StatsiteAddr string `mapstructure:"statsite_address"` StatsiteAddr string `mapstructure:"statsite_address"`
StatsdAddr string `mapstructure:"statsd_address"` StatsdAddr string `mapstructure:"statsd_address"`
DataDogAddr string `mapstructure:"datadog_address"` DataDogAddr string `mapstructure:"datadog_address"`
DataDogTags []string `mapstructure:"datadog_tags"`
PrometheusMetrics bool `mapstructure:"prometheus_metrics"` PrometheusMetrics bool `mapstructure:"prometheus_metrics"`
DisableHostname bool `mapstructure:"disable_hostname"` DisableHostname bool `mapstructure:"disable_hostname"`
UseNodeName bool `mapstructure:"use_node_name"` UseNodeName bool `mapstructure:"use_node_name"`
@ -1170,6 +1171,9 @@ func (a *Telemetry) Merge(b *Telemetry) *Telemetry {
if b.DataDogAddr != "" { if b.DataDogAddr != "" {
result.DataDogAddr = b.DataDogAddr result.DataDogAddr = b.DataDogAddr
} }
if b.DataDogTags != nil {
result.DataDogTags = b.DataDogTags
}
if b.PrometheusMetrics { if b.PrometheusMetrics {
result.PrometheusMetrics = b.PrometheusMetrics result.PrometheusMetrics = b.PrometheusMetrics
} }

View File

@ -641,6 +641,7 @@ func parseTelemetry(result **Telemetry, list *ast.ObjectList) error {
"publish_allocation_metrics", "publish_allocation_metrics",
"publish_node_metrics", "publish_node_metrics",
"datadog_address", "datadog_address",
"datadog_tags",
"prometheus_metrics", "prometheus_metrics",
"circonus_api_token", "circonus_api_token",
"circonus_api_app", "circonus_api_app",

View File

@ -56,6 +56,7 @@ func TestConfig_Merge(t *testing.T) {
StatsiteAddr: "127.0.0.1:8125", StatsiteAddr: "127.0.0.1:8125",
StatsdAddr: "127.0.0.1:8125", StatsdAddr: "127.0.0.1:8125",
DataDogAddr: "127.0.0.1:8125", DataDogAddr: "127.0.0.1:8125",
DataDogTags: []string{"cat1:tag1", "cat2:tag2"},
PrometheusMetrics: true, PrometheusMetrics: true,
DisableHostname: false, DisableHostname: false,
DisableTaggedMetrics: true, DisableTaggedMetrics: true,
@ -191,6 +192,7 @@ func TestConfig_Merge(t *testing.T) {
StatsiteAddr: "127.0.0.2:8125", StatsiteAddr: "127.0.0.2:8125",
StatsdAddr: "127.0.0.2:8125", StatsdAddr: "127.0.0.2:8125",
DataDogAddr: "127.0.0.1:8125", DataDogAddr: "127.0.0.1:8125",
DataDogTags: []string{"cat1:tag1", "cat2:tag2"},
PrometheusMetrics: true, PrometheusMetrics: true,
DisableHostname: true, DisableHostname: true,
PublishNodeMetrics: true, PublishNodeMetrics: true,

View File

@ -279,6 +279,7 @@ $ curl \
"CirconusSubmissionInterval": "", "CirconusSubmissionInterval": "",
"CollectionInterval": "1s", "CollectionInterval": "1s",
"DataDogAddr": "", "DataDogAddr": "",
"DataDogTags": [],
"DisableHostname": false, "DisableHostname": false,
"PublishAllocationMetrics": false, "PublishAllocationMetrics": false,
"PublishNodeMetrics": false, "PublishNodeMetrics": false,

View File

@ -108,9 +108,15 @@ These `telemetry` parameters apply to
- `datadog_address` `(string: "")` - Specifies the address of a DataDog statsd - `datadog_address` `(string: "")` - Specifies the address of a DataDog statsd
server to forward metrics to. 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 ```hcl
telemetry { telemetry {
datadog_address = "dogstatsd.company.local:8125" datadog_address = "dogstatsd.company.local:8125"
datadog_tags = ["my_tag_name:my_tag_value"]
} }
``` ```