diff options
Diffstat (limited to 'kamon-datadog/src')
-rw-r--r-- | kamon-datadog/src/main/scala/kamon/datadog/DatadogMetricsSender.scala | 15 | ||||
-rw-r--r-- | kamon-datadog/src/test/scala/kamon/datadog/DatadogMetricSenderSpec.scala | 22 |
2 files changed, 29 insertions, 8 deletions
diff --git a/kamon-datadog/src/main/scala/kamon/datadog/DatadogMetricsSender.scala b/kamon-datadog/src/main/scala/kamon/datadog/DatadogMetricsSender.scala index 80d4f098..4a73f5aa 100644 --- a/kamon-datadog/src/main/scala/kamon/datadog/DatadogMetricsSender.scala +++ b/kamon-datadog/src/main/scala/kamon/datadog/DatadogMetricsSender.scala @@ -23,7 +23,7 @@ import akka.util.ByteString import kamon.metric.SubscriptionsDispatcher.TickMetricSnapshot import java.text.{ DecimalFormatSymbols, DecimalFormat } import kamon.metric.instrument.{ Counter, Histogram } -import kamon.metric.{ MetricKey, Entity } +import kamon.metric.{ SingleInstrumentEntityRecorder, MetricKey, Entity } import java.util.Locale class DatadogMetricsSender(remote: InetSocketAddress, maxPacketSizeInBytes: Long) extends Actor with UdpExtensionProvider { @@ -90,11 +90,18 @@ class DatadogMetricsSender(remote: InetSocketAddress, maxPacketSizeInBytes: Long def encodeDatadogCounter(count: Long): String = count.toString + "|c" def buildMetricName(entity: Entity, metricKey: MetricKey): String = - s"$appName.${entity.category}.${metricKey.name}" + if (SingleInstrumentEntityRecorder.AllCategories.contains(entity.category)) + s"$appName.${entity.category}" + else + s"$appName.${entity.category}.${metricKey.name}" def buildIdentificationTag(entity: Entity, metricKey: MetricKey): String = { - val normalizedEntityName = entity.name.replace(": ", ":") - s"|#${entity.category}:${normalizedEntityName}" + val normalizedEntityName = entity.name.replace(" ", "") + if (entity.tags.nonEmpty) { + val tagsString = entity.tags.map { case (k, v) ⇒ k + ":" + v } mkString "," + s"|#${entity.category}:${normalizedEntityName},$tagsString" + } else + s"|#${entity.category}:${normalizedEntityName}" } } diff --git a/kamon-datadog/src/test/scala/kamon/datadog/DatadogMetricSenderSpec.scala b/kamon-datadog/src/test/scala/kamon/datadog/DatadogMetricSenderSpec.scala index b35902f9..22ce1f8e 100644 --- a/kamon-datadog/src/test/scala/kamon/datadog/DatadogMetricSenderSpec.scala +++ b/kamon-datadog/src/test/scala/kamon/datadog/DatadogMetricSenderSpec.scala @@ -96,7 +96,20 @@ class DatadogMetricSenderSpec extends BaseKamonSpec("datadog-metric-sender-spec" val udp = setup(Map(entity -> testRecorder.collect(collectionContext))) val Udp.Send(data, _, _) = udp.expectMsgType[Udp.Send] - data.utf8String should be("kamon.category.metric-one:10|ms|@0.5|#category:datadog\nkamon.category.counter:4|c|#category:datadog\nkamon.category.metric-two:21|ms|#category:datadog") + data.utf8String.split("\n") should contain allOf ( + "kamon.category.metric-one:10|ms|@0.5|#category:datadog", + "kamon.category.metric-two:21|ms|#category:datadog", + "kamon.category.counter:4|c|#category:datadog") + } + + "include all entity tags, if available in the metric packet" in new UdpListenerFixture { + val (entity, testRecorder) = buildRecorder("datadog", tags = Map("my-cool-tag" -> "some-value")) + testRecorder.metricTwo.record(10L, 2) + + val udp = setup(Map(entity -> testRecorder.collect(collectionContext))) + val Udp.Send(data, _, _) = udp.expectMsgType[Udp.Send] + + data.utf8String should be(s"kamon.category.metric-two:10|ms|@0.5|#category:datadog,my-cool-tag:some-value") } } @@ -105,9 +118,10 @@ class DatadogMetricSenderSpec extends BaseKamonSpec("datadog-metric-sender-spec" val localhostName = ManagementFactory.getRuntimeMXBean.getName.split('@')(1) val testMaxPacketSize = system.settings.config.getBytes("kamon.datadog.max-packet-size") - def buildRecorder(name: String): (Entity, TestEntityRecorder) = { - val registration = Kamon.metrics.register(TestEntityRecorder, name).get - (registration.entity, registration.recorder) + def buildRecorder(name: String, tags: Map[String, String] = Map.empty): (Entity, TestEntityRecorder) = { + val entity = Entity(name, TestEntityRecorder.category, tags) + val recorder = Kamon.metrics.entity(TestEntityRecorder, entity) + (entity, recorder) } def setup(metrics: Map[Entity, EntitySnapshot]): TestProbe = { |