aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Topolnjak <ivantopo@gmail.com>2014-08-02 17:36:26 -0300
committerIvan Topolnjak <ivantopo@gmail.com>2014-08-02 17:36:26 -0300
commitcefc5c0e6cd0c5de49aa6bb748266d575fa4d728 (patch)
treec7cfd773b4f43c57b2828a910c5ee5dc49ea7c23
parenta6741bbf57eb8c9088190778d6cb6da89f895925 (diff)
downloadKamon-cefc5c0e6cd0c5de49aa6bb748266d575fa4d728.tar.gz
Kamon-cefc5c0e6cd0c5de49aa6bb748266d575fa4d728.tar.bz2
Kamon-cefc5c0e6cd0c5de49aa6bb748266d575fa4d728.zip
= core: cleanup actor metrics recorder after the actor is stopped, closes #69
-rw-r--r--kamon-core/src/main/scala/kamon/instrumentation/akka/ActorCellInstrumentation.scala2
-rw-r--r--kamon-core/src/main/scala/kamon/metric/MetricsExtension.scala2
-rw-r--r--kamon-core/src/test/scala/kamon/metric/ActorMetricsSpec.scala16
3 files changed, 16 insertions, 4 deletions
diff --git a/kamon-core/src/main/scala/kamon/instrumentation/akka/ActorCellInstrumentation.scala b/kamon-core/src/main/scala/kamon/instrumentation/akka/ActorCellInstrumentation.scala
index 5fce4555..446bc487 100644
--- a/kamon-core/src/main/scala/kamon/instrumentation/akka/ActorCellInstrumentation.scala
+++ b/kamon-core/src/main/scala/kamon/instrumentation/akka/ActorCellInstrumentation.scala
@@ -82,7 +82,6 @@ class ActorCellInstrumentation {
val cellWithMetrics = cell.asInstanceOf[ActorCellMetrics]
cellWithMetrics.actorMetricsRecorder.map { p ⇒
- cellWithMetrics.mailboxSizeCollectorCancellable.cancel()
Kamon(Metrics)(cell.system).unregister(cellWithMetrics.metricIdentity)
}
}
@@ -103,7 +102,6 @@ class ActorCellInstrumentation {
trait ActorCellMetrics {
var metricIdentity: ActorMetrics = _
var actorMetricsRecorder: Option[ActorMetricsRecorder] = _
- var mailboxSizeCollectorCancellable: Cancellable = _
}
@Aspect
diff --git a/kamon-core/src/main/scala/kamon/metric/MetricsExtension.scala b/kamon-core/src/main/scala/kamon/metric/MetricsExtension.scala
index 00214f51..51cda6b2 100644
--- a/kamon-core/src/main/scala/kamon/metric/MetricsExtension.scala
+++ b/kamon-core/src/main/scala/kamon/metric/MetricsExtension.scala
@@ -52,7 +52,7 @@ class MetricsExtension(system: ExtendedActorSystem) extends Kamon.Extension {
}
def unregister(identity: MetricGroupIdentity): Unit = {
- storage.remove(identity)
+ storage.remove(identity).map(_.cleanup)
}
def subscribe[C <: MetricGroupCategory](category: C, selection: String, subscriber: ActorRef, permanently: Boolean = false): Unit =
diff --git a/kamon-core/src/test/scala/kamon/metric/ActorMetricsSpec.scala b/kamon-core/src/test/scala/kamon/metric/ActorMetricsSpec.scala
index a05dc344..8f5e1b9b 100644
--- a/kamon-core/src/test/scala/kamon/metric/ActorMetricsSpec.scala
+++ b/kamon-core/src/test/scala/kamon/metric/ActorMetricsSpec.scala
@@ -18,6 +18,7 @@ package kamon.metric
import java.nio.LongBuffer
import akka.instrumentation.ActorCellMetrics
+import kamon.Kamon
import kamon.metric.ActorMetricsTestActor._
import kamon.metric.instrument.Histogram.MutableRecord
import org.scalatest.{ WordSpecLike, Matchers }
@@ -38,7 +39,7 @@ class ActorMetricsSpec extends TestKitBase with WordSpecLike with Matchers with
| filters = [
| {
| actor {
- | includes = [ "user/tracked-*", "user/measuring-*", "user/clean-after-collect" ]
+ | includes = [ "user/tracked-*", "user/measuring-*", "user/clean-after-collect", "user/stop" ]
| excludes = [ "user/tracked-explicitly-excluded"]
| }
| }
@@ -152,6 +153,19 @@ class ActorMetricsSpec extends TestKitBase with WordSpecLike with Matchers with
snapshot.timeInMailbox.recordsIterator.next().count should be(1L)
snapshot.timeInMailbox.recordsIterator.next().level should be(timings.approximateTimeInMailbox +- 10.millis.toNanos)
}
+
+ "clean up the associated recorder when the actor is stopped" in new ActorMetricsFixtures {
+ val trackedActor = createTestActor("stop")
+ actorMetricsRecorderOf(trackedActor).get // force the actor to be initialized
+ Kamon(Metrics).storage.get(ActorMetrics("user/stop")) should not be empty
+
+ val deathWatcher = TestProbe()
+ deathWatcher.watch(trackedActor)
+ trackedActor ! PoisonPill
+ deathWatcher.expectTerminated(trackedActor)
+
+ Kamon(Metrics).storage.get(ActorMetrics("user/stop")) shouldBe empty
+ }
}
trait ActorMetricsFixtures {