diff options
Diffstat (limited to 'kamon-core/src/main/scala')
-rw-r--r-- | kamon-core/src/main/scala/kamon/metrics/ActorMetricsOps.scala | 8 | ||||
-rw-r--r-- | kamon-core/src/main/scala/kamon/metrics/AtomicSnapshotableHistogram.scala | 13 | ||||
-rw-r--r-- | kamon-core/src/main/scala/kamon/trace/Trace.scala | 19 | ||||
-rw-r--r-- | kamon-core/src/main/scala/kamon/trace/TraceContext.scala | 2 | ||||
-rw-r--r-- | kamon-core/src/main/scala/kamon/trace/logging/LogbackTraceTokenConverter.scala (renamed from kamon-core/src/main/scala/kamon/trace/logging/LogbackUowConverter.scala) | 4 |
5 files changed, 22 insertions, 24 deletions
diff --git a/kamon-core/src/main/scala/kamon/metrics/ActorMetricsOps.scala b/kamon-core/src/main/scala/kamon/metrics/ActorMetricsOps.scala index dc4abde0..4a6c98f4 100644 --- a/kamon-core/src/main/scala/kamon/metrics/ActorMetricsOps.scala +++ b/kamon-core/src/main/scala/kamon/metrics/ActorMetricsOps.scala @@ -45,14 +45,6 @@ trait ActorMetricsOps { () ⇒ new HdrActorMetricsRecorder(processingTimeHdrConfig, timeInMailboxHdrConfig, mailboxSizeHdrConfig) } - import scala.concurrent.duration._ - system.scheduler.schedule(0.seconds, 10.seconds)( - actorMetrics.collect { - case (name, recorder: HdrActorMetricsRecorder) ⇒ - println(s"Actor: $name") - recorder.processingTimeHistogram.copy.getHistogramData.outputPercentileDistribution(System.out, 1000000D) - })(system.dispatcher) - def shouldTrackActor(path: String): Boolean = trackedActors.exists(glob ⇒ glob.accept(path)) && !excludedActors.exists(glob ⇒ glob.accept(path)) diff --git a/kamon-core/src/main/scala/kamon/metrics/AtomicSnapshotableHistogram.scala b/kamon-core/src/main/scala/kamon/metrics/AtomicSnapshotableHistogram.scala index 39d4ac0b..c9e47792 100644 --- a/kamon-core/src/main/scala/kamon/metrics/AtomicSnapshotableHistogram.scala +++ b/kamon-core/src/main/scala/kamon/metrics/AtomicSnapshotableHistogram.scala @@ -18,8 +18,7 @@ package org.HdrHistogram import java.util.concurrent.atomic.AtomicLongFieldUpdater import scala.annotation.tailrec -import org.HdrHistogram.AtomicSnapshotableHistogram.{Value, Snapshot} - +import org.HdrHistogram.AtomicSnapshotableHistogram.{ Value, Snapshot } /** * This implementation aims to be used for real time data collection where data snapshots are taken often over time. @@ -27,25 +26,23 @@ import org.HdrHistogram.AtomicSnapshotableHistogram.{Value, Snapshot} * leave it in a consistent state even in the case of concurrent modification while the snapshot is being taken. */ class AtomicSnapshotableHistogram(highestTrackableValue: Long, numberOfSignificantValueDigits: Int) - extends AtomicHistogram(1L, highestTrackableValue, numberOfSignificantValueDigits) { + extends AtomicHistogram(1L, highestTrackableValue, numberOfSignificantValueDigits) { import AtomicSnapshotableHistogram.totalCountUpdater - def snapshotAndReset(): Snapshot = { val entries = Vector.newBuilder[Value] val countsLength = counts.length() @tailrec def iterate(index: Int, previousValue: Long, nrOfRecordings: Long, bucketLimit: Long, increment: Long): Long = { - if(index < countsLength) { + if (index < countsLength) { val currentValue = previousValue + increment val countAtValue = counts.getAndSet(index, 0) - if(countAtValue > 0) + if (countAtValue > 0) entries += Value(currentValue, countAtValue) - - if(currentValue == bucketLimit) + if (currentValue == bucketLimit) iterate(index + 1, currentValue, nrOfRecordings + countAtValue, (bucketLimit << 1) + 1, increment << 1) else iterate(index + 1, currentValue, nrOfRecordings + countAtValue, bucketLimit, increment) diff --git a/kamon-core/src/main/scala/kamon/trace/Trace.scala b/kamon-core/src/main/scala/kamon/trace/Trace.scala index 31e8185a..7dd3a6f8 100644 --- a/kamon-core/src/main/scala/kamon/trace/Trace.scala +++ b/kamon-core/src/main/scala/kamon/trace/Trace.scala @@ -21,6 +21,8 @@ import scala.Some import kamon.trace.Trace.Register import scala.concurrent.duration._ import java.util.concurrent.atomic.AtomicLong +import scala.util.Try +import java.net.InetAddress object Trace extends ExtensionId[TraceExtension] with ExtensionIdProvider { def lookup(): ExtensionId[_ <: Extension] = Trace @@ -40,8 +42,8 @@ object Trace extends ExtensionId[TraceExtension] with ExtensionIdProvider { private def set(ctx: Option[TraceContext]) = traceContext.set(ctx) def clear: Unit = traceContext.remove() - def start(name: String)(implicit system: ActorSystem): TraceContext = { - val ctx = newTraceContext(name) + def start(name: String, token: Option[String])(implicit system: ActorSystem): TraceContext = { + val ctx = newTraceContext(name, token.getOrElse(TraceToken.generate())) ctx.start(name) set(Some(ctx)) @@ -68,7 +70,7 @@ object Trace extends ExtensionId[TraceExtension] with ExtensionIdProvider { } // TODO: FIX - def newTraceContext(name: String)(implicit system: ActorSystem): TraceContext = TraceContext(Kamon(Trace).api, tranid.getAndIncrement, name) + def newTraceContext(name: String, token: String)(implicit system: ActorSystem): TraceContext = TraceContext(Kamon(Trace).api, tranid.getAndIncrement, name, token) def startSegment(category: Segments.Category, description: String = "", attributes: Map[String, String] = Map()): SegmentCompletionHandle = { val start = Segments.Start(category, description, attributes) @@ -80,14 +82,21 @@ object Trace extends ExtensionId[TraceExtension] with ExtensionIdProvider { case class SegmentCompletionHandle(start: Segments.Start) { def complete(): Unit = { val end = Segments.End() - println(s"Completing the Segment: $start - $end") + //println(s"Completing the Segment: $start - $end") } def complete(end: Segments.End): Unit = { - println(s"Completing the Segment: $start - $end") + //println(s"Completing the Segment: $start - $end") } } } +object TraceToken { + val tokenCounter = new AtomicLong + val hostnamePrefix = Try(InetAddress.getLocalHost.getHostName).getOrElse("unknown-localhost") + + def generate(): String = "%s-%s".format(hostnamePrefix, tokenCounter.incrementAndGet()) +} + class TraceExtension(system: ExtendedActorSystem) extends Kamon.Extension { val api: ActorRef = system.actorOf(Props[TraceManager], "kamon-trace") } diff --git a/kamon-core/src/main/scala/kamon/trace/TraceContext.scala b/kamon-core/src/main/scala/kamon/trace/TraceContext.scala index 3e68a816..5780b749 100644 --- a/kamon-core/src/main/scala/kamon/trace/TraceContext.scala +++ b/kamon-core/src/main/scala/kamon/trace/TraceContext.scala @@ -23,7 +23,7 @@ import kamon.Kamon import kamon.trace.UowTracing.{ Finish, Start } // TODO: Decide if we need or not an ID, generating it takes time and it doesn't seem necessary. -case class TraceContext(private val collector: ActorRef, id: Long, uow: String = "", userContext: Option[Any] = None) { +case class TraceContext(private val collector: ActorRef, id: Long, name: String, token: String, userContext: Option[Any] = None) { def start(name: String) = { collector ! Start(id, name) diff --git a/kamon-core/src/main/scala/kamon/trace/logging/LogbackUowConverter.scala b/kamon-core/src/main/scala/kamon/trace/logging/LogbackTraceTokenConverter.scala index add47fdf..403e4ee7 100644 --- a/kamon-core/src/main/scala/kamon/trace/logging/LogbackUowConverter.scala +++ b/kamon-core/src/main/scala/kamon/trace/logging/LogbackTraceTokenConverter.scala @@ -19,6 +19,6 @@ import ch.qos.logback.classic.pattern.ClassicConverter import ch.qos.logback.classic.spi.ILoggingEvent import kamon.trace.Trace -class LogbackUowConverter extends ClassicConverter { - def convert(event: ILoggingEvent): String = Trace.context().map(_.uow).getOrElse("undefined") +class LogbackTraceTokenConverter extends ClassicConverter { + def convert(event: ILoggingEvent): String = Trace.context().map(_.token).getOrElse("undefined") } |