Skip to content

Commit 1005d6d

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 ee80eab commit 1005d6d

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
@@ -814,7 +814,7 @@ func (c *Counter) Inc(v int64) {
814814
// maintained elsewhere.
815815
func (c *Counter) Update(val int64) {
816816
if buildutil.CrdbTestBuild {
817-
if prev := c.count.Load(); val < prev {
817+
if prev := c.count.Load(); val < prev && val != 0 {
818818
panic(fmt.Sprintf("Counters should not decrease, prev: %d, new: %d.", prev, val))
819819
}
820820
}
@@ -1435,7 +1435,7 @@ func (cv *CounterVec) Update(labels map[string]string, v int64) {
14351435
}
14361436

14371437
currentValue := cv.Count(labels)
1438-
if currentValue > v {
1438+
if currentValue > v && v != 0 {
14391439
panic(fmt.Sprintf("Counters should not decrease, prev: %d, new: %d.", currentValue, v))
14401440
}
14411441

0 commit comments

Comments
 (0)