diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2014-12-04 03:20:41 +0100 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2014-12-04 03:20:41 +0100 |
commit | 0858ddfc94853e603975712c16f6945c01288f9a (patch) | |
tree | 277f96a67593d6d6a55e9e5c3e5fb7cdca90778a /kamon-core/src/main/scala/kamon/trace/Sampler.scala | |
parent | b0077e7f5571a0055b36ddd25e9440163083eb32 (diff) | |
download | Kamon-0858ddfc94853e603975712c16f6945c01288f9a.tar.gz Kamon-0858ddfc94853e603975712c16f6945c01288f9a.tar.bz2 Kamon-0858ddfc94853e603975712c16f6945c01288f9a.zip |
+ core: cleanup the simple trace implementation
Diffstat (limited to 'kamon-core/src/main/scala/kamon/trace/Sampler.scala')
-rw-r--r-- | kamon-core/src/main/scala/kamon/trace/Sampler.scala | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/kamon-core/src/main/scala/kamon/trace/Sampler.scala b/kamon-core/src/main/scala/kamon/trace/Sampler.scala index 60a400f8..650592a5 100644 --- a/kamon-core/src/main/scala/kamon/trace/Sampler.scala +++ b/kamon-core/src/main/scala/kamon/trace/Sampler.scala @@ -2,21 +2,22 @@ package kamon.trace import java.util.concurrent.atomic.AtomicLong +import kamon.NanoInterval import scala.concurrent.forkjoin.ThreadLocalRandom trait Sampler { def shouldTrace: Boolean - def shouldReport(traceElapsedNanoTime: Long): Boolean + def shouldReport(traceElapsedTime: NanoInterval): Boolean } object NoSampling extends Sampler { def shouldTrace: Boolean = false - def shouldReport(traceElapsedNanoTime: Long): Boolean = false + def shouldReport(traceElapsedTime: NanoInterval): Boolean = false } object SampleAll extends Sampler { def shouldTrace: Boolean = true - def shouldReport(traceElapsedNanoTime: Long): Boolean = true + def shouldReport(traceElapsedTime: NanoInterval): Boolean = true } class RandomSampler(chance: Int) extends Sampler { @@ -24,7 +25,7 @@ class RandomSampler(chance: Int) extends Sampler { require(chance <= 100, "kamon.trace.random-sampler.chance cannot be > 100") def shouldTrace: Boolean = ThreadLocalRandom.current().nextInt(100) <= chance - def shouldReport(traceElapsedNanoTime: Long): Boolean = true + def shouldReport(traceElapsedTime: NanoInterval): Boolean = true } class OrderedSampler(interval: Int) extends Sampler { @@ -33,13 +34,13 @@ class OrderedSampler(interval: Int) extends Sampler { private val counter = new AtomicLong(0L) def shouldTrace: Boolean = counter.incrementAndGet() % interval == 0 // TODO: find a more efficient way to do this, protect from long overflow. - def shouldReport(traceElapsedNanoTime: Long): Boolean = true + def shouldReport(traceElapsedTime: NanoInterval): Boolean = true } class ThresholdSampler(thresholdInNanoseconds: Long) extends Sampler { require(thresholdInNanoseconds > 0, "kamon.trace.threshold-sampler.minimum-elapsed-time cannot be <= 0") def shouldTrace: Boolean = true - def shouldReport(traceElapsedNanoTime: Long): Boolean = traceElapsedNanoTime >= thresholdInNanoseconds + def shouldReport(traceElapsedTime: NanoInterval): Boolean = traceElapsedTime.nanos >= thresholdInNanoseconds } |