Skip to content

Commit adeabf2

Browse files
authored
Merge pull request hashicorp#8877 from hashicorp/mkcp/telemetry/consul.api.http
Add flag for disabling 1.9 metrics backwards compatibility and warnings when set to default
2 parents 46a4ef7 + f916b72 commit adeabf2

File tree

8 files changed

+35
-10
lines changed

8 files changed

+35
-10
lines changed

agent/agent.go

+12
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,12 @@ func (a *Agent) Start(ctx context.Context) error {
598598
go a.retryJoinWAN()
599599
}
600600

601+
// DEPRECATED: Warn users if they're emitting deprecated metrics. Remove this warning and the flagged metrics in a
602+
// future release of Consul.
603+
if !a.config.Telemetry.DisableCompatOneNine {
604+
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.")
605+
}
606+
601607
return nil
602608
}
603609

@@ -3497,6 +3503,12 @@ func (a *Agent) ReloadConfig() error {
34973503
// breaking some existing behavior.
34983504
newCfg.NodeID = a.config.NodeID
34993505

3506+
// DEPRECATED: Warn users on reload if they're emitting deprecated metrics. Remove this warning and the flagged
3507+
// metrics in a future release of Consul.
3508+
if !a.config.Telemetry.DisableCompatOneNine {
3509+
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.")
3510+
}
3511+
35003512
return a.reloadConfigInternal(newCfg)
35013513
}
35023514

agent/config/builder.go

