allow partial overrides of summary_options in mappings

Signed-off-by: glightfoot <glightfoot@rsglab.com>
This commit is contained in:
glightfoot 2021-01-28 11:11:55 -05:00
parent 38fdc17c42
commit 0ea986a974
3 changed files with 19 additions and 9 deletions

View file

@ -422,7 +422,7 @@ By setting this to `true`, `glob` match type will not honor the occurance of rul
Setting `buckets` or `quantiles` in the defaults is deprecated in favor of `histogram_options` and `summary_options`, which will override the deprecated values.
NOTE: If `summary_options` is present in a mapping config, it will override all of the `summary_options` set in the `defaults` section.
If `summary_options` is present in a mapping config, it will only override the fields set in the mapping. Unset fields in the mapping will take the values from the defaults.
```yaml
defaults:

View file

@ -22,8 +22,9 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
"github.com/prometheus/statsd_exporter/pkg/mapper/fsm"
yaml "gopkg.in/yaml.v2"
"github.com/prometheus/statsd_exporter/pkg/mapper/fsm"
)
var (
@ -100,7 +101,7 @@ func (m *MetricMapper) GetDefaultHistogramOptions() HistogramOptions {
r.Buckets = prometheus.DefBuckets
} else {
r = m.Defaults.HistogramOptions.Clone()
if m.Defaults.HistogramOptions != nil && len(m.Defaults.HistogramOptions.Buckets) == 0 {
if len(m.Defaults.HistogramOptions.Buckets) == 0 {
r.Buckets = prometheus.DefBuckets
}
}
@ -115,7 +116,7 @@ func (m *MetricMapper) GetDefaultSummaryOptions() SummaryOptions {
r.Quantiles = defaultQuantiles
} else {
r = m.Defaults.SummaryOptions.Clone()
if m.Defaults.SummaryOptions != nil && len(m.Defaults.SummaryOptions.Quantiles) == 0 {
if len(m.Defaults.SummaryOptions.Quantiles) == 0 {
r.Quantiles = defaultQuantiles
}
}

View file

@ -23,6 +23,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/prometheus/statsd_exporter/pkg/clock"
"github.com/prometheus/statsd_exporter/pkg/mapper"
"github.com/prometheus/statsd_exporter/pkg/metrics"
@ -300,11 +301,19 @@ func (r *Registry) GetSummary(metricName string, labels prometheus.Labels, help
metricsCount.WithLabelValues("summary").Inc()
summaryOptions := r.Mapper.GetDefaultSummaryOptions()
if mapping != nil && mapping.SummaryOptions != nil {
summaryOptions = *mapping.SummaryOptions
}
if mapping != nil && mapping.SummaryOptions != nil && len(mapping.SummaryOptions.Quantiles) > 0 {
summaryOptions.Quantiles = mapping.SummaryOptions.Quantiles
tmp := mapping.SummaryOptions.Clone()
if len(tmp.Quantiles) > 0 {
summaryOptions.Quantiles = tmp.Quantiles
}
if tmp.BufCap != 0 {
summaryOptions.BufCap = tmp.BufCap
}
if tmp.AgeBuckets != 0 {
summaryOptions.AgeBuckets = tmp.AgeBuckets
}
if tmp.MaxAge != 0 {
summaryOptions.MaxAge = tmp.MaxAge
}
}
objectives := make(map[float64]float64)