add config flag to disable 1.9 metrics backwards compatibility. Add warnings on start and reload on default value

This commit is contained in:
Kit Patella 2020-10-07 17:12:52 -07:00
parent 9851a16d05
commit 328036dd37
6 changed files with 30 additions and 6 deletions

View File

@ -592,6 +592,12 @@ func (a *Agent) Start(ctx context.Context) error {
go a.retryJoinWAN() go a.retryJoinWAN()
} }
// DEPRECATED: Warn users if they're emitting deprecated metrics. Remove this warning and the flagged metrics in a
// future release of Consul.
if !a.config.Telemetry.DisableCompatOneNine {
a.logger.Warn("DEPRECATED Backwards compatibility with pre-1.9 metrics enabled. These metrics will be removed in a future version of Consul. Set `telemetry { disable_compat_1.9 = true }` to disable them.")
}
return nil return nil
} }
@ -3489,6 +3495,12 @@ func (a *Agent) ReloadConfig() error {
// breaking some existing behavior. // breaking some existing behavior.
newCfg.NodeID = a.config.NodeID newCfg.NodeID = a.config.NodeID
// DEPRECATED: Warn users on reload if they're emitting deprecated metrics. Remove this warning and the flagged
// metrics in a future release of Consul.
if !a.config.Telemetry.DisableCompatOneNine {
a.logger.Warn("DEPRECATED Backwards compatibility with pre-1.9 metrics enabled. These metrics will be removed in a future version of Consul. Set `telemetry { disable_compat_1.9 = true }` to disable them.")
}
return a.reloadConfigInternal(newCfg) return a.reloadConfigInternal(newCfg)
} }

View File

