Skip to content

Commit

Permalink
Add native histograms to the main latency histogram metrics
Browse files Browse the repository at this point in the history
This help downstream projects like Mimir transition to using native
histograms.
Ref: grafana/mimir#5020

Signed-off-by: György Krajcsovits <[email protected]>
  • Loading branch information
krajorama committed Mar 1, 2024
1 parent b073df3 commit de89e8b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cache/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ func newClientMetrics(reg prometheus.Registerer) *clientMetrics {
Name: "operation_duration_seconds",
Help: "Duration of operations against cache.",
Buckets: []float64{0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.2, 0.5, 1, 3, 6, 10},
// Use defaults recommended by Prometheus for native histograms.
NativeHistogramBucketFactor: 1.1,
NativeHistogramMaxBucketNumber: 100,
NativeHistogramMinResetDuration: time.Hour,
}, []string{"operation"})
cm.duration.WithLabelValues(opGetMulti)
cm.duration.WithLabelValues(opSet)
Expand Down
4 changes: 4 additions & 0 deletions gate/gate.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ func NewInstrumented(reg prometheus.Registerer, maxConcurrent int, gate Gate) Ga
Name: "gate_duration_seconds",
Help: "How many seconds it took for queries to wait at the gate.",
Buckets: []float64{0.01, 0.1, 0.3, 0.6, 1, 3, 6, 9, 20, 30, 60, 90, 120, 240, 360, 720},
// Use defaults recommended by Prometheus for native histograms.
NativeHistogramBucketFactor: 1.1,
NativeHistogramMaxBucketNumber: 100,
NativeHistogramMinResetDuration: time.Hour,
}),
}

Expand Down
5 changes: 5 additions & 0 deletions kv/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kv
import (
"context"
"strconv"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
Expand Down Expand Up @@ -53,6 +54,10 @@ func newMetricsClient(backend string, c Client, reg prometheus.Registerer) Clien
Name: "kv_request_duration_seconds",
Help: "Time spent on kv store requests.",
Buckets: prometheus.DefBuckets,
// Use defaults recommended by Prometheus for native histograms.
NativeHistogramBucketFactor: 1.1,
NativeHistogramMaxBucketNumber: 100,
NativeHistogramMinResetDuration: time.Hour,
ConstLabels: prometheus.Labels{
"type": backend,
},
Expand Down

0 comments on commit de89e8b

Please sign in to comment.