diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2014-01-27 09:11:32 -0300 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2014-01-27 09:11:32 -0300 |
commit | 633b4058207d084724743c6b6367ac60f95ff987 (patch) | |
tree | a0ea788593b93b2657e1924e578ff274aab3eeee /kamon-core/src | |
parent | f341a9f01aa53bb79dbbc8a2cccd652c03ae5267 (diff) | |
download | Kamon-633b4058207d084724743c6b6367ac60f95ff987.tar.gz Kamon-633b4058207d084724743c6b6367ac60f95ff987.tar.bz2 Kamon-633b4058207d084724743c6b6367ac60f95ff987.zip |
rename UOW to TraceToken and generate it by default when a Trace starts
Diffstat (limited to 'kamon-core/src')
-rw-r--r-- | kamon-core/src/main/java/kamon/util/GlobPathFilter.java | 3 | ||||
-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 | ||||
-rw-r--r-- | kamon-core/src/test/scala/kamon/trace/instrumentation/ActorLoggingSpec.scala | 2 | ||||
-rw-r--r-- | kamon-core/src/test/scala/kamon/trace/instrumentation/ActorMessagePassingTracingSpec.scala | 2 | ||||
-rw-r--r-- | kamon-core/src/test/scala/kamon/trace/instrumentation/TraceContextFixture.scala | 2 |
9 files changed, 26 insertions, 29 deletions
diff --git a/kamon-core/src/main/java/kamon/util/GlobPathFilter.java b/kamon-core/src/main/java/kamon/util/GlobPathFilter.java index 5b019bec..a000e2a0 100644 --- a/kamon-core/src/main/java/kamon/util/GlobPathFilter.java +++ b/kamon-core/src/main/java/kamon/util/GlobPathFilter.java @@ -1,6 +1,6 @@ /* * ========================================================================================= - * Copyright © 2013 the kamon project <http://kamon.io/> + * Copyright 2013 the kamon project <http://kamon.io/> * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of the License at @@ -14,7 +14,6 @@ * ========================================================================================= */ - // This file was copied from: https://github.com/jboss-modules/jboss-modules/blob/master/src/main/java/org/jboss/modules/filter/GlobPathFilter.java package kamon.util; 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") } diff --git a/kamon-core/src/test/scala/kamon/trace/instrumentation/ActorLoggingSpec.scala b/kamon-core/src/test/scala/kamon/trace/instrumentation/ActorLoggingSpec.scala index 89742651..d6648cef 100644 --- a/kamon-core/src/test/scala/kamon/trace/instrumentation/ActorLoggingSpec.scala +++ b/kamon-core/src/test/scala/kamon/trace/instrumentation/ActorLoggingSpec.scala @@ -25,7 +25,7 @@ class ActorLoggingSpec extends TestKit(ActorSystem("actor-logging-spec")) with W "the ActorLogging instrumentation" should { "attach the TraceContext (if available) to log events" in { - val testTraceContext = Some(TraceContext(Actor.noSender, 1)) + val testTraceContext = Some(TraceContext(Actor.noSender, 1, "test", "test-1")) val loggerActor = system.actorOf(Props[LoggerActor]) system.eventStream.subscribe(testActor, classOf[LogEvent]) diff --git a/kamon-core/src/test/scala/kamon/trace/instrumentation/ActorMessagePassingTracingSpec.scala b/kamon-core/src/test/scala/kamon/trace/instrumentation/ActorMessagePassingTracingSpec.scala index 89251bf4..f32623b9 100644 --- a/kamon-core/src/test/scala/kamon/trace/instrumentation/ActorMessagePassingTracingSpec.scala +++ b/kamon-core/src/test/scala/kamon/trace/instrumentation/ActorMessagePassingTracingSpec.scala @@ -67,7 +67,7 @@ class ActorMessagePassingTracingSpec extends TestKit(ActorSystem("actor-message- } trait TraceContextEchoFixture { - val testTraceContext = Some(Trace.newTraceContext("")) + val testTraceContext = Some(Trace.newTraceContext("test", "test-1")) val ctxEchoActor = system.actorOf(Props[TraceContextEcho]) } diff --git a/kamon-core/src/test/scala/kamon/trace/instrumentation/TraceContextFixture.scala b/kamon-core/src/test/scala/kamon/trace/instrumentation/TraceContextFixture.scala index 62f7ec84..2df95d09 100644 --- a/kamon-core/src/test/scala/kamon/trace/instrumentation/TraceContextFixture.scala +++ b/kamon-core/src/test/scala/kamon/trace/instrumentation/TraceContextFixture.scala @@ -6,5 +6,5 @@ import akka.actor.Actor trait TraceContextFixture { val random = new Random(System.nanoTime) - val testTraceContext = Some(TraceContext(Actor.noSender, random.nextInt)) + val testTraceContext = Some(TraceContext(Actor.noSender, random.nextInt, "test", "test-1")) }
\ No newline at end of file |