aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Grotzke <martin.grotzke@googlemail.com>2017-07-06 17:22:55 +0200
committerDiego Parra <diegolparra@gmail.com>2017-07-06 12:22:55 -0300
commit79c7f9bbbbf775e09b7a02109a77986665be43bc (patch)
tree753cba629f7c24365eb6a41251ac20fa9a5c2355
parent097caeb1f15c24db6d28cb646a064a9f3d5fa80d (diff)
downloadKamon-kamon-0.6.x.tar.gz
Kamon-kamon-0.6.x.tar.bz2
Kamon-kamon-0.6.x.zip
Log warn when Entity with name=null is created / if dispatching entities fails (#475)kamon-0.6.x
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.
-rw-r--r--kamon-core/src/main/scala/kamon/metric/Entity.scala9
-rw-r--r--kamon-core/src/main/scala/kamon/metric/SubscriptionsDispatcher.scala12
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