diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2015-07-21 14:23:54 +0200 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2015-07-21 14:23:54 +0200 |
commit | a9dc9a9879dc04b39911ce4d7971775403e05695 (patch) | |
tree | 71453fc02d5ee2c4f927b7fce94b670712ddcb1c /kamon-core/src/main/scala/kamon/trace/Sampler.scala | |
parent | c85c28d8c1b12b3d35cfc6dca628e72115db49f3 (diff) | |
parent | 02e18a1186f9b0dd9a7133ff30aa73774822db13 (diff) | |
download | Kamon-a9dc9a9879dc04b39911ce4d7971775403e05695.tar.gz Kamon-a9dc9a9879dc04b39911ce4d7971775403e05695.tar.bz2 Kamon-a9dc9a9879dc04b39911ce4d7971775403e05695.zip |
Merge branch 'samplers' of https://github.com/Elyrixia/Kamon into pr/elyrixia-samplers-206
Diffstat (limited to 'kamon-core/src/main/scala/kamon/trace/Sampler.scala')
-rw-r--r-- | kamon-core/src/main/scala/kamon/trace/Sampler.scala | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/kamon-core/src/main/scala/kamon/trace/Sampler.scala b/kamon-core/src/main/scala/kamon/trace/Sampler.scala index ac780d5e..8480ecff 100644 --- a/kamon-core/src/main/scala/kamon/trace/Sampler.scala +++ b/kamon-core/src/main/scala/kamon/trace/Sampler.scala @@ -18,8 +18,7 @@ package kamon.trace import java.net.InetAddress import java.util.concurrent.atomic.AtomicLong - -import kamon.util.{ NanoInterval, Sequencer } +import kamon.util.{ NanoTimestamp, NanoInterval, Sequencer } import scala.concurrent.forkjoin.ThreadLocalRandom import scala.util.Try @@ -50,8 +49,8 @@ class RandomSampler(chance: Int) extends Sampler { class OrderedSampler(interval: Int) extends Sampler { import OrderedSampler._ - require(interval > 0, "kamon.trace.ordered-sampler.interval cannot be <= 0") - assume(interval isPowerOfTwo, "kamon.trace.ordered-sampler.interval must be power of two") + require(interval > 0, "kamon.trace.ordered-sampler.sample-interval cannot be <= 0") + assume(interval isPowerOfTwo, "kamon.trace.ordered-sampler.sample-interval must be power of two") private val sequencer = Sequencer() @@ -69,11 +68,27 @@ object OrderedSampler { } } -class ThresholdSampler(thresholdInNanoseconds: Long) extends Sampler { - require(thresholdInNanoseconds > 0, "kamon.trace.threshold-sampler.minimum-elapsed-time cannot be <= 0") +class ThresholdSampler(thresholdInNanoseconds: NanoInterval) extends Sampler { + require(thresholdInNanoseconds.nanos > 0, "kamon.trace.threshold-sampler.minimum-elapsed-time cannot be <= 0") def shouldTrace: Boolean = true - def shouldReport(traceElapsedTime: NanoInterval): Boolean = traceElapsedTime.nanos >= thresholdInNanoseconds + def shouldReport(traceElapsedTime: NanoInterval): Boolean = traceElapsedTime >= thresholdInNanoseconds +} + +class ClockSampler(pauseInNanoseconds: NanoInterval) extends Sampler { + require(pauseInNanoseconds.nanos > 0, "kamon.trace.clock-sampler.pause cannot be <= 0") + + private val timer: AtomicLong = new AtomicLong(0L) + + def shouldTrace: Boolean = { + val now = NanoTimestamp.now.nanos + val lastTimer = timer.get() + if ((lastTimer + pauseInNanoseconds.nanos) < now) + timer.compareAndSet(lastTimer, now) + else + false + } + def shouldReport(traceElapsedTime: NanoInterval): Boolean = true } class DefaultTokenGenerator extends Function0[String] { @@ -83,5 +98,4 @@ class DefaultTokenGenerator extends Function0[String] { def apply(): String = { _hostnamePrefix + "-" + String.valueOf(_tokenCounter.incrementAndGet()) } -} - +}
\ No newline at end of file |