aboutsummaryrefslogtreecommitdiff
path: root/kamon-akka
diff options
context:
space:
mode:
authorIvan Topolnjak <ivantopo@gmail.com>2015-02-12 11:30:06 +0100
committerIvan Topolnjak <ivantopo@gmail.com>2015-02-13 05:15:30 +0100
commitc6bb65535bcc3cc1ff3834a91473ee8dfa6145e8 (patch)
treed7dbe6a1007b168998f167ac74a98744542c6fa8 /kamon-akka
parent6729c9632245328a007332cdcce7d362584d735a (diff)
downloadKamon-c6bb65535bcc3cc1ff3834a91473ee8dfa6145e8.tar.gz
Kamon-c6bb65535bcc3cc1ff3834a91473ee8dfa6145e8.tar.bz2
Kamon-c6bb65535bcc3cc1ff3834a91473ee8dfa6145e8.zip
! all: Kamon now works as a single instance in a companion object.
Diffstat (limited to 'kamon-akka')
-rw-r--r--kamon-akka/src/main/scala/kamon/akka/instrumentation/ActorCellInstrumentation.scala11
-rw-r--r--kamon-akka/src/main/scala/kamon/akka/instrumentation/AskPatternInstrumentation.scala2
-rw-r--r--kamon-akka/src/main/scala/kamon/akka/instrumentation/DispatcherInstrumentation.scala9
-rw-r--r--kamon-akka/src/test/scala/kamon/akka/ActorMetricsSpec.scala (renamed from kamon-akka/src/test/scala/kamon/metric/ActorMetricsSpec.scala)62
-rw-r--r--kamon-akka/src/test/scala/kamon/akka/DispatcherMetricsSpec.scala (renamed from kamon-akka/src/test/scala/kamon/metric/DispatcherMetricsSpec.scala)116
-rw-r--r--kamon-akka/src/test/scala/kamon/akka/RouterMetricsSpec.scala (renamed from kamon-akka/src/test/scala/kamon/metric/RouterMetricsSpec.scala)49
-rw-r--r--kamon-akka/src/test/scala/kamon/akka/instrumentation/AskPatternInstrumentationSpec.scala2
7 files changed, 127 insertions, 124 deletions
diff --git a/kamon-akka/src/main/scala/kamon/akka/instrumentation/ActorCellInstrumentation.scala b/kamon-akka/src/main/scala/kamon/akka/instrumentation/ActorCellInstrumentation.scala
index c961737d..7c722569 100644
--- a/kamon-akka/src/main/scala/kamon/akka/instrumentation/ActorCellInstrumentation.scala
+++ b/kamon-akka/src/main/scala/kamon/akka/instrumentation/ActorCellInstrumentation.scala
@@ -19,8 +19,9 @@ package akka.kamon.instrumentation
import akka.actor._
import akka.dispatch.{ Envelope, MessageDispatcher }
import akka.routing.RoutedActorCell
+import kamon.Kamon
import kamon.akka.{ RouterMetrics, ActorMetrics }
-import kamon.metric.{ Metrics, Entity }
+import kamon.metric.Entity
import kamon.trace._
import org.aspectj.lang.ProceedingJoinPoint
import org.aspectj.lang.annotation._
@@ -33,7 +34,7 @@ class ActorCellInstrumentation {
@After("actorCellCreation(cell, system, ref, props, dispatcher, parent)")
def afterCreation(cell: ActorCell, system: ActorSystem, ref: ActorRef, props: Props, dispatcher: MessageDispatcher, parent: ActorRef): Unit = {
- Metrics.get(system).register(ActorMetrics, ref.path.elements.mkString("/")).map { registration ⇒
+ Kamon.metrics.register(ActorMetrics, ref.path.elements.mkString("/")).map { registration ⇒
val cellMetrics = cell.asInstanceOf[ActorCellMetrics]
cellMetrics.entity = registration.entity
@@ -89,14 +90,14 @@ class ActorCellInstrumentation {
def afterStop(cell: ActorCell): Unit = {
val cellMetrics = cell.asInstanceOf[ActorCellMetrics]
cellMetrics.recorder.map { _ ⇒
- Metrics.get(cell.system).unregister(cellMetrics.entity)
+ Kamon.metrics.unregister(cellMetrics.entity)
}
// The Stop can't be captured from the RoutedActorCell so we need to put this piece of cleanup here.
if (cell.isInstanceOf[RoutedActorCell]) {
val routedCellMetrics = cell.asInstanceOf[RoutedActorCellMetrics]
routedCellMetrics.routerRecorder.map { _ ⇒
- Metrics.get(cell.system).unregister(routedCellMetrics.routerEntity)
+ Kamon.metrics.unregister(routedCellMetrics.routerEntity)
}
}
}
@@ -123,7 +124,7 @@ class RoutedActorCellInstrumentation {
@After("routedActorCellCreation(cell, system, ref, props, dispatcher, routeeProps, supervisor)")
def afterRoutedActorCellCreation(cell: RoutedActorCell, system: ActorSystem, ref: ActorRef, props: Props, dispatcher: MessageDispatcher, routeeProps: Props, supervisor: ActorRef): Unit = {
- Metrics.get(system).register(RouterMetrics, ref.path.elements.mkString("/")).map { registration ⇒
+ Kamon.metrics.register(RouterMetrics, ref.path.elements.mkString("/")).map { registration ⇒
val cellMetrics = cell.asInstanceOf[RoutedActorCellMetrics]
cellMetrics.routerEntity = registration.entity
diff --git a/kamon-akka/src/main/scala/kamon/akka/instrumentation/AskPatternInstrumentation.scala b/kamon-akka/src/main/scala/kamon/akka/instrumentation/AskPatternInstrumentation.scala
index 28bfcae9..e1dcdf32 100644
--- a/kamon-akka/src/main/scala/kamon/akka/instrumentation/AskPatternInstrumentation.scala
+++ b/kamon-akka/src/main/scala/kamon/akka/instrumentation/AskPatternInstrumentation.scala
@@ -44,7 +44,7 @@ class AskPatternInstrumentation {
actor match {
// the AskPattern will only work for InternalActorRef's with these conditions.
case ref: InternalActorRef if !ref.isTerminated && timeout.duration.length > 0 ⇒
- val akkaExtension = ctx.lookupExtension(Akka)
+ val akkaExtension = Kamon.extension(Akka)
val future = pjp.proceed().asInstanceOf[Future[AnyRef]]
val system = ref.provider.guardian.underlying.system
diff --git a/kamon-akka/src/main/scala/kamon/akka/instrumentation/DispatcherInstrumentation.scala b/kamon-akka/src/main/scala/kamon/akka/instrumentation/DispatcherInstrumentation.scala
index f4bc31c4..7b15c443 100644
--- a/kamon-akka/src/main/scala/kamon/akka/instrumentation/DispatcherInstrumentation.scala
+++ b/kamon-akka/src/main/scala/kamon/akka/instrumentation/DispatcherInstrumentation.scala
@@ -22,8 +22,9 @@ import akka.actor.{ ActorSystem, ActorSystemImpl }
import akka.dispatch.ForkJoinExecutorConfigurator.AkkaForkJoinPool
import akka.dispatch._
import akka.kamon.instrumentation.LookupDataAware.LookupData
+import kamon.Kamon
import kamon.akka.{ AkkaDispatcherMetrics, ThreadPoolExecutorDispatcherMetrics, ForkJoinPoolDispatcherMetrics }
-import kamon.metric.{ Metrics, Entity }
+import kamon.metric.Entity
import org.aspectj.lang.ProceedingJoinPoint
import org.aspectj.lang.annotation._
@@ -58,10 +59,10 @@ class DispatcherInstrumentation {
private def registerDispatcher(dispatcherName: String, executorService: ExecutorService, system: ActorSystem): Unit =
executorService match {
case fjp: AkkaForkJoinPool ⇒
- Metrics.get(system).register(ForkJoinPoolDispatcherMetrics.factory(fjp), dispatcherName)
+ Kamon.metrics.register(ForkJoinPoolDispatcherMetrics.factory(fjp), dispatcherName)
case tpe: ThreadPoolExecutor ⇒
- Metrics.get(system).register(ThreadPoolExecutorDispatcherMetrics.factory(tpe), dispatcherName)
+ Kamon.metrics.register(ThreadPoolExecutorDispatcherMetrics.factory(tpe), dispatcherName)
case others ⇒ // Currently not interested in other kinds of dispatchers.
}
@@ -119,7 +120,7 @@ class DispatcherInstrumentation {
import lazyExecutor.lookupData
if (lookupData.actorSystem != null)
- Metrics.get(lookupData.actorSystem).unregister(Entity(lookupData.dispatcherName, AkkaDispatcherMetrics.Category))
+ Kamon.metrics.unregister(Entity(lookupData.dispatcherName, AkkaDispatcherMetrics.Category))
}
}
diff --git a/kamon-akka/src/test/scala/kamon/metric/ActorMetricsSpec.scala b/kamon-akka/src/test/scala/kamon/akka/ActorMetricsSpec.scala
index 322abed2..19a71053 100644
--- a/kamon-akka/src/test/scala/kamon/metric/ActorMetricsSpec.scala
+++ b/kamon-akka/src/test/scala/kamon/akka/ActorMetricsSpec.scala
@@ -13,42 +13,44 @@
* =========================================================================================
*/
-package kamon.metric
+package kamon.akka
import java.nio.LongBuffer
-import kamon.Kamon
-import kamon.akka.ActorMetrics
-import kamon.metric.ActorMetricsTestActor._
-import kamon.metric.instrument.CollectionContext
-import org.scalatest.{ BeforeAndAfterAll, WordSpecLike, Matchers }
-import akka.testkit.{ ImplicitSender, TestProbe, TestKitBase }
import akka.actor._
+import akka.testkit.TestProbe
import com.typesafe.config.ConfigFactory
+import kamon.Kamon
+import kamon.akka.ActorMetricsTestActor._
+import kamon.metric.EntitySnapshot
+import kamon.metric.instrument.CollectionContext
+import kamon.testkit.BaseKamonSpec
+
import scala.concurrent.duration._
-class ActorMetricsSpec extends TestKitBase with WordSpecLike with Matchers with ImplicitSender with BeforeAndAfterAll {
- implicit lazy val system: ActorSystem = ActorSystem("actor-metrics-spec", ConfigFactory.parseString(
- """
- |kamon.metric {
- | tick-interval = 1 hour
- | default-collection-context-buffer-size = 10
- |
- | filters {
- | akka-actor {
- | includes = [ "user/tracked-*", "user/measuring-*", "user/clean-after-collect", "user/stop" ]
- | excludes = [ "user/tracked-explicitly-excluded", "user/non-tracked-actor" ]
- | }
- | }
- |
- | instrument-settings {
- | akka-actor.mailbox-size.refresh-interval = 1 hour
- | }
- |}
- |
- |akka.loglevel = OFF
- |
- """.stripMargin))
+class ActorMetricsSpec extends BaseKamonSpec("actor-metrics-spec") {
+ override lazy val config =
+ ConfigFactory.parseString(
+ """
+ |kamon.metric {
+ | tick-interval = 1 hour
+ | default-collection-context-buffer-size = 10
+ |
+ | filters {
+ | akka-actor {
+ | includes = [ "user/tracked-*", "user/measuring-*", "user/clean-after-collect", "user/stop" ]
+ | excludes = [ "user/tracked-explicitly-excluded", "user/non-tracked-actor" ]
+ | }
+ | }
+ |
+ | instrument-settings {
+ | akka-actor.mailbox-size.refresh-interval = 1 hour
+ | }
+ |}
+ |
+ |akka.loglevel = OFF
+ |
+ """.stripMargin)
"the Kamon actor metrics" should {
"respect the configured include and exclude filters" in new ActorMetricsFixtures {
@@ -163,7 +165,7 @@ class ActorMetricsSpec extends TestKitBase with WordSpecLike with Matchers with
def actorRecorderName(ref: ActorRef): String = ref.path.elements.mkString("/")
def actorMetricsRecorderOf(ref: ActorRef): Option[ActorMetrics] =
- Kamon(Metrics)(system).register(ActorMetrics, actorRecorderName(ref)).map(_.recorder)
+ Kamon.metrics.register(ActorMetrics, actorRecorderName(ref)).map(_.recorder)
def collectMetricsOf(ref: ActorRef): Option[EntitySnapshot] = {
Thread.sleep(5) // Just in case the test advances a bit faster than the actor being tested.
diff --git a/kamon-akka/src/test/scala/kamon/metric/DispatcherMetricsSpec.scala b/kamon-akka/src/test/scala/kamon/akka/DispatcherMetricsSpec.scala
index 2c530da9..209b5cf5 100644
--- a/kamon-akka/src/test/scala/kamon/metric/DispatcherMetricsSpec.scala
+++ b/kamon-akka/src/test/scala/kamon/akka/DispatcherMetricsSpec.scala
@@ -13,72 +13,73 @@
* =========================================================================================
*/
-package kamon.metric
+package kamon.akka
import java.nio.LongBuffer
-import akka.actor.{ PoisonPill, Props, ActorRef, ActorSystem }
+import akka.actor.{ ActorRef, ActorSystem }
import akka.dispatch.MessageDispatcher
import akka.testkit.{ TestKitBase, TestProbe }
import com.typesafe.config.ConfigFactory
import kamon.Kamon
-import kamon.akka.{ ForkJoinPoolDispatcherMetrics, ThreadPoolExecutorDispatcherMetrics }
-import kamon.metric.ActorMetricsTestActor.{ Pong, Ping }
import kamon.metric.instrument.CollectionContext
+import kamon.metric.{ EntityRecorder, EntitySnapshot }
+import kamon.testkit.BaseKamonSpec
import org.scalatest.{ BeforeAndAfterAll, Matchers, WordSpecLike }
-import scala.concurrent.{ Await, Future }
import scala.concurrent.duration._
+import scala.concurrent.{ Await, Future }
-class DispatcherMetricsSpec extends TestKitBase with WordSpecLike with Matchers with BeforeAndAfterAll {
- implicit lazy val system: ActorSystem = ActorSystem("dispatcher-metrics-spec", ConfigFactory.parseString(
- """
- |kamon.metric {
- | tick-interval = 1 hour
- | default-collection-context-buffer-size = 10
- |
- | filters = {
- | akka-dispatcher {
- | includes = [ "*" ]
- | excludes = [ "explicitly-excluded" ]
- | }
- | }
- |
- | default-instrument-settings {
- | gauge.refresh-interval = 1 hour
- | min-max-counter.refresh-interval = 1 hour
- | }
- |}
- |
- |explicitly-excluded {
- | type = "Dispatcher"
- | executor = "fork-join-executor"
- |}
- |
- |tracked-fjp {
- | type = "Dispatcher"
- | executor = "fork-join-executor"
- |
- | fork-join-executor {
- | parallelism-min = 8
- | parallelism-factor = 100.0
- | parallelism-max = 22
- | }
- |}
- |
- |tracked-tpe {
- | type = "Dispatcher"
- | executor = "thread-pool-executor"
- |
- | thread-pool-executor {
- | core-pool-size-min = 7
- | core-pool-size-factor = 100.0
- | max-pool-size-factor = 100.0
- | max-pool-size-max = 21
- | }
- |}
- |
- """.stripMargin))
+class DispatcherMetricsSpec extends BaseKamonSpec("dispatcher-metrics-spec") {
+ override lazy val config =
+ ConfigFactory.parseString(
+ """
+ |kamon.metric {
+ | tick-interval = 1 hour
+ | default-collection-context-buffer-size = 10
+ |
+ | filters = {
+ | akka-dispatcher {
+ | includes = [ "*" ]
+ | excludes = [ "explicitly-excluded" ]
+ | }
+ | }
+ |
+ | default-instrument-settings {
+ | gauge.refresh-interval = 1 hour
+ | min-max-counter.refresh-interval = 1 hour
+ | }
+ |}
+ |
+ |explicitly-excluded {
+ | type = "Dispatcher"
+ | executor = "fork-join-executor"
+ |}
+ |
+ |tracked-fjp {
+ | type = "Dispatcher"
+ | executor = "fork-join-executor"
+ |
+ | fork-join-executor {
+ | parallelism-min = 8
+ | parallelism-factor = 100.0
+ | parallelism-max = 22
+ | }
+ |}
+ |
+ |tracked-tpe {
+ | type = "Dispatcher"
+ | executor = "thread-pool-executor"
+ |
+ | thread-pool-executor {
+ | core-pool-size-min = 7
+ | core-pool-size-factor = 100.0
+ | max-pool-size-factor = 100.0
+ | max-pool-size-max = 21
+ | }
+ |}
+ |
+ """.stripMargin)
"the Kamon dispatcher metrics" should {
"respect the configured include and exclude filters" in {
@@ -95,6 +96,7 @@ class DispatcherMetricsSpec extends TestKitBase with WordSpecLike with Matchers
"record metrics for a dispatcher with thread-pool-executor" in {
implicit val tpeDispatcher = system.dispatchers.lookup("tracked-tpe")
+ refreshDispatcherInstruments(tpeDispatcher)
collectDispatcherMetrics(tpeDispatcher)
Await.result({
@@ -156,14 +158,10 @@ class DispatcherMetricsSpec extends TestKitBase with WordSpecLike with Matchers
}
- val collectionContext = new CollectionContext {
- val buffer: LongBuffer = LongBuffer.allocate(10000)
- }
-
def actorRecorderName(ref: ActorRef): String = ref.path.elements.mkString("/")
def findDispatcherRecorder(dispatcher: MessageDispatcher): Option[EntityRecorder] =
- Kamon(Metrics)(system).find(dispatcher.id, "akka-dispatcher")
+ Kamon.metrics.find(dispatcher.id, "akka-dispatcher")
def collectDispatcherMetrics(dispatcher: MessageDispatcher): EntitySnapshot =
findDispatcherRecorder(dispatcher).map(_.collect(collectionContext)).get
diff --git a/kamon-akka/src/test/scala/kamon/metric/RouterMetricsSpec.scala b/kamon-akka/src/test/scala/kamon/akka/RouterMetricsSpec.scala
index 5f6bbb4f..ec55648b 100644
--- a/kamon-akka/src/test/scala/kamon/metric/RouterMetricsSpec.scala
+++ b/kamon-akka/src/test/scala/kamon/akka/RouterMetricsSpec.scala
@@ -13,40 +13,41 @@
* =========================================================================================
*/
-package kamon.metric
+package kamon.akka
import java.nio.LongBuffer
import akka.actor._
import akka.routing._
-import akka.testkit.{ ImplicitSender, TestKitBase, TestProbe }
+import akka.testkit.TestProbe
import com.typesafe.config.ConfigFactory
import kamon.Kamon
-import kamon.akka.RouterMetrics
-import kamon.metric.RouterMetricsTestActor._
+import kamon.akka.RouterMetricsTestActor._
+import kamon.metric.EntitySnapshot
import kamon.metric.instrument.CollectionContext
-import org.scalatest.{ BeforeAndAfterAll, Matchers, WordSpecLike }
+import kamon.testkit.BaseKamonSpec
import scala.concurrent.duration._
-class RouterMetricsSpec extends TestKitBase with WordSpecLike with Matchers with ImplicitSender with BeforeAndAfterAll {
- implicit lazy val system: ActorSystem = ActorSystem("router-metrics-spec", ConfigFactory.parseString(
- """
- |kamon.metric {
- | tick-interval = 1 hour
- | default-collection-context-buffer-size = 10
- |
- | filters = {
- | akka-router {
- | includes = [ "user/tracked-*", "user/measuring-*", "user/stop-*" ]
- | excludes = [ "user/tracked-explicitly-excluded-*"]
- | }
- | }
- |}
- |
- |akka.loglevel = OFF
- |
- """.stripMargin))
+class RouterMetricsSpec extends BaseKamonSpec("router-metrics-spec") {
+ override lazy val config =
+ ConfigFactory.parseString(
+ """
+ |kamon.metric {
+ | tick-interval = 1 hour
+ | default-collection-context-buffer-size = 10
+ |
+ | filters = {
+ | akka-router {
+ | includes = [ "user/tracked-*", "user/measuring-*", "user/stop-*" ]
+ | excludes = [ "user/tracked-explicitly-excluded-*"]
+ | }
+ | }
+ |}
+ |
+ |akka.loglevel = OFF
+ |
+ """.stripMargin)
"the Kamon router metrics" should {
"respect the configured include and exclude filters" in new RouterMetricsFixtures {
@@ -204,7 +205,7 @@ class RouterMetricsSpec extends TestKitBase with WordSpecLike with Matchers with
}
def routerMetricsRecorderOf(routerName: String): Option[RouterMetrics] =
- Kamon(Metrics)(system).register(RouterMetrics, routerName).map(_.recorder)
+ Kamon.metrics.register(RouterMetrics, routerName).map(_.recorder)
def collectMetricsOf(routerName: String): Option[EntitySnapshot] = {
Thread.sleep(5) // Just in case the test advances a bit faster than the actor being tested.
diff --git a/kamon-akka/src/test/scala/kamon/akka/instrumentation/AskPatternInstrumentationSpec.scala b/kamon-akka/src/test/scala/kamon/akka/instrumentation/AskPatternInstrumentationSpec.scala
index 0d63a19e..44b90642 100644
--- a/kamon-akka/src/test/scala/kamon/akka/instrumentation/AskPatternInstrumentationSpec.scala
+++ b/kamon-akka/src/test/scala/kamon/akka/instrumentation/AskPatternInstrumentationSpec.scala
@@ -114,7 +114,7 @@ class AskPatternInstrumentationSpec extends BaseKamonSpec("ask-pattern-tracing-s
}
def setAskPatternTimeoutWarningMode(mode: String): Unit = {
- val target = Kamon(Akka)(system)
+ val target = Kamon(Akka)
val field = target.getClass.getDeclaredField("askPatternTimeoutWarning")
field.setAccessible(true)
field.set(target, mode)