aboutsummaryrefslogtreecommitdiff
path: root/kamon-core-tests/src/test/scala/kamon/instrumentation/MetricGroupSpec.scala
diff options
context:
space:
mode:
authorDiego Parra <diegolparra@gmail.com>2018-11-30 02:25:37 -0300
committerGitHub <noreply@github.com>2018-11-30 02:25:37 -0300
commit55e052f0da580296c9b273612c50c57f8ad4206d (patch)
tree8d89a849cee4dc039073db2223efdff8fce855aa /kamon-core-tests/src/test/scala/kamon/instrumentation/MetricGroupSpec.scala
parentfe367087830db4dd147e5d92fb6bf689114871dc (diff)
parentb068f55387e0cfe92b3ec403132d5c851d51eb00 (diff)
downloadKamon-55e052f0da580296c9b273612c50c57f8ad4206d.tar.gz
Kamon-55e052f0da580296c9b273612c50c57f8ad4206d.tar.bz2
Kamon-55e052f0da580296c9b273612c50c57f8ad4206d.zip
Merge pull request #561 from ivantopo/metric-group
add a simple metric group utility for instrumentations
Diffstat (limited to 'kamon-core-tests/src/test/scala/kamon/instrumentation/MetricGroupSpec.scala')
-rw-r--r--kamon-core-tests/src/test/scala/kamon/instrumentation/MetricGroupSpec.scala62
1 files changed, 62 insertions, 0 deletions
diff --git a/kamon-core-tests/src/test/scala/kamon/instrumentation/MetricGroupSpec.scala b/kamon-core-tests/src/test/scala/kamon/instrumentation/MetricGroupSpec.scala
new file mode 100644
index 00000000..0b823bc4
--- /dev/null
+++ b/kamon-core-tests/src/test/scala/kamon/instrumentation/MetricGroupSpec.scala
@@ -0,0 +1,62 @@
+package kamon.instrumentation
+
+import kamon.Kamon
+import kamon.testkit.MetricInspection
+import org.scalatest.{Matchers, WordSpec}
+
+class MetricGroupSpec extends WordSpec with MetricInspection with Matchers {
+
+ "a Metric Group" should {
+ "register metrics with common tags and remove them when cleaning up" in {
+ val group = new CommonTagsOnly(Map("type" -> "common"))
+
+ Counter.valuesForTag("type") should contain only("common")
+ Gauge.valuesForTag("type") should contain only("common")
+ Histogram.valuesForTag("type") should contain only("common")
+ RangeSampler.valuesForTag("type") should contain only("common")
+
+ group.cleanup()
+
+ Counter.valuesForTag("type") shouldBe empty
+ Gauge.valuesForTag("type") shouldBe empty
+ Histogram.valuesForTag("type") shouldBe empty
+ RangeSampler.valuesForTag("type") shouldBe empty
+ }
+
+ "override common tags with tags supplied to the tag method" in {
+ val group = new MixedTags(Map("type" -> "basic"))
+
+ Counter.valuesForTag("type") should contain only("basic")
+ Gauge.valuesForTag("type") should contain only("simple")
+ Histogram.valuesForTag("type") should contain only("tuple")
+ RangeSampler.valuesForTag("type") should contain only("map")
+
+ group.cleanup()
+
+ Counter.valuesForTag("type") shouldBe empty
+ Gauge.valuesForTag("type") shouldBe empty
+ Histogram.valuesForTag("type") shouldBe empty
+ RangeSampler.valuesForTag("type") shouldBe empty
+ }
+ }
+
+
+ val Counter = Kamon.counter("metric.group.counter")
+ val Gauge = Kamon.gauge("metric.group.gauge")
+ val Histogram = Kamon.histogram("metric.group.histogram")
+ val RangeSampler = Kamon.rangeSampler("metric.group.range-sampler")
+
+ class CommonTagsOnly(tags: Map[String, String]) extends MetricGroup(tags) {
+ val counter = tag(Counter)
+ val gauge = tag(Gauge)
+ val histogram = tag(Histogram)
+ val rangeSampler = tag(RangeSampler)
+ }
+
+ class MixedTags(tags: Map[String, String]) extends MetricGroup(tags) {
+ val counter = tag(Counter)
+ val gauge = tag(Gauge, "type", "simple")
+ val histogram = tag(Histogram, "type" -> "tuple")
+ val rangeSampler = tag(RangeSampler, Map("type" -> "map"))
+ }
+}