From 5ee349e075f7b3ba2cbc7f3a235fd2ce3b8a7151 Mon Sep 17 00:00:00 2001 From: Maisem Ali Date: Thu, 7 Sep 2023 14:47:21 -0700 Subject: [PATCH] tsweb/varz: fix exporting histograms Updates tailscale/corp#8641 Signed-off-by: Maisem Ali --- tsweb/varz/varz.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tsweb/varz/varz.go b/tsweb/varz/varz.go index 858bbcc3d..c24873fc5 100644 --- a/tsweb/varz/varz.go +++ b/tsweb/varz/varz.go @@ -31,13 +31,14 @@ func init() { } const ( - gaugePrefix = "gauge_" - counterPrefix = "counter_" - labelMapPrefix = "labelmap_" + gaugePrefix = "gauge_" + counterPrefix = "counter_" + labelMapPrefix = "labelmap_" + histogramPrefix = "histogram_" ) // prefixesToTrim contains key prefixes to remove when exporting and sorting metrics. -var prefixesToTrim = []string{gaugePrefix, counterPrefix, labelMapPrefix} +var prefixesToTrim = []string{gaugePrefix, counterPrefix, labelMapPrefix, histogramPrefix} var timeStart = time.Now() @@ -71,10 +72,12 @@ func prometheusMetric(prefix string, key string) (string, string, string) { case strings.HasPrefix(key, gaugePrefix): typ = "gauge" key = strings.TrimPrefix(key, gaugePrefix) - case strings.HasPrefix(key, counterPrefix): typ = "counter" key = strings.TrimPrefix(key, counterPrefix) + case strings.HasPrefix(key, histogramPrefix): + typ = "histogram" + key = strings.TrimPrefix(key, histogramPrefix) } if strings.HasPrefix(key, labelMapPrefix) { key = strings.TrimPrefix(key, labelMapPrefix)