Skip to content

Commit

Permalink
metric: export quantiles from prometheus-based histogram
Browse files Browse the repository at this point in the history
This change builds on the previous one and adds a function to export
quantiles from the Prometheus-based histogram. This functionality is
used to store histogram data in the internal timeseries database. The
hdr library came with a function to do this, while Prometheus does not
have a public API for exporting quantiles.

The function implemented here is very similar to the one found
internally in Prometheus, using linear interpolation to calculate values
at a given quantile.

This commit also includes some additional testing and general
refactoring of the metrics code.

Release note: None

Release justification:
  • Loading branch information
aadityasondhi committed Aug 26, 2022
1 parent 25e708a commit 02210c1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/util/metric/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,11 @@ func (h *HistogramV2) ToPrometheusMetricWindowed() *prometheusgo.Metric {
defer h.windowed.Unlock()
m := &prometheusgo.Metric{}
if err := h.windowed.cur.Write(m); err != nil {
<<<<<<< HEAD
panic(err)
=======
panic(err) // TODD
>>>>>>> 5658e48493 (metric: export quantiles from prometheus-based histogram)
}
return m
}
Expand Down Expand Up @@ -563,10 +567,13 @@ func (h *HistogramV2) ValueAtQuantileWindowed(q float64) float64 {
if math.IsNaN(val) || math.IsInf(val, -1) {
return 0
}
<<<<<<< HEAD
// should not extrapolate past the upper bound of the largest bucket
if val > *buckets[len(buckets)-1].UpperBound {
return *buckets[len(buckets)-1].UpperBound
}
=======
>>>>>>> 5658e48493 (metric: export quantiles from prometheus-based histogram)
return val
}

Expand Down

0 comments on commit 02210c1

Please sign in to comment.