diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2015-01-29 03:05:08 +0100 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2015-01-29 03:05:08 +0100 |
commit | 558e2f4d87db733c1274586ba25a924acfcf5b63 (patch) | |
tree | dea95fbd1819ee7f46134f3a4d5a1d8fbfeb287a /kamon-core/src/main/scala/kamon/metric | |
parent | 0a8cf25a114d27250e1ebd68db70407a9ef73cc5 (diff) | |
download | Kamon-558e2f4d87db733c1274586ba25a924acfcf5b63.tar.gz Kamon-558e2f4d87db733c1274586ba25a924acfcf5b63.tar.bz2 Kamon-558e2f4d87db733c1274586ba25a924acfcf5b63.zip |
= core: protect against negative values on diff gauges recordings.
Diffstat (limited to 'kamon-core/src/main/scala/kamon/metric')
-rw-r--r-- | kamon-core/src/main/scala/kamon/metric/instrument/Gauge.scala | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/kamon-core/src/main/scala/kamon/metric/instrument/Gauge.scala b/kamon-core/src/main/scala/kamon/metric/instrument/Gauge.scala index ea5a9b41..d711867e 100644 --- a/kamon-core/src/main/scala/kamon/metric/instrument/Gauge.scala +++ b/kamon-core/src/main/scala/kamon/metric/instrument/Gauge.scala @@ -56,11 +56,14 @@ class DifferentialValueCollector(wrappedValueCollector: CurrentValueCollector) e def currentValue: Long = { if (_readAtLeastOnce) { val wrappedCurrent = wrappedValueCollector.currentValue - wrappedCurrent - _lastObservedValue.getAndSet(wrappedCurrent) + val diff = wrappedCurrent - _lastObservedValue.getAndSet(wrappedCurrent) + + if(diff >= 0) diff else 0L + } else { _lastObservedValue.set(wrappedValueCollector.currentValue) _readAtLeastOnce = true - 0 + 0L } } |