+1
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,7 @@ func (b *Builder) Build() (rt RuntimeConfig, err error) {
936936
CirconusCheckTags: b.stringVal(c.Telemetry.CirconusCheckTags),
937937
CirconusSubmissionInterval: b.stringVal(c.Telemetry.CirconusSubmissionInterval),
938938
CirconusSubmissionURL: b.stringVal(c.Telemetry.CirconusSubmissionURL),
939+
DisableCompatOneNine: b.boolVal(c.Telemetry.DisableCompatOneNine),
939940
DisableHostname: b.boolVal(c.Telemetry.DisableHostname),
940941
DogstatsdAddr: b.stringVal(c.Telemetry.DogstatsdAddr),
941942
DogstatsdTags: c.Telemetry.DogstatsdTags,

agent/config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ type Telemetry struct {
629629
CirconusCheckTags *string `json:"circonus_check_tags,omitempty" hcl:"circonus_check_tags" mapstructure:"circonus_check_tags"`
630630
CirconusSubmissionInterval *string `json:"circonus_submission_interval,omitempty" hcl:"circonus_submission_interval" mapstructure:"circonus_submission_interval"`
631631
CirconusSubmissionURL *string `json:"circonus_submission_url,omitempty" hcl:"circonus_submission_url" mapstructure:"circonus_submission_url"`
632+
DisableCompatOneNine *bool `json:"disable_compat_1.9,omitempty" hcl:"disable_compat_1.9" mapstructure:"disable_compat_1.9"`
632633
DisableHostname *bool `json:"disable_hostname,omitempty" hcl:"disable_hostname" mapstructure:"disable_hostname"`
633634
DogstatsdAddr *string `json:"dogstatsd_addr,omitempty" hcl:"dogstatsd_addr" mapstructure:"dogstatsd_addr"`
634635
DogstatsdTags []string `json:"dogstatsd_tags,omitempty" hcl:"dogstatsd_tags" mapstructure:"dogstatsd_tags"`

agent/config/default.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func DefaultSource() Source {
122122
telemetry = {
123123
metrics_prefix = "consul"
124124
filter_default = true
125-
prefix_filter = [ "-consul.api.http" ]
125+
prefix_filter = []
126126
}
127127
128128
`,

agent/config/runtime_test.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -2262,7 +2262,7 @@ func TestBuilder_BuildAndValidate_ConfigFlagsAndEdgecases(t *testing.T) {
22622262
patch: func(rt *RuntimeConfig) {
22632263
rt.DataDir = dataDir
22642264
rt.Telemetry.AllowedPrefixes = []string{"foo"}
2265-
rt.Telemetry.BlockedPrefixes = []string{"consul.api.http", "bar"}
2265+
rt.Telemetry.BlockedPrefixes = []string{"bar"}
22662266
},
22672267
warns: []string{`Filter rule must begin with either '+' or '-': "nix"`},
22682268
},
@@ -5434,7 +5434,8 @@ func TestFullConfig(t *testing.T) {
54345434
"metrics_prefix": "ftO6DySn",
54355435
"prometheus_retention_time": "15s",
54365436
"statsd_address": "drce87cy",
5437-
"statsite_address": "HpFwKB8R"
5437+
"statsite_address": "HpFwKB8R",
5438+
"disable_compat_1.9": true
54385439
},
54395440
"tls_cipher_suites": "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256",
54405441
"tls_min_version": "pAOWafkR",
@@ -6119,6 +6120,7 @@ func TestFullConfig(t *testing.T) {
61196120
prometheus_retention_time = "15s"
61206121
statsd_address = "drce87cy"
61216122
statsite_address = "HpFwKB8R"
6123+
disable_compat_1.9 = true
61226124
}
61236125
tls_cipher_suites = "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256"
61246126
tls_min_version = "pAOWafkR"
@@ -6890,12 +6892,13 @@ func TestFullConfig(t *testing.T) {
68906892
CirconusCheckTags: "prvO4uBl",
68916893
CirconusSubmissionInterval: "DolzaflP",
68926894
CirconusSubmissionURL: "gTcbS93G",
6895+
DisableCompatOneNine: true,
68936896
DisableHostname: true,
68946897
DogstatsdAddr: "0wSndumK",
68956898
DogstatsdTags: []string{"3N81zSUB", "Xtj8AnXZ"},
68966899
FilterDefault: true,
68976900
AllowedPrefixes: []string{"oJotS8XJ"},
6898-
BlockedPrefixes: []string{"consul.api.http", "cazlEhGn"},
6901+
BlockedPrefixes: []string{"cazlEhGn"},
68996902
MetricsPrefix: "ftO6DySn",
69006903
PrometheusRetentionTime: 15 * time.Second,
69016904
StatsdAddr: "drce87cy",
@@ -7589,6 +7592,7 @@ func TestSanitize(t *testing.T) {
75897592
"CirconusSubmissionInterval": "",
75907593
"CirconusSubmissionURL": "",
75917594
"Disable": false,
7595+
"DisableCompatOneNine": false,
75927596
"DisableHostname": false,
75937597
"DogstatsdAddr": "",
75947598
"DogstatsdTags": [],

agent/http.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,15 @@ func (s *HTTPHandlers) handler(enableDebug bool) http.Handler {
197197
start := time.Now()
198198
handler(resp, req)
199199

200-
// This new metric is disabled by default with the prefix_filter option.
201-
// It will be enabled by default in a future version.
202200
labels := []metrics.Label{{Name: "method", Value: req.Method}, {Name: "path", Value: path_label}}
203201
metrics.MeasureSinceWithLabels([]string{"api", "http"}, start, labels)
204202

205-
// Duplicated information. Kept for backward compatibility.
206-
key := append([]string{"http", req.Method}, parts...)
207-
metrics.MeasureSince(key, start)
203+
// DEPRECATED Emit pre-1.9 metric as `consul.http...` to maintain backwards compatibility. Enabled by
204+
// default. Users may set `telemetry { disable_compat_1.9 = true }`
205+
if !s.agent.config.Telemetry.DisableCompatOneNine {
206+
key := append([]string{"http", req.Method}, parts...)
207+
metrics.MeasureSince(key, start)
208+
}
208209
}
209210

210211
var gzipHandler http.Handler

lib/telemetry.go

+5
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ type TelemetryConfig struct {
132132
// hcl: telemetry { circonus_submission_url = string }
133133
CirconusSubmissionURL string `json:"circonus_submission_url,omitempty" mapstructure:"circonus_submission_url"`
134134

135+
// DisableCompatOneNine is a flag to stop emitting metrics that have been deprecated in version 1.9.
136+
//
137+
// hcl: telemetry { disable_compat_1.9 = (true|false) }
138+
DisableCompatOneNine bool `json:"disable_compat_1.9,omitempty" mapstructure:"disable_compat_1.9"`
139+
135140
// DisableHostname will disable hostname prefixing for all metrics.
136141
//
137142
// hcl: telemetry { disable_hostname = (true|false)

website/pages/docs/agent/telemetry.mdx

+2-1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ This is a full list of metrics emitted by Consul.
141141
| ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------- | ------- |
142142
| `consul.acl.blocked.service.registration` | This increments whenever a deregistration fails for a service (blocked by an ACL) | requests | counter |
143143
| `consul.acl.blocked..registration` | This increments whenever a registration fails for an entity (check, node or service) is blocked by an ACL | requests | counter |
144+
| `consul.api.http` | Migrated from consul.http.. this samples how long it takes to service the given HTTP request for the given verb and path. Includes labels for `path` and `method`. `path` does not include details like service or key names, for these an underscore will be present as a placeholder (eg. path=`v1.kv._`) | ms | timer |
144145
| `consul.client.rpc` | This increments whenever a Consul agent in client mode makes an RPC request to a Consul server. This gives a measure of how much a given agent is loading the Consul servers. Currently, this is only generated by agents in client mode, not Consul servers. | requests | counter |
145146
| `consul.client.rpc.exceeded` | This increments whenever a Consul agent in client mode makes an RPC request to a Consul server gets rate limited by that agent's [`limits`](/docs/agent/options#limits) configuration. This gives an indication that there's an abusive application making too many requests on the agent, or that the rate limit needs to be increased. Currently, this only applies to agents in client mode, not Consul servers. | rejected requests | counter |
146147
| `consul.client.rpc.failed` | This increments whenever a Consul agent in client mode makes an RPC request to a Consul server and fails. | requests | counter |
@@ -180,7 +181,7 @@ This is a full list of metrics emitted by Consul.
180181
| `consul.dns.stale_queries` | This increments when an agent serves a query within the allowed stale threshold. | queries | counter |
181182
| `consul.dns.ptr_query.` | This measures the time spent handling a reverse DNS query for the given node. | ms | timer |
182183
| `consul.dns.domain_query.` | This measures the time spent handling a domain query for the given node. | ms | timer |
183-
| `consul.http` | This tracks how long it takes to service the given HTTP request for the given verb and path. Paths do not include details like service or key names, for these an underscore will be present as a placeholder (eg. label `path=v1_kv_`) | ms | timer |
184+
| `consul.http...` | DEPRECATED IN 1.9: This tracks how long it takes to service the given HTTP request for the given verb and path. Paths do not include details like service or key names, for these an underscore will be present as a placeholder (eg. `consul.http.GET.v1.kv._`) | ms | timer |
184185

185186
## Server Health
186187

0 commit comments

Comments
 (0)