Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

providers/prometheus: Add WithHistogramOpts for native histograms #584

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions providers/prometheus/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ func WithHistogramBuckets(buckets []float64) HistogramOption {
return func(o *prometheus.HistogramOpts) { o.Buckets = buckets }
}

// WithHistogramOpts allows you to specify HistogramOpts but makes sure the correct name and label is used.
// This function is helpful when specifying more than just the buckets, like using NativeHistograms.
func WithHistogramOpts(opts *prometheus.HistogramOpts) HistogramOption {
// TODO: This isn't ideal either if new fields are added to prometheus.HistogramOpts.
// Maybe we can change the interface to accept abitrary HistogramOpts and
// only make sure to overwrite the necessary fields (name, labels).
return func(o *prometheus.HistogramOpts) {
o.Buckets = opts.Buckets
o.NativeHistogramBucketFactor = opts.NativeHistogramBucketFactor
o.NativeHistogramZeroThreshold = opts.NativeHistogramZeroThreshold
o.NativeHistogramMaxBucketNumber = opts.NativeHistogramMaxBucketNumber
o.NativeHistogramMinResetDuration = opts.NativeHistogramMinResetDuration
o.NativeHistogramMaxZeroThreshold = opts.NativeHistogramMaxZeroThreshold
}
}

// WithHistogramConstLabels allows you to add custom ConstLabels to
// histograms metrics.
func WithHistogramConstLabels(labels prometheus.Labels) HistogramOption {
Expand Down