Skip to content

Commit 32ae386

Browse files
authored
providers/prometheus: Add WithHistogramOpts for native histograms (#584)
We need to be able to set the NativeHistogramBucketFactor for example to enable native histograms. Therefore, the `WithHistogramBuckets` Option isn't flexible enough anymore. I've added the `WithHistogramOpts` option. Signed-off-by: Matthias Loibl <[email protected]>
1 parent a689ca8 commit 32ae386

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

providers/prometheus/options.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ func WithHistogramBuckets(buckets []float64) HistogramOption {
5353
return func(o *prometheus.HistogramOpts) { o.Buckets = buckets }
5454
}
5555

56+
// WithHistogramOpts allows you to specify HistogramOpts but makes sure the correct name and label is used.
57+
// This function is helpful when specifying more than just the buckets, like using NativeHistograms.
58+
func WithHistogramOpts(opts *prometheus.HistogramOpts) HistogramOption {
59+
// TODO: This isn't ideal either if new fields are added to prometheus.HistogramOpts.
60+
// Maybe we can change the interface to accept abitrary HistogramOpts and
61+
// only make sure to overwrite the necessary fields (name, labels).
62+
return func(o *prometheus.HistogramOpts) {
63+
o.Buckets = opts.Buckets
64+
o.NativeHistogramBucketFactor = opts.NativeHistogramBucketFactor
65+
o.NativeHistogramZeroThreshold = opts.NativeHistogramZeroThreshold
66+
o.NativeHistogramMaxBucketNumber = opts.NativeHistogramMaxBucketNumber
67+
o.NativeHistogramMinResetDuration = opts.NativeHistogramMinResetDuration
68+
o.NativeHistogramMaxZeroThreshold = opts.NativeHistogramMaxZeroThreshold
69+
}
70+
}
71+
5672
// WithHistogramConstLabels allows you to add custom ConstLabels to
5773
// histograms metrics.
5874
func WithHistogramConstLabels(labels prometheus.Labels) HistogramOption {

0 commit comments

Comments
 (0)