From 84661043035f3af3b1e14b92489c5e162734dca0 Mon Sep 17 00:00:00 2001 From: greyireland Date: Tue, 7 Feb 2023 15:00:56 +0800 Subject: [PATCH] add inf --- histogram.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/histogram.go b/histogram.go index 5c7a80b..c98eb39 100644 --- a/histogram.go +++ b/histogram.go @@ -233,11 +233,15 @@ func (h *Histogram) marshalTo(prefix string, w io.Writer) { } func (h *Histogram) marshalToPrometheus(prefix string, w io.Writer) { countTotal := uint64(0) + inf := false h.VisitNonZeroBuckets(func(vmrange string, count uint64) { v := strings.Split(vmrange, "...") if len(v) != 2 { return } + if v[1] == "+Inf" { + inf = true + } tag := fmt.Sprintf("le=%q", v[1]) metricName := addTag(prefix, tag) name, labels := splitMetricName(metricName) @@ -247,6 +251,12 @@ func (h *Histogram) marshalToPrometheus(prefix string, w io.Writer) { if countTotal == 0 { return } + if !inf { + tag := fmt.Sprintf("le=%q", "+Inf") + metricName := addTag(prefix, tag) + name, labels := splitMetricName(metricName) + fmt.Fprintf(w, "%s_bucket%s %d\n", name, labels, countTotal) + } name, labels := splitMetricName(prefix) sum := h.getSum() if float64(int64(sum)) == sum {