Skip to content

Commit

Permalink
metric: use cumulative count instead of windowed count in tsdb
Browse files Browse the repository at this point in the history
Previously, we were writing the windowed count of a histogram into tsdb.
This meant that on each tick, the count reset. This is useful for
calculating averages and quantiles using windowed histograms, but makes
little sense to record for `count`.

This patch now uses the cumulative count in tsdb.

Informs cockroachdb#98745

Release note (bug fix): Timeseries metric counts will now show
cumulative counts for a histogram rather than the windowed count.
  • Loading branch information
aadityasondhi committed Apr 20, 2023
1 parent d2e36ef commit 0d3faff
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/server/status/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,9 @@ type registryRecorder struct {
func extractValue(name string, mtr interface{}, fn func(string, float64)) error {
switch mtr := mtr.(type) {
case metric.WindowedHistogram:
// Use cumulative count here
fn(name+"-count", float64(mtr.(*metric.Histogram).TotalCount()))
n := float64(mtr.TotalCountWindowed())
fn(name+"-count", n)
avg := mtr.TotalSumWindowed() / n
if math.IsNaN(avg) || math.IsInf(avg, +1) || math.IsInf(avg, -1) {
avg = 0
Expand Down

0 comments on commit 0d3faff

Please sign in to comment.