Allow creation of native histograms

Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>
This commit is contained in:
Pedro Tanaka 2022-11-11 16:02:13 +01:00
parent fbfa209c87
commit f77011fd34
No known key found for this signature in database
GPG key ID: D0D8389DA4EE060B
2 changed files with 24 additions and 4 deletions

View file

@ -65,6 +65,8 @@ type SummaryOptions struct {
type HistogramOptions struct {
Buckets []float64 `yaml:"buckets"`
NativeHistogramBucketFactor float64 `yaml:"native_histogram_bucket_factor"`
NativeHistogramMaxBuckets uint32 `yaml:"native_histogram_max_buckets"`
}
type metricObjective struct {
@ -88,6 +90,12 @@ func (m *MetricMapper) InitFromYAMLString(fileContents string) error {
if len(n.Defaults.HistogramOptions.Buckets) == 0 {
n.Defaults.HistogramOptions.Buckets = prometheus.DefBuckets
}
if n.Defaults.HistogramOptions.NativeHistogramBucketFactor == 0 {
n.Defaults.HistogramOptions.NativeHistogramBucketFactor = 1.1
}
if n.Defaults.HistogramOptions.NativeHistogramMaxBuckets <= 0 {
n.Defaults.HistogramOptions.NativeHistogramMaxBuckets = 256
}
if len(n.Defaults.SummaryOptions.Quantiles) == 0 {
n.Defaults.SummaryOptions.Quantiles = defaultQuantiles

View file

@ -274,10 +274,22 @@ func (r *Registry) GetHistogram(metricName string, labels prometheus.Labels, hel
if mapping.HistogramOptions != nil && len(mapping.HistogramOptions.Buckets) > 0 {
buckets = mapping.HistogramOptions.Buckets
}
bucketFactor := r.Mapper.Defaults.HistogramOptions.NativeHistogramBucketFactor
if mapping.HistogramOptions != nil && mapping.HistogramOptions.NativeHistogramBucketFactor > 0 {
bucketFactor = mapping.HistogramOptions.NativeHistogramBucketFactor
}
maxBuckets := r.Mapper.Defaults.HistogramOptions.NativeHistogramMaxBuckets
if mapping.HistogramOptions != nil && mapping.HistogramOptions.NativeHistogramMaxBuckets > 0 {
maxBuckets = mapping.HistogramOptions.NativeHistogramMaxBuckets
}
histogramVec = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: metricName,
Help: help,
Buckets: buckets,
NativeHistogramBucketFactor: bucketFactor,
NativeHistogramMaxBucketNumber: maxBuckets,
}, labelNames)
if err := r.Registerer.Register(uncheckedCollector{histogramVec}); err != nil {