From 79c7f9bbbbf775e09b7a02109a77986665be43bc Mon Sep 17 00:00:00 2001 From: Martin Grotzke Date: Thu, 6 Jul 2017 17:22:55 +0200 Subject: Log warn when Entity with name=null is created / if dispatching entities fails (#475) An application that creates a metric while passing `null` as metrics name will not receive the expected `TickMetricSnapshot` (if it subscribes for metrics). As log level _warn_ (instead of error) is chosen, because from an application perspective the app's functionality is not affected, i.e. there's no _immediate_ action required, but it's ok if this gets solved eventually. --- kamon-core/src/main/scala/kamon/metric/Entity.scala | 9 ++++++++- .../main/scala/kamon/metric/SubscriptionsDispatcher.scala | 12 ++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/kamon-core/src/main/scala/kamon/metric/Entity.scala b/kamon-core/src/main/scala/kamon/metric/Entity.scala index 91249af0..17b728fd 100644 --- a/kamon-core/src/main/scala/kamon/metric/Entity.scala +++ b/kamon-core/src/main/scala/kamon/metric/Entity.scala @@ -16,6 +16,8 @@ package kamon.metric +import org.slf4j.LoggerFactory + /** * Identify a `thing` that is being monitored by Kamon. A [[kamon.metric.Entity]] is used to identify tracked `things` * in both the metrics recording and reporting sides. Only the name and category fields are used with determining @@ -23,9 +25,14 @@ package kamon.metric * * // TODO: Find a better word for `thing`. */ -case class Entity(name: String, category: String, tags: Map[String, String]) +case class Entity(name: String, category: String, tags: Map[String, String]) { + if(name == null) Entity.log.warn("Entity with name=null created (category: {}), your monitoring will not work as expected!", category) +} object Entity { + + private lazy val log = LoggerFactory.getLogger(classOf[Entity]) + def apply(name: String, category: String): Entity = apply(name, category, Map.empty) diff --git a/kamon-core/src/main/scala/kamon/metric/SubscriptionsDispatcher.scala b/kamon-core/src/main/scala/kamon/metric/SubscriptionsDispatcher.scala index 09bf58ad..ab25173a 100644 --- a/kamon-core/src/main/scala/kamon/metric/SubscriptionsDispatcher.scala +++ b/kamon-core/src/main/scala/kamon/metric/SubscriptionsDispatcher.scala @@ -20,11 +20,12 @@ import akka.actor._ import kamon.metric.SubscriptionsDispatcher._ import kamon.util.{MilliTimestamp, GlobPathFilter} import scala.concurrent.duration.FiniteDuration +import scala.util.control.NonFatal /** * Manages subscriptions to metrics and dispatch snapshots on every tick to all subscribers. */ -private[kamon] class SubscriptionsDispatcher(interval: FiniteDuration, metricsExtension: MetricsModuleImpl) extends Actor { +private[kamon] class SubscriptionsDispatcher(interval: FiniteDuration, metricsExtension: MetricsModuleImpl) extends Actor with ActorLogging { var lastTick = MilliTimestamp.now var oneShotSubscriptions = Map.empty[ActorRef, SubscriptionFilter] var permanentSubscriptions = Map.empty[ActorRef, SubscriptionFilter] @@ -72,7 +73,14 @@ private[kamon] class SubscriptionsDispatcher(interval: FiniteDuration, metricsEx snapshots: Map[Entity, EntitySnapshot]): Unit = { for ((subscriber, filter) ← subscriptions) { - val selection = snapshots.filter(group ⇒ filter.accept(group._1)) + val selection = snapshots.filter(group ⇒ + try filter.accept(group._1) + catch { + case NonFatal(e) => + log.warning("Checking if filter {} accepts snapshot {} failed: {}", filter, group._1, e) + false + } + ) val tickMetrics = TickMetricSnapshot(lastTick, currentTick, selection) subscriber ! tickMetrics -- cgit v1.2.3