aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Topolnjak <ivantopo@gmail.com>2016-04-01 13:20:20 +0200
committerIvan Topolnjak <ivantopo@gmail.com>2016-04-01 13:20:20 +0200
commit25a51121f1dd155a043fc60006e789c5e1676a8d (patch)
treeb6f625040a5a1422f068fef28410a713ef35f407
parent0d793ffbf2af4b3a8d96de9d9c9edc7bd5b2af97 (diff)
downloadKamon-25a51121f1dd155a043fc60006e789c5e1676a8d.tar.gz
Kamon-25a51121f1dd155a043fc60006e789c5e1676a8d.tar.bz2
Kamon-25a51121f1dd155a043fc60006e789c5e1676a8d.zip
core: catch any exception being thrown when recording values on histograms
fixes #232, fixes #332
-rw-r--r--kamon-core/src/main/scala/kamon/metric/instrument/Histogram.scala19
-rw-r--r--kamon-core/src/test/scala/kamon/metric/instrument/HistogramSpec.scala6
2 files changed, 19 insertions, 6 deletions
diff --git a/kamon-core/src/main/scala/kamon/metric/instrument/Histogram.scala b/kamon-core/src/main/scala/kamon/metric/instrument/Histogram.scala
index dc9a4bbf..77cb503b 100644
--- a/kamon-core/src/main/scala/kamon/metric/instrument/Histogram.scala
+++ b/kamon-core/src/main/scala/kamon/metric/instrument/Histogram.scala
@@ -20,6 +20,7 @@ import java.nio.LongBuffer
import kamon.metric.instrument.Histogram.{ DynamicRange, Snapshot }
import org.HdrHistogram.ModifiedAtomicHistogram
+import org.slf4j.LoggerFactory
trait Histogram extends Instrument {
type SnapshotType = Histogram.Snapshot
@@ -135,6 +136,10 @@ object Histogram {
}
}
+object HdrHistogram {
+ private val log = LoggerFactory.getLogger(classOf[HdrHistogram])
+}
+
/**
* This implementation is meant to be used for real time data collection where data snapshots are taken often over time.
* The collect(..) operation extracts all the recorded values from the histogram and resets the counts, but still
@@ -142,10 +147,20 @@ object Histogram {
*/
class HdrHistogram(dynamicRange: DynamicRange) extends ModifiedAtomicHistogram(dynamicRange.lowestDiscernibleValue,
dynamicRange.highestTrackableValue, dynamicRange.precision) with Histogram {
+ import HdrHistogram.log
+
+ def record(value: Long): Unit = tryRecord(value, 1L)
- def record(value: Long): Unit = recordValue(value)
+ def record(value: Long, count: Long): Unit = tryRecord(value, count)
- def record(value: Long, count: Long): Unit = recordValueWithCount(value, count)
+ private def tryRecord(value: Long, count: Long): Unit = {
+ try {
+ recordValueWithCount(value, count)
+ } catch {
+ case anyException: Throwable ⇒
+ log.warn("Failed to store value {} in HdrHistogram, please review your range configuration.")
+ }
+ }
def collect(context: CollectionContext): Histogram.Snapshot = {
import context.buffer
diff --git a/kamon-core/src/test/scala/kamon/metric/instrument/HistogramSpec.scala b/kamon-core/src/test/scala/kamon/metric/instrument/HistogramSpec.scala
index adfcd826..dd60fee1 100644
--- a/kamon-core/src/test/scala/kamon/metric/instrument/HistogramSpec.scala
+++ b/kamon-core/src/test/scala/kamon/metric/instrument/HistogramSpec.scala
@@ -32,10 +32,8 @@ class HistogramSpec extends WordSpec with Matchers {
histogram.record(10000)
}
- "fail when recording values higher than the highest trackable value" in new HistogramFixture {
- intercept[IndexOutOfBoundsException] {
- histogram.record(1000000)
- }
+ "not fail when recording values higher than the highest trackable value" in new HistogramFixture {
+ histogram.record(Long.MaxValue)
}
"reset all recorded levels to zero after a snapshot collection" in new HistogramFixture {