diff options
author | Péter Szilágyi <peterke@gmail.com> | 2019-09-10 19:39:07 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2019-09-10 19:39:07 +0800 |
commit | 72d5a27a397f4397082df91dd1650251e828a251 (patch) | |
tree | e43b537e3eb5560b40a1ead4df44282fcfa3a996 /metrics | |
parent | 4f6bf2f1c56c0a44455036dda11d5b186962f8ab (diff) | |
download | go-tangerine-72d5a27a397f4397082df91dd1650251e828a251.tar go-tangerine-72d5a27a397f4397082df91dd1650251e828a251.tar.gz go-tangerine-72d5a27a397f4397082df91dd1650251e828a251.tar.bz2 go-tangerine-72d5a27a397f4397082df91dd1650251e828a251.tar.lz go-tangerine-72d5a27a397f4397082df91dd1650251e828a251.tar.xz go-tangerine-72d5a27a397f4397082df91dd1650251e828a251.tar.zst go-tangerine-72d5a27a397f4397082df91dd1650251e828a251.zip |
core, metrics, p2p: switch some invalid counters to gauges
Diffstat (limited to 'metrics')
-rw-r--r-- | metrics/gauge.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/metrics/gauge.go b/metrics/gauge.go index 0fbfdb860..b6b2758b0 100644 --- a/metrics/gauge.go +++ b/metrics/gauge.go @@ -6,6 +6,8 @@ import "sync/atomic" type Gauge interface { Snapshot() Gauge Update(int64) + Dec(int64) + Inc(int64) Value() int64 } @@ -65,6 +67,16 @@ func (GaugeSnapshot) Update(int64) { panic("Update called on a GaugeSnapshot") } +// Dec panics. +func (GaugeSnapshot) Dec(int64) { + panic("Dec called on a GaugeSnapshot") +} + +// Inc panics. +func (GaugeSnapshot) Inc(int64) { + panic("Inc called on a GaugeSnapshot") +} + // Value returns the value at the time the snapshot was taken. func (g GaugeSnapshot) Value() int64 { return int64(g) } @@ -77,6 +89,12 @@ func (NilGauge) Snapshot() Gauge { return NilGauge{} } // Update is a no-op. func (NilGauge) Update(v int64) {} +// Dec is a no-op. +func (NilGauge) Dec(i int64) {} + +// Inc is a no-op. +func (NilGauge) Inc(i int64) {} + // Value is a no-op. func (NilGauge) Value() int64 { return 0 } @@ -101,6 +119,16 @@ func (g *StandardGauge) Value() int64 { return atomic.LoadInt64(&g.value) } +// Dec decrements the gauge's current value by the given amount. +func (g *StandardGauge) Dec(i int64) { + atomic.AddInt64(&g.value, -i) +} + +// Inc increments the gauge's current value by the given amount. +func (g *StandardGauge) Inc(i int64) { + atomic.AddInt64(&g.value, i) +} + // FunctionalGauge returns value from given function type FunctionalGauge struct { value func() int64 @@ -118,3 +146,13 @@ func (g FunctionalGauge) Snapshot() Gauge { return GaugeSnapshot(g.Value()) } func (FunctionalGauge) Update(int64) { panic("Update called on a FunctionalGauge") } + +// Dec panics. +func (FunctionalGauge) Dec(int64) { + panic("Dec called on a FunctionalGauge") +} + +// Inc panics. +func (FunctionalGauge) Inc(int64) { + panic("Inc called on a FunctionalGauge") +} |