Permalink
Browse files
metrics: counter: return error for -ve inc
- Loading branch information...
Showing
with
4 additions
and
0 deletions.
-
+4
−0
metrics.go
|
|
@@ -617,6 +617,10 @@ func (c *PCPCounter) Set(val int64) error { |
|
|
|
|
|
// Inc increases the stored counter's value by the passed increment
|
|
|
func (c *PCPCounter) Inc(val int64) error {
|
|
|
+ if val < 0 {
|
|
|
+ return errors.New("cannot decrement a counter")
|
|
|
+ }
|
|
|
+
|
|
|
v := c.Val()
|
|
|
v += val
|
|
|
return c.Set(v)
|
|
|
|
0 comments on commit
7643da8