Skip to content

Commit

Permalink
Add new Telemetry config options (#9238)
Browse files Browse the repository at this point in the history
* Add new Telemetry config options

Add cluster_name, maximum_gauge_cardinality, and usage_gauge_period
configuration options to the config stanza.

Update unit tests.

Document.

Co-authored-by: Mark Gritter <[email protected]>
  • Loading branch information
2 people authored and andaley committed Jul 17, 2020
1 parent f3a4d04 commit ffd04db
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 3 deletions.
12 changes: 12 additions & 0 deletions command/server/config_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ func testLoadConfigFile_topLevel(t *testing.T, entropy *configutil.Entropy) {
DogStatsDAddr: "127.0.0.1:7254",
DogStatsDTags: []string{"tag_1:val_1", "tag_2:val_2"},
PrometheusRetentionTime: 30 * time.Second,
UsageGaugePeriod: 5 * time.Minute,
MaximumGaugeCardinality: 125,
},

DisableMlock: true,
Expand Down Expand Up @@ -170,6 +172,8 @@ func testLoadConfigFile_json2(t *testing.T, entropy *configutil.Entropy) {
StatsiteAddr: "foo",
StatsdAddr: "bar",
DisableHostname: true,
UsageGaugePeriod: 5 * time.Minute,
MaximumGaugeCardinality: 125,
CirconusAPIToken: "0",
CirconusAPIApp: "vault",
CirconusAPIURL: "http://api.circonus.com/v2",
Expand Down Expand Up @@ -364,6 +368,8 @@ func testLoadConfigFile(t *testing.T) {
StatsdAddr: "bar",
StatsiteAddr: "foo",
DisableHostname: false,
UsageGaugePeriod: 5 * time.Minute,
MaximumGaugeCardinality: 100,
DogStatsDAddr: "127.0.0.1:7254",
DogStatsDTags: []string{"tag_1:val_1", "tag_2:val_2"},
PrometheusRetentionTime: configutil.PrometheusDefaultRetentionTime,
Expand Down Expand Up @@ -446,6 +452,8 @@ func testLoadConfigFile_json(t *testing.T) {
StatsiteAddr: "baz",
StatsdAddr: "",
DisableHostname: false,
UsageGaugePeriod: 5 * time.Minute,
MaximumGaugeCardinality: 100,
CirconusAPIToken: "",
CirconusAPIApp: "",
CirconusAPIURL: "",
Expand Down Expand Up @@ -523,6 +531,8 @@ func testLoadConfigDir(t *testing.T) {
StatsiteAddr: "qux",
StatsdAddr: "baz",
DisableHostname: true,
UsageGaugePeriod: 5 * time.Minute,
MaximumGaugeCardinality: 100,
PrometheusRetentionTime: configutil.PrometheusDefaultRetentionTime,
},
ClusterName: "testcluster",
Expand Down Expand Up @@ -616,6 +626,8 @@ func testConfig_Sanitized(t *testing.T) {
"type": "consul",
},
"telemetry": map[string]interface{}{
"usage_gauge_period": 5 * time.Minute,
"maximum_gauge_cardinality": 100,
"circonus_api_app": "",
"circonus_api_token": "",
"circonus_api_url": "",
Expand Down
2 changes: 2 additions & 0 deletions command/server/test-fixtures/config-dir/baz.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ telemetry {
statsd_address = "baz"
statsite_address = "qux"
disable_hostname = true
usage_gauge_period = "5m"
maximum_gauge_cardinality = 100
}
ui=true
raw_storage_endpoint=true
Expand Down
3 changes: 3 additions & 0 deletions command/server/test-fixtures/config.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ service_registration "consul" {

telemetry {
statsd_address = "bar"
usage_gauge_period = "5m"
maximum_gauge_cardinality = 100

statsite_address = "foo"
dogstatsd_addr = "127.0.0.1:7254"
dogstatsd_tags = ["tag_1:val_1", "tag_2:val_2"]
Expand Down
4 changes: 3 additions & 1 deletion command/server/test-fixtures/config.hcl.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
}
},
"telemetry": {
"statsite_address": "baz"
"statsite_address": "baz",
"usage_gauge_period": "5m",
"maximum_gauge_cardinality": 100
},
"max_lease_ttl": "10h",
"default_lease_ttl": "10h",
Expand Down
2 changes: 2 additions & 0 deletions command/server/test-fixtures/config2.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ service_registration "consul" {

telemetry {
statsd_address = "bar"
usage_gauge_period = "5m"
maximum_gauge_cardinality = 125
statsite_address = "foo"
dogstatsd_addr = "127.0.0.1:7254"
dogstatsd_tags = ["tag_1:val_1", "tag_2:val_2"]
Expand Down
3 changes: 3 additions & 0 deletions command/server/test-fixtures/config2.hcl.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
"statsd_address":"bar",
"statsite_address":"foo",
"disable_hostname":true,
"usage_gauge_period": "5m",
"maximum_gauge_cardinality": 125,

"circonus_api_token": "0",
"circonus_api_app": "vault",
"circonus_api_url": "http://api.circonus.com/v2",
Expand Down
2 changes: 2 additions & 0 deletions command/server/test-fixtures/config3.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ telemetry {
statsd_address = "bar"
circonus_api_token = "baz"
metrics_prefix = "pfx"
usage_gauge_period = "5m"
maximum_gauge_cardinality = 100
}

seal "awskms" {
Expand Down
2 changes: 2 additions & 0 deletions internalshared/configutil/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ func (c *SharedConfig) Sanitized() map[string]interface{} {
"statsd_address": c.Telemetry.StatsdAddr,
"disable_hostname": c.Telemetry.DisableHostname,
"metrics_prefix": c.Telemetry.MetricsPrefix,
"usage_gauge_period": c.Telemetry.UsageGaugePeriod,
"maximum_gauge_cardinality": c.Telemetry.MaximumGaugeCardinality,
"circonus_api_token": "",
"circonus_api_app": c.Telemetry.CirconusAPIApp,
"circonus_api_url": c.Telemetry.CirconusAPIURL,
Expand Down
28 changes: 26 additions & 2 deletions internalshared/configutil/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (

const (
PrometheusDefaultRetentionTime = 24 * time.Hour
UsageGaugeDefaultPeriod = 10 * time.Minute
MaximumGaugeCardinalityDefault = 500
)

// Telemetry is the telemetry configuration for the server
Expand All @@ -35,6 +37,10 @@ type Telemetry struct {
DisableHostname bool `hcl:"disable_hostname"`
EnableHostnameLabel bool `hcl:"enable_hostname_label"`
MetricsPrefix string `hcl:"metrics_prefix"`
UsageGaugePeriod time.Duration
UsageGaugePeriodRaw interface{} `hcl:"usage_gauge_period"`

MaximumGaugeCardinality int `hcl:"maximum_gauge_cardinality"`

// Circonus: see https://github.com/circonus-labs/circonus-gometrics
// for more details on the various configuration options.
Expand Down Expand Up @@ -168,6 +174,24 @@ func parseTelemetry(result *SharedConfig, list *ast.ObjectList) error {
result.Telemetry.PrometheusRetentionTime = PrometheusDefaultRetentionTime
}

if result.Telemetry.UsageGaugePeriodRaw != nil {
if result.Telemetry.UsageGaugePeriodRaw == "none" {
result.Telemetry.UsageGaugePeriod = 0
} else {
var err error
if result.Telemetry.UsageGaugePeriod, err = parseutil.ParseDurationSecond(result.Telemetry.UsageGaugePeriodRaw); err != nil {
return err
}
result.Telemetry.UsageGaugePeriodRaw = nil
}
} else {
result.Telemetry.UsageGaugePeriod = UsageGaugeDefaultPeriod
}

if result.Telemetry.MaximumGaugeCardinality == 0 {
result.Telemetry.MaximumGaugeCardinality = MaximumGaugeCardinalityDefault
}

return nil
}

Expand Down Expand Up @@ -330,8 +354,8 @@ func SetupTelemetry(opts *SetupTelemetryOpts) (*metrics.InmemSink, *metricsutil.
// and to any backend.
wrapper := &metricsutil.ClusterMetricSink{
ClusterName: opts.ClusterName,
MaxGaugeCardinality: 500,
GaugeInterval: 10 * time.Minute,
MaxGaugeCardinality: opts.Config.MaximumGaugeCardinality,
GaugeInterval: opts.Config.UsageGaugePeriod,
Sink: globalMetrics,
}

Expand Down
4 changes: 4 additions & 0 deletions website/pages/docs/configuration/telemetry.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ parameters on this page are grouped by the telemetry provider.

The following options are available on all telemetry configurations.

- `usage_gauge_period` `(string: "10m")` - Specifies the interval at which high-cardinality
usage data is collected, such as token counts, entity counts, and secret counts.
A value of "none" disables the collection.
- `maximum_gauge_cardinality` `(int: 500)` - The maximum cardinality of gauge labels.
- `disable_hostname` `(bool: false)` - Specifies if gauge values should be
prefixed with the local hostname.
- `enable_hostname_label` `(bool: false)` - Specifies if all metric values should
Expand Down

0 comments on commit ffd04db

Please sign in to comment.