@ -936,6 +936,7 @@ func (b *Builder) Build() (rt RuntimeConfig, err error) {
CirconusCheckTags: b.stringVal(c.Telemetry.CirconusCheckTags), CirconusCheckTags: b.stringVal(c.Telemetry.CirconusCheckTags),
CirconusSubmissionInterval: b.stringVal(c.Telemetry.CirconusSubmissionInterval), CirconusSubmissionInterval: b.stringVal(c.Telemetry.CirconusSubmissionInterval),
CirconusSubmissionURL: b.stringVal(c.Telemetry.CirconusSubmissionURL), CirconusSubmissionURL: b.stringVal(c.Telemetry.CirconusSubmissionURL),
DisableCompatOneNine: b.boolVal(c.Telemetry.DisableCompatOneNine),
DisableHostname: b.boolVal(c.Telemetry.DisableHostname), DisableHostname: b.boolVal(c.Telemetry.DisableHostname),
DogstatsdAddr: b.stringVal(c.Telemetry.DogstatsdAddr), DogstatsdAddr: b.stringVal(c.Telemetry.DogstatsdAddr),
DogstatsdTags: c.Telemetry.DogstatsdTags, DogstatsdTags: c.Telemetry.DogstatsdTags,

View File

@ -628,6 +628,7 @@ type Telemetry struct {
CirconusCheckTags *string `json:"circonus_check_tags,omitempty" hcl:"circonus_check_tags" mapstructure:"circonus_check_tags"` CirconusCheckTags *string `json:"circonus_check_tags,omitempty" hcl:"circonus_check_tags" mapstructure:"circonus_check_tags"`
CirconusSubmissionInterval *string `json:"circonus_submission_interval,omitempty" hcl:"circonus_submission_interval" mapstructure:"circonus_submission_interval"` CirconusSubmissionInterval *string `json:"circonus_submission_interval,omitempty" hcl:"circonus_submission_interval" mapstructure:"circonus_submission_interval"`
CirconusSubmissionURL *string `json:"circonus_submission_url,omitempty" hcl:"circonus_submission_url" mapstructure:"circonus_submission_url"` CirconusSubmissionURL *string `json:"circonus_submission_url,omitempty" hcl:"circonus_submission_url" mapstructure:"circonus_submission_url"`
DisableCompatOneNine *bool `json:"disable_compat_1.9,omitempty" hcl:"disable_compat_1.9" mapstructure:"disable_compat_1.9"`
DisableHostname *bool `json:"disable_hostname,omitempty" hcl:"disable_hostname" mapstructure:"disable_hostname"` DisableHostname *bool `json:"disable_hostname,omitempty" hcl:"disable_hostname" mapstructure:"disable_hostname"`
DogstatsdAddr *string `json:"dogstatsd_addr,omitempty" hcl:"dogstatsd_addr" mapstructure:"dogstatsd_addr"` DogstatsdAddr *string `json:"dogstatsd_addr,omitempty" hcl:"dogstatsd_addr" mapstructure:"dogstatsd_addr"`
DogstatsdTags []string `json:"dogstatsd_tags,omitempty" hcl:"dogstatsd_tags" mapstructure:"dogstatsd_tags"` DogstatsdTags []string `json:"dogstatsd_tags,omitempty" hcl:"dogstatsd_tags" mapstructure:"dogstatsd_tags"`

View File

@ -5227,7 +5227,8 @@ func TestFullConfig(t *testing.T) {
"metrics_prefix": "ftO6DySn", "metrics_prefix": "ftO6DySn",
"prometheus_retention_time": "15s", "prometheus_retention_time": "15s",
"statsd_address": "drce87cy", "statsd_address": "drce87cy",
"statsite_address": "HpFwKB8R" "statsite_address": "HpFwKB8R",
"disable_compat_1.9": true
}, },
"tls_cipher_suites": "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", "tls_cipher_suites": "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256",
"tls_min_version": "pAOWafkR", "tls_min_version": "pAOWafkR",
@ -5911,6 +5912,7 @@ func TestFullConfig(t *testing.T) {
prometheus_retention_time = "15s" prometheus_retention_time = "15s"
statsd_address = "drce87cy" statsd_address = "drce87cy"
statsite_address = "HpFwKB8R" statsite_address = "HpFwKB8R"
disable_compat_1.9 = true
} }
tls_cipher_suites = "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256" tls_cipher_suites = "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256"
tls_min_version = "pAOWafkR" tls_min_version = "pAOWafkR"
@ -6681,6 +6683,7 @@ func TestFullConfig(t *testing.T) {
CirconusCheckTags: "prvO4uBl", CirconusCheckTags: "prvO4uBl",
CirconusSubmissionInterval: "DolzaflP", CirconusSubmissionInterval: "DolzaflP",
CirconusSubmissionURL: "gTcbS93G", CirconusSubmissionURL: "gTcbS93G",
DisableCompatOneNine: true,
DisableHostname: true, DisableHostname: true,
DogstatsdAddr: "0wSndumK", DogstatsdAddr: "0wSndumK",
DogstatsdTags: []string{"3N81zSUB", "Xtj8AnXZ"}, DogstatsdTags: []string{"3N81zSUB", "Xtj8AnXZ"},
@ -7379,6 +7382,7 @@ func TestSanitize(t *testing.T) {
"CirconusSubmissionInterval": "", "CirconusSubmissionInterval": "",
"CirconusSubmissionURL": "", "CirconusSubmissionURL": "",
"Disable": false, "Disable": false,
"DisableCompatOneNine": false,
"DisableHostname": false, "DisableHostname": false,
"DogstatsdAddr": "", "DogstatsdAddr": "",
"DogstatsdTags": [], "DogstatsdTags": [],

View File

@ -195,14 +195,15 @@ func (s *HTTPHandlers) handler(enableDebug bool) http.Handler {
start := time.Now() start := time.Now()
handler(resp, req) handler(resp, req)
// This new metric is disabled by default with the prefix_filter option.
// It will be enabled by default in a future version.
labels := []metrics.Label{{Name: "method", Value: req.Method}, {Name: "path", Value: path_label}} labels := []metrics.Label{{Name: "method", Value: req.Method}, {Name: "path", Value: path_label}}
metrics.MeasureSinceWithLabels([]string{"api", "http"}, start, labels) metrics.MeasureSinceWithLabels([]string{"api", "http"}, start, labels)
// Duplicated information. Kept for backward compatibility. // DEPRECATED Emit pre-1.9 metric as `consul.http...` to maintain backwards compatibility. Enabled by
key := append([]string{"http", req.Method}, parts...) // default. Users may set `telemetry { disable_compat_1.9 = true }`
metrics.MeasureSince(key, start) if !s.agent.config.Telemetry.DisableCompatOneNine {
key := append([]string{"http", req.Method}, parts...)
metrics.MeasureSince(key, start)
}
} }
var gzipHandler http.Handler var gzipHandler http.Handler

View File

@ -132,6 +132,11 @@ type TelemetryConfig struct {
// hcl: telemetry { circonus_submission_url = string } // hcl: telemetry { circonus_submission_url = string }
CirconusSubmissionURL string `json:"circonus_submission_url,omitempty" mapstructure:"circonus_submission_url"` CirconusSubmissionURL string `json:"circonus_submission_url,omitempty" mapstructure:"circonus_submission_url"`
// DisableCompatOneNine is a flag to stop emitting metrics that have been deprecated in version 1.9.
//
// hcl: telemetry { disable_compat_1.9 = (true|false) }
DisableCompatOneNine bool `json:"disable_compat_1.9,omitempty" mapstructure:"disable_compat_1.9"`
// DisableHostname will disable hostname prefixing for all metrics. // DisableHostname will disable hostname prefixing for all metrics.
// //
// hcl: telemetry { disable_hostname = (true|false) // hcl: telemetry { disable_hostname = (true|false)