Use +Inf label additionally for Histogram metrics (#18807)

This commit is contained in:
Shubhendu 2024-01-19 04:21:28 +05:30 committed by GitHub
parent 7c0673279b
commit 19387cafab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View file

@ -20,6 +20,7 @@ package cmd
import (
"context"
"fmt"
"math"
"net/http"
"runtime"
"strconv"
@ -1715,6 +1716,17 @@ func getHistogramMetrics(hist *prometheus.HistogramVec, desc MetricDescription)
}
metrics = append(metrics, metric)
}
// add metrics with +Inf label
labels1 := make(map[string]string)
for _, lp := range dtoMetric.GetLabel() {
labels1[*lp.Name] = *lp.Value
}
labels1["le"] = fmt.Sprintf("%.3f", math.Inf(+1))
metrics = append(metrics, Metric{
Description: desc,
VariableLabels: labels1,
Value: dtoMetric.Counter.GetValue(),
})
}
return metrics
}

View file

@ -81,7 +81,8 @@ func TestGetHistogramMetrics(t *testing.T) {
}
metrics := getHistogramMetrics(ttfbHist, getBucketTTFBDistributionMD())
if expPoints := len(labels) * len(histBuckets); expPoints != len(metrics) {
// additional labels for +Inf for all histogram metrics
if expPoints := len(labels) * (len(histBuckets) + 1); expPoints != len(metrics) {
t.Fatalf("Expected %v data points but got %v", expPoints, len(metrics))
}
}