Skip to content

Commit f969221

Browse files
committed
metric: permit counter resets in update assertion
When we call `Update` on counter metrics, we have an assertion that panics in tests if the counter is set to a lower value than the prior update. In practice, counters are permitted to reset and 3rd party metric systems expect this to happen occasionally. The assertion logic is adjusted to permit a setting of zero when the value is lower. Resolves: #154364 Resolves: #154365 Resolves: #154366 Resolves: #154367 Resolves: #154368 Epic: None Release note: None
1 parent 52aaf2e commit f969221

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

pkg/util/metric/metric.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ func (c *Counter) Inc(v int64) {
825825
// maintained elsewhere.
826826
func (c *Counter) Update(val int64) {
827827
if buildutil.CrdbTestBuild {
828-
if prev := c.count.Load(); val < prev {
828+
if prev := c.count.Load(); val < prev && val != 0 {
829829
panic(fmt.Sprintf("Counters should not decrease, prev: %d, new: %d.", prev, val))
830830
}
831831
}
@@ -1446,7 +1446,7 @@ func (cv *CounterVec) Update(labels map[string]string, v int64) {
14461446
}
14471447

14481448
currentValue := cv.Count(labels)
1449-
if currentValue > v {
1449+
if currentValue > v && v != 0 {
14501450
panic(fmt.Sprintf("Counters should not decrease, prev: %d, new: %d.", currentValue, v))
14511451
}
14521452

0 commit comments

Comments
 (0)