Fix prometheus histogram and summary merging (#6756)

This commit is contained in:
Daniel Nelson
2019-12-04 13:41:33 -08:00
committed by GitHub
parent 48f9f22f33
commit eeb4690686
2 changed files with 253 additions and 3 deletions

View File

@@ -52,12 +52,32 @@ type Histogram struct {
Sum float64
}
func (h *Histogram) merge(b Bucket) {
for i := range h.Buckets {
if h.Buckets[i].Bound == b.Bound {
h.Buckets[i].Count = b.Count
return
}
}
h.Buckets = append(h.Buckets, b)
}
type Summary struct {
Quantiles []Quantile
Count uint64
Sum float64
}
func (s *Summary) merge(q Quantile) {
for i := range s.Quantiles {
if s.Quantiles[i].Quantile == q.Quantile {
s.Quantiles[i].Value = q.Value
return
}
}
s.Quantiles = append(s.Quantiles, q)
}
type MetricKey uint64
func MakeMetricKey(labels []LabelPair) MetricKey {
@@ -210,7 +230,6 @@ func (c *Collection) Add(metric telegraf.Metric) {
Scaler: &Scaler{Value: value},
}
// what if already here
entry.Metrics[metricKey] = m
case telegraf.Histogram:
if m == nil {
@@ -236,7 +255,7 @@ func (c *Collection) Add(metric telegraf.Metric) {
continue
}
m.Histogram.Buckets = append(m.Histogram.Buckets, Bucket{
m.Histogram.merge(Bucket{
Bound: bound,
Count: count,
})
@@ -297,7 +316,7 @@ func (c *Collection) Add(metric telegraf.Metric) {
continue
}
m.Summary.Quantiles = append(m.Summary.Quantiles, Quantile{
m.Summary.merge(Quantile{
Quantile: quantile,
Value: value,
})