From 647fe1f591ce643038e29e7312fc315e87ff4b21 Mon Sep 17 00:00:00 2001 From: Nick Cabatoff Date: Wed, 12 Feb 2020 13:45:15 -0500 Subject: [PATCH] Add support for telemetry option `metrics_prefix`. When set, instead of starting with `vault_`, metrics will start with `${prefix}_`. --- command/server.go | 7 ++++++- command/server/config.go | 6 ++++-- command/server/config_test_helpers.go | 2 ++ command/server/test-fixtures/config.hcl | 1 + command/server/test-fixtures/config3.hcl | 1 + 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/command/server.go b/command/server.go index 9580245023ba..ae9be228c1a3 100644 --- a/command/server.go +++ b/command/server.go @@ -2320,7 +2320,12 @@ func (c *ServerCommand) setupTelemetry(config *server.Config) (*metricsutil.Metr telConfig = &server.Telemetry{} } - metricsConf := metrics.DefaultConfig("vault") + serviceName := "vault" + if telConfig.MetricsPrefix != "" { + serviceName = telConfig.MetricsPrefix + } + + metricsConf := metrics.DefaultConfig(serviceName) metricsConf.EnableHostname = !telConfig.DisableHostname metricsConf.EnableHostnameLabel = telConfig.EnableHostnameLabel diff --git a/command/server/config.go b/command/server/config.go index 347b72c98316..1224033ab3cc 100644 --- a/command/server/config.go +++ b/command/server/config.go @@ -179,8 +179,9 @@ type Telemetry struct { StatsiteAddr string `hcl:"statsite_address"` StatsdAddr string `hcl:"statsd_address"` - DisableHostname bool `hcl:"disable_hostname"` - EnableHostnameLabel bool `hcl:"enable_hostname_label"` + DisableHostname bool `hcl:"disable_hostname"` + EnableHostnameLabel bool `hcl:"enable_hostname_label"` + MetricsPrefix string `hcl:"metrics_prefix"` // Circonus: see https://github.com/circonus-labs/circonus-gometrics // for more details on the various configuration options. @@ -1099,6 +1100,7 @@ func (c *Config) Sanitized() map[string]interface{} { "statsite_address": c.Telemetry.StatsiteAddr, "statsd_address": c.Telemetry.StatsdAddr, "disable_hostname": c.Telemetry.DisableHostname, + "metrics_prefix": c.Telemetry.MetricsPrefix, "circonus_api_token": "", "circonus_api_app": c.Telemetry.CirconusAPIApp, "circonus_api_url": c.Telemetry.CirconusAPIURL, diff --git a/command/server/config_test_helpers.go b/command/server/config_test_helpers.go index 54f479a158d0..d4c00093aa10 100644 --- a/command/server/config_test_helpers.go +++ b/command/server/config_test_helpers.go @@ -321,6 +321,7 @@ func testLoadConfigFile(t *testing.T) { DogStatsDAddr: "127.0.0.1:7254", DogStatsDTags: []string{"tag_1:val_1", "tag_2:val_2"}, PrometheusRetentionTime: prometheusDefaultRetentionTime, + MetricsPrefix: "myprefix", }, DisableCache: true, @@ -554,6 +555,7 @@ func testConfig_Sanitized(t *testing.T) { "circonus_check_tags": "", "circonus_submission_interval": "", "disable_hostname": false, + "metrics_prefix": "pfx", "dogstatsd_addr": "", "dogstatsd_tags": []string(nil), "prometheus_retention_time": 24 * time.Hour, diff --git a/command/server/test-fixtures/config.hcl b/command/server/test-fixtures/config.hcl index e3c1ebe44e99..84639db66968 100644 --- a/command/server/test-fixtures/config.hcl +++ b/command/server/test-fixtures/config.hcl @@ -27,6 +27,7 @@ telemetry { statsite_address = "foo" dogstatsd_addr = "127.0.0.1:7254" dogstatsd_tags = ["tag_1:val_1", "tag_2:val_2"] + metrics_prefix = "myprefix" } max_lease_ttl = "10h" diff --git a/command/server/test-fixtures/config3.hcl b/command/server/test-fixtures/config3.hcl index 1358c2b18e81..250f54405cf1 100644 --- a/command/server/test-fixtures/config3.hcl +++ b/command/server/test-fixtures/config3.hcl @@ -29,6 +29,7 @@ service_registration "consul" { telemetry { statsd_address = "bar" circonus_api_token = "baz" + metrics_prefix = "pfx" } seal "awskms" {