Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use method and path as labels for http metrics #8271

Merged
merged 4 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions agent/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func DefaultSource() Source {
telemetry = {
metrics_prefix = "consul"
filter_default = true
prefix_filter = [ "-consul.api.http" ]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added it here, please tell me if it should be added elsewhere.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be correct. I'll need to double check. A comment explaining why this is disabled by default would be great. Something about it being a new metric and will be enabled by default in a future version.

}

`,
Expand Down
4 changes: 2 additions & 2 deletions agent/config/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2263,7 +2263,7 @@ func TestConfigFlagsAndEdgecases(t *testing.T) {
patch: func(rt *RuntimeConfig) {
rt.DataDir = dataDir
rt.Telemetry.AllowedPrefixes = []string{"foo"}
rt.Telemetry.BlockedPrefixes = []string{"bar"}
rt.Telemetry.BlockedPrefixes = []string{"consul.api.http", "bar"}
},
warns: []string{`Filter rule must begin with either '+' or '-': "nix"`},
},
Expand Down Expand Up @@ -6361,7 +6361,7 @@ func TestFullConfig(t *testing.T) {
DogstatsdTags: []string{"3N81zSUB", "Xtj8AnXZ"},
FilterDefault: true,
AllowedPrefixes: []string{"oJotS8XJ"},
BlockedPrefixes: []string{"cazlEhGn"},
BlockedPrefixes: []string{"consul.api.http", "cazlEhGn"},
MetricsPrefix: "ftO6DySn",
PrometheusRetentionTime: 15 * time.Second,
StatsdAddr: "drce87cy",
Expand Down
17 changes: 14 additions & 3 deletions agent/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,23 @@ func (s *HTTPServer) handler(enableDebug bool) http.Handler {
parts = append(parts, part)
}

// Register the wrapper, which will close over the expensive-to-compute
// parts from above.
// TODO (kyhavlov): Convert this to utilize metric labels in a major release
// Tranform the pattern to a valid label by replacing the '/' by '_'.
// Omit the leading slash.
// Distinguish thing like /v1/query from /v1/query/<query_id> by having
// an extra underscore.
path_label := strings.Replace(pattern[1:], "/", "_", -1)

// Register the wrapper.
wrapper := func(resp http.ResponseWriter, req *http.Request) {
start := time.Now()
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}}
metrics.MeasureSinceWithLabels([]string{"api", "http"}, start, labels)

// Duplicated information. Kept for backward compatibility.
key := append([]string{"http", req.Method}, parts...)
metrics.MeasureSince(key, start)
}
Expand Down
2 changes: 1 addition & 1 deletion website/pages/docs/agent/telemetry.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ This is a full list of metrics emitted by Consul.
| `consul.dns.stale_queries` | This increments when an agent serves a query within the allowed stale threshold. | queries | counter |
| `consul.dns.ptr_query.` | This measures the time spent handling a reverse DNS query for the given node. | ms | timer |
| `consul.dns.domain_query.` | This measures the time spent handling a domain query for the given node. | ms | timer |
| `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. `consul.http.GET.v1.kv._`) | ms | timer |
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I leave this line in the documentation since both metrics are sent?

| `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 |

## Server Health

Expand Down