diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2014-07-10 20:53:39 -0300 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2014-07-10 20:53:39 -0300 |
commit | 9d81b6cf128859030f393c07a7d08abc464acbcf (patch) | |
tree | e896733d882501541ff83bd76b23d8e83b1e24fc /kamon-statsd/src/test/scala/kamon/statsd | |
parent | 3686990509d004b53f5c069a5353d0484556eb2e (diff) | |
download | Kamon-9d81b6cf128859030f393c07a7d08abc464acbcf.tar.gz Kamon-9d81b6cf128859030f393c07a7d08abc464acbcf.tar.bz2 Kamon-9d81b6cf128859030f393c07a7d08abc464acbcf.zip |
! statsd,datadog: reformat metric names to get a better display of automatically named traces, closes #35
After a bit of testing it seems like instead of generating more friendly names by default, we need to do
changes that are specific to each module (StatsD and Datadog) in order to make it work properly. Here is
a list of the introduced changes:
- StatsD
- Change dots (.) to underscores (_) on the host name string.
- Change ': ' to single underscore and spaced to underscore. Userful for automatically generated http
trace names.
- Change '/' to underscore. Ideally the dashboard could replace '_' with '/' to display it like a path.
- Datadog
- Change ': ' to ':'. Userful for automatically generated http trace names.
Diffstat (limited to 'kamon-statsd/src/test/scala/kamon/statsd')
-rw-r--r-- | kamon-statsd/src/test/scala/kamon/statsd/StatsDMetricSenderSpec.scala | 72 |
1 files changed, 49 insertions, 23 deletions
diff --git a/kamon-statsd/src/test/scala/kamon/statsd/StatsDMetricSenderSpec.scala b/kamon-statsd/src/test/scala/kamon/statsd/StatsDMetricSenderSpec.scala index 60d52491..3bc1364c 100644 --- a/kamon-statsd/src/test/scala/kamon/statsd/StatsDMetricSenderSpec.scala +++ b/kamon-statsd/src/test/scala/kamon/statsd/StatsDMetricSenderSpec.scala @@ -30,15 +30,31 @@ import java.net.InetSocketAddress import com.typesafe.config.ConfigFactory class StatsDMetricSenderSpec extends TestKitBase with WordSpecLike with Matchers { - implicit lazy val system = ActorSystem("statsd-metric-sender-spec", - ConfigFactory.parseString("kamon.statsd.max-packet-size = 256 bytes")) + implicit lazy val system: ActorSystem = ActorSystem("statsd-metric-sender-spec", ConfigFactory.parseString( + """ + |kamon { + | metrics { + | disable-aspectj-weaver-missing-error = true + | } + | + | statsd { + | max-packet-size = 256 bytes + | } + |} + | + """.stripMargin)) val collectionContext = Kamon(Metrics).buildDefaultCollectionContext "the StatsDMetricSender" should { + "normalize the group entity name to remove spaces, colons and replace '/' with '_'" in new UdpListenerFixture { + val testMetricKey = buildMetricKey("trace", "POST: /kamon/example", "elapsed-time") + testMetricKey should be(s"kamon.localhost_local.trace.POST-_kamon_example.elapsed-time") + } + "flush the metrics data after processing the tick, even if the max-packet-size is not reached" in new UdpListenerFixture { - val testMetricName = "test-metric" - val testMetricKey = buildMetricKey(testMetricName) + val testMetricName = "processing-time" + val testMetricKey = buildMetricKey("actor", "/user/kamon", testMetricName) val testRecorder = Histogram(1000L, Precision.Normal, Scale.Unit) testRecorder.record(10L) @@ -49,8 +65,8 @@ class StatsDMetricSenderSpec extends TestKitBase with WordSpecLike with Matchers } "render several measurements of the same key under a single (key + multiple measurements) packet" in new UdpListenerFixture { - val testMetricName = "test-metric" - val testMetricKey = buildMetricKey(testMetricName) + val testMetricName = "processing-time" + val testMetricKey = buildMetricKey("actor", "/user/kamon", testMetricName) val testRecorder = Histogram(1000L, Precision.Normal, Scale.Unit) testRecorder.record(10L) testRecorder.record(11L) @@ -63,8 +79,8 @@ class StatsDMetricSenderSpec extends TestKitBase with WordSpecLike with Matchers } "include the correspondent sampling rate when rendering multiple occurrences of the same value" in new UdpListenerFixture { - val testMetricName = "test-metric" - val testMetricKey = buildMetricKey(testMetricName) + val testMetricName = "processing-time" + val testMetricKey = buildMetricKey("actor", "/user/kamon", testMetricName) val testRecorder = Histogram(1000L, Precision.Normal, Scale.Unit) testRecorder.record(10L) testRecorder.record(10L) @@ -76,8 +92,8 @@ class StatsDMetricSenderSpec extends TestKitBase with WordSpecLike with Matchers } "flush the packet when the max-packet-size is reached" in new UdpListenerFixture { - val testMetricName = "test-metric" - val testMetricKey = buildMetricKey(testMetricName) + val testMetricName = "processing-time" + val testMetricKey = buildMetricKey("actor", "/user/kamon", testMetricName) val testRecorder = Histogram(10000L, Precision.Normal, Scale.Unit) var bytes = testMetricKey.length @@ -97,9 +113,9 @@ class StatsDMetricSenderSpec extends TestKitBase with WordSpecLike with Matchers "render multiple keys in the same packet using newline as separator" in new UdpListenerFixture { val firstTestMetricName = "first-test-metric" - val firstTestMetricKey = buildMetricKey(firstTestMetricName) + val firstTestMetricKey = buildMetricKey("actor", "/user/kamon", firstTestMetricName) val secondTestMetricName = "second-test-metric" - val secondTestMetricKey = buildMetricKey(secondTestMetricName) + val secondTestMetricKey = buildMetricKey("actor", "/user/kamon", secondTestMetricName) val firstTestRecorder = Histogram(1000L, Precision.Normal, Scale.Unit) val secondTestRecorder = Histogram(1000L, Precision.Normal, Scale.Unit) @@ -121,14 +137,32 @@ class StatsDMetricSenderSpec extends TestKitBase with WordSpecLike with Matchers } trait UdpListenerFixture { - val localhostName = ManagementFactory.getRuntimeMXBean.getName.split('@')(1) val testMaxPacketSize = system.settings.config.getBytes("kamon.statsd.max-packet-size") + val metricKeyGenerator = new SimpleMetricKeyGenerator(system.settings.config) { + override def normalizedLocalhostName: String = "localhost_local" + } - def buildMetricKey(metricName: String): String = s"kamon.$localhostName.test-metric-category.test-group.$metricName" + val testGroupIdentity = new MetricGroupIdentity { + val name: String = "/user/kamon" + val category: MetricGroupCategory = new MetricGroupCategory { + val name: String = "actor" + } + } + + def buildMetricKey(categoryName: String, entityName: String, metricName: String): String = { + val metricIdentity = new MetricIdentity { val name: String = metricName } + val groupIdentity = new MetricGroupIdentity { + val name: String = entityName + val category: MetricGroupCategory = new MetricGroupCategory { + val name: String = categoryName + } + } + metricKeyGenerator.generateKey(groupIdentity, metricIdentity) + } def setup(metrics: Map[String, MetricSnapshot]): TestProbe = { val udp = TestProbe() - val metricsSender = system.actorOf(Props(new StatsDMetricsSender(new InetSocketAddress(localhostName, 0), testMaxPacketSize) { + val metricsSender = system.actorOf(Props(new StatsDMetricsSender(new InetSocketAddress("127.0.0.1", 0), testMaxPacketSize, metricKeyGenerator) { override def udpExtension(implicit system: ActorSystem): ActorRef = udp.ref })) @@ -136,17 +170,9 @@ class StatsDMetricSenderSpec extends TestKitBase with WordSpecLike with Matchers udp.expectMsgType[Udp.SimpleSender] udp.reply(Udp.SimpleSenderReady) - val testGroupIdentity = new MetricGroupIdentity { - val name: String = "test-group" - val category: MetricGroupCategory = new MetricGroupCategory { - val name: String = "test-metric-category" - } - } - val testMetrics = for ((metricName, snapshot) ← metrics) yield { val testMetricIdentity = new MetricIdentity { val name: String = metricName - val tag: String = "" } (testMetricIdentity, snapshot) |