aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego <diegolparra@gmail.com>2016-03-06 00:50:43 -0300
committerDiego <diegolparra@gmail.com>2016-03-06 00:50:43 -0300
commitab45bdb179aa3de1a7e1e39b6e88dfabd9491495 (patch)
treef9c0c20e20734f14929e892fb4dfcb95d2fc72e9
parentaffe465fdcc002fb12c54b3bb139ba3ef4fb1d85 (diff)
downloadKamon-ab45bdb179aa3de1a7e1e39b6e88dfabd9491495.tar.gz
Kamon-ab45bdb179aa3de1a7e1e39b6e88dfabd9491495.tar.bz2
Kamon-ab45bdb179aa3de1a7e1e39b6e88dfabd9491495.zip
= core: minor refactor in ExecutorServiceMetrics
-rw-r--r--kamon-core/src/main/scala/kamon/util/executors/ExecutorServiceMetrics.scala50
-rw-r--r--kamon-core/src/test/scala/kamon/util/executors/ExecutorServiceMetricsSpec.scala46
2 files changed, 44 insertions, 52 deletions
diff --git a/kamon-core/src/main/scala/kamon/util/executors/ExecutorServiceMetrics.scala b/kamon-core/src/main/scala/kamon/util/executors/ExecutorServiceMetrics.scala
index 7a87163f..98d2ea0c 100644
--- a/kamon-core/src/main/scala/kamon/util/executors/ExecutorServiceMetrics.scala
+++ b/kamon-core/src/main/scala/kamon/util/executors/ExecutorServiceMetrics.scala
@@ -16,10 +16,10 @@
package kamon.util.executors
+import java.util.concurrent.{ ExecutorService, ForkJoinPool ⇒ JavaForkJoinPool, ThreadPoolExecutor }
+
import kamon.Kamon
import kamon.metric.Entity
-import java.util.concurrent.{ ForkJoinPool ⇒ JavaForkJoinPool }
-import java.util.concurrent.{ ExecutorService, ThreadPoolExecutor }
import scala.concurrent.forkjoin.ForkJoinPool
import scala.util.control.NoStackTrace
@@ -48,8 +48,10 @@ object ExecutorServiceMetrics {
* @param threadPool The intance of the [[ThreadPoolExecutor]]
* @param tags The tags associated to the [[ThreadPoolExecutor]]
*/
- private def registerThreadPool(name: String, threadPool: ThreadPoolExecutor, tags: Map[String, String]): Unit = {
- Kamon.metrics.entity(ThreadPoolExecutorMetrics.factory(threadPool, Category), Entity(name, Category, tags))
+ @inline private def registerThreadPool(name: String, threadPool: ThreadPoolExecutor, tags: Map[String, String]): Entity = {
+ val threadPoolEntity = Entity(name, Category, tags + ("executor-type" -> "thread-pool-executor"))
+ Kamon.metrics.entity(ThreadPoolExecutorMetrics.factory(threadPool, Category), threadPoolEntity)
+ threadPoolEntity
}
/**
@@ -60,8 +62,10 @@ object ExecutorServiceMetrics {
* @param forkJoinPool The instance of the [[ForkJoinPool]]
* @param tags The tags associated to the [[ForkJoinPool]]
*/
- private def registerScalaForkJoin(name: String, forkJoinPool: ForkJoinPool, tags: Map[String, String] = Map.empty): Unit = {
- Kamon.metrics.entity(ForkJoinPoolMetrics.factory(forkJoinPool, Category), Entity(name, Category, tags))
+ @inline private def registerScalaForkJoin(name: String, forkJoinPool: ForkJoinPool, tags: Map[String, String]): Entity = {
+ val forkJoinEntity = Entity(name, Category, tags + ("executor-type" -> "fork-join-pool"))
+ Kamon.metrics.entity(ForkJoinPoolMetrics.factory(forkJoinPool, Category), forkJoinEntity)
+ forkJoinEntity
}
/**
@@ -72,8 +76,10 @@ object ExecutorServiceMetrics {
* @param forkJoinPool The instance of the [[JavaForkJoinPool]]
* @param tags The tags associated to the [[JavaForkJoinPool]]
*/
- private def registerJavaForkJoin(name: String, forkJoinPool: JavaForkJoinPool, tags: Map[String, String] = Map.empty): Unit = {
- Kamon.metrics.entity(ForkJoinPoolMetrics.factory(forkJoinPool, Category), Entity(name, Category, tags))
+ @inline private def registerJavaForkJoin(name: String, forkJoinPool: JavaForkJoinPool, tags: Map[String, String]): Entity = {
+ val forkJoinEntity = Entity(name, Category, tags + ("executor-type" -> "fork-join-pool"))
+ Kamon.metrics.entity(ForkJoinPoolMetrics.factory(forkJoinPool, Category), forkJoinEntity)
+ forkJoinEntity
}
/**
@@ -84,7 +90,7 @@ object ExecutorServiceMetrics {
* @param executorService The instance of the [[ExecutorService]]
* @param tags The tags associated to the [[ExecutorService]]
*/
- def register(name: String, executorService: ExecutorService, tags: Map[String, String]): Unit = executorService match {
+ def register(name: String, executorService: ExecutorService, tags: Map[String, String]): Entity = executorService match {
case threadPoolExecutor: ThreadPoolExecutor ⇒ registerThreadPool(name, threadPoolExecutor, tags)
case scalaForkJoinPool: ForkJoinPool if scalaForkJoinPool.getClass.isAssignableFrom(ScalaForkJoinPool) ⇒ registerScalaForkJoin(name, scalaForkJoinPool, tags)
case javaForkJoinPool: JavaForkJoinPool if javaForkJoinPool.getClass.isAssignableFrom(JavaForkJoinPool) ⇒ registerJavaForkJoin(name, javaForkJoinPool, tags)
@@ -94,36 +100,24 @@ object ExecutorServiceMetrics {
case other ⇒ throw new NotSupportedException(s"The ExecutorService $name is not supported.")
}
- //Java variants
- def register(name: String, executorService: ExecutorService): Unit = {
- register(name, executorService, Map.empty[String, String])
- }
-
- def register(name: String, executorService: ExecutorService, tags: java.util.Map[String, String]): Unit = {
+ //Java variant
+ def register(name: String, executorService: ExecutorService, tags: java.util.Map[String, String]): Entity = {
import scala.collection.JavaConverters._
register(name, executorService, tags.asScala.toMap)
}
/**
*
- * Remove the [[https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html ExecutorService]] to Monitor.
+ * Register the [[https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html ExecutorService]] to Monitor.
*
* @param name The name of the [[ExecutorService]]
- * @param tags The tags associated to the [[ExecutorService]]
+ * @param executorService The instance of the [[ExecutorService]]
*/
- def remove(name: String, tags: Map[String, String]): Unit = {
- Kamon.metrics.removeEntity(name, Category, tags)
- }
-
- //Java variants
- def remove(name: String): Unit = {
- remove(name, Map.empty[String, String])
+ def register(name: String, executorService: ExecutorService): Entity = {
+ register(name, executorService, Map.empty[String, String])
}
- def remove(name: String, tags: java.util.Map[String, String]): Unit = {
- import scala.collection.JavaConverters._
- remove(name, tags.asScala.toMap)
- }
+ def remove(entity: Entity): Unit = Kamon.metrics.removeEntity(entity)
/**
* INTERNAL USAGE ONLY
diff --git a/kamon-core/src/test/scala/kamon/util/executors/ExecutorServiceMetricsSpec.scala b/kamon-core/src/test/scala/kamon/util/executors/ExecutorServiceMetricsSpec.scala
index b3bc7623..4e5394f8 100644
--- a/kamon-core/src/test/scala/kamon/util/executors/ExecutorServiceMetricsSpec.scala
+++ b/kamon-core/src/test/scala/kamon/util/executors/ExecutorServiceMetricsSpec.scala
@@ -19,7 +19,7 @@ package kamon.util.executors
import java.util.concurrent.Executors
import kamon.Kamon
-import kamon.metric.EntityRecorder
+import kamon.metric.{Entity, EntityRecorder}
import kamon.testkit.BaseKamonSpec
class ExecutorServiceMetricsSpec extends BaseKamonSpec("executor-service-metrics-spec") {
@@ -27,51 +27,49 @@ class ExecutorServiceMetricsSpec extends BaseKamonSpec("executor-service-metrics
"the ExecutorServiceMetrics" should {
"register a SingleThreadPool, collect their metrics and remove it" in {
val singleThreadPoolExecutor = Executors.newSingleThreadExecutor()
- ExecutorServiceMetrics.register("single-thread-pool", singleThreadPoolExecutor)
- findExecutorRecorder("single-thread-pool") should not be empty
+ val singleThreadPoolExecutorEntity = ExecutorServiceMetrics.register("single-thread-pool", singleThreadPoolExecutor)
+ findExecutorRecorder(singleThreadPoolExecutorEntity) should not be empty
- ExecutorServiceMetrics.remove("single-thread-pool")
- findExecutorRecorder("single-thread-pool") should be(empty)
+ ExecutorServiceMetrics.remove(singleThreadPoolExecutorEntity)
+ findExecutorRecorder(singleThreadPoolExecutorEntity) should be(empty)
}
"register a ThreadPoolExecutor, collect their metrics and remove it" in {
val threadPoolExecutor = Executors.newCachedThreadPool()
- ExecutorServiceMetrics.register("thread-pool-executor", threadPoolExecutor)
- findExecutorRecorder("thread-pool-executor") should not be empty
+ val threadPoolExecutorEntity = ExecutorServiceMetrics.register("thread-pool-executor", threadPoolExecutor)
+ findExecutorRecorder(threadPoolExecutorEntity) should not be empty
- ExecutorServiceMetrics.remove("thread-pool-executor")
- findExecutorRecorder("thread-pool-executor") should be(empty)
+ ExecutorServiceMetrics.remove(threadPoolExecutorEntity)
+ findExecutorRecorder(threadPoolExecutorEntity) should be(empty)
}
"register a ScheduledThreadPoolExecutor, collect their metrics and remove it" in {
val scheduledThreadPoolExecutor = Executors.newSingleThreadScheduledExecutor()
- ExecutorServiceMetrics.register("scheduled-thread-pool-executor", scheduledThreadPoolExecutor)
- findExecutorRecorder("scheduled-thread-pool-executor") should not be empty
+ val scheduledThreadPoolEntity = ExecutorServiceMetrics.register("scheduled-thread-pool-executor", scheduledThreadPoolExecutor)
+ findExecutorRecorder(scheduledThreadPoolEntity) should not be empty
- ExecutorServiceMetrics.remove("scheduled-thread-pool-executor")
- findExecutorRecorder("scheduled-thread-pool-executor") should be(empty)
+ ExecutorServiceMetrics.remove(scheduledThreadPoolEntity)
+ findExecutorRecorder(scheduledThreadPoolEntity) should be(empty)
}
"register a Java ForkJoinPool, collect their metrics and remove it" in {
val javaForkJoinPool = Executors.newWorkStealingPool()
- ExecutorServiceMetrics.register("java-fork-join-pool", javaForkJoinPool)
- findExecutorRecorder("java-fork-join-pool") should not be empty
+ val javaForkJoinPoolEntity = ExecutorServiceMetrics.register("java-fork-join-pool", javaForkJoinPool)
+ findExecutorRecorder(javaForkJoinPoolEntity) should not be empty
- ExecutorServiceMetrics.remove("java-fork-join-pool")
- findExecutorRecorder("java-fork-join-pool") should be(empty)
+ ExecutorServiceMetrics.remove(javaForkJoinPoolEntity)
+ findExecutorRecorder(javaForkJoinPoolEntity) should be(empty)
}
"register a Scala ForkJoinPool, collect their metrics and remove it" in {
val scalaForkJoinPool = new scala.concurrent.forkjoin.ForkJoinPool()
- ExecutorServiceMetrics.register("scala-fork-join-pool", scalaForkJoinPool)
- findExecutorRecorder("scala-fork-join-pool") should not be empty
+ val scalaForkJoinPoolEntity = ExecutorServiceMetrics.register("scala-fork-join-pool", scalaForkJoinPool)
+ findExecutorRecorder(scalaForkJoinPoolEntity) should not be empty
- ExecutorServiceMetrics.remove("scala-fork-join-pool")
- findExecutorRecorder("scala-fork-join-pool") should be(empty)
+ ExecutorServiceMetrics.remove(scalaForkJoinPoolEntity)
+ findExecutorRecorder(scalaForkJoinPoolEntity) should be(empty)
}
- def findExecutorRecorder(name: String): Option[EntityRecorder] =
- Kamon.metrics.find(name, ExecutorServiceMetrics.Category, Map.empty)
+ def findExecutorRecorder(entity: Entity): Option[EntityRecorder] = Kamon.metrics.find(entity)
}
-
}