aboutsummaryrefslogtreecommitdiff
path: root/kamon-core/src/test/scala/kamon/metric/instrument/InstrumentFactorySpec.scala
diff options
context:
space:
mode:
authorIvan Topolnjak <ivantopo@gmail.com>2017-04-24 14:10:46 +0200
committerIvan Topolnjak <ivantopo@gmail.com>2017-04-24 14:17:10 +0200
commitbbd52dcca66caa3cbd78478a1d075ff54da4f65a (patch)
treed121b293a21a14e5d4d19946b44e6008257f8db3 /kamon-core/src/test/scala/kamon/metric/instrument/InstrumentFactorySpec.scala
parent4d828e1a3195e55365c865aa3a78af9668742643 (diff)
downloadKamon-bbd52dcca66caa3cbd78478a1d075ff54da4f65a.tar.gz
Kamon-bbd52dcca66caa3cbd78478a1d075ff54da4f65a.tar.bz2
Kamon-bbd52dcca66caa3cbd78478a1d075ff54da4f65a.zip
bring the new skeleton into place
Diffstat (limited to 'kamon-core/src/test/scala/kamon/metric/instrument/InstrumentFactorySpec.scala')
-rw-r--r--kamon-core/src/test/scala/kamon/metric/instrument/InstrumentFactorySpec.scala112
1 files changed, 112 insertions, 0 deletions
diff --git a/kamon-core/src/test/scala/kamon/metric/instrument/InstrumentFactorySpec.scala b/kamon-core/src/test/scala/kamon/metric/instrument/InstrumentFactorySpec.scala
new file mode 100644
index 00000000..fc82ddcd
--- /dev/null
+++ b/kamon-core/src/test/scala/kamon/metric/instrument/InstrumentFactorySpec.scala
@@ -0,0 +1,112 @@
+package kamon.metric.instrument
+
+import java.time.Duration
+
+import com.typesafe.config.ConfigFactory
+import kamon.metric.Entity
+import org.scalatest.{Matchers, WordSpec}
+
+class InstrumentFactorySpec extends WordSpec with Matchers{
+ val testEntity = Entity("test", "test-category", Map.empty)
+ val customEntity = Entity("test", "custom-category", Map.empty)
+ val baseConfiguration = ConfigFactory.parseString(
+ """
+ |default-settings {
+ | histogram {
+ | lowest-discernible-value = 100
+ | highest-trackable-value = 5000
+ | significant-value-digits = 2
+ | }
+ |
+ | min-max-counter {
+ | lowest-discernible-value = 200
+ | highest-trackable-value = 6000
+ | significant-value-digits = 3
+ | sample-interval = 647 millis
+ | }
+ |}
+ |
+ |custom-settings {
+ |
+ |}
+ """.stripMargin
+ )
+
+
+ "the metrics InstrumentFactory" should {
+ "create instruments using the default configuration settings" in {
+ val factory = InstrumentFactory(baseConfiguration)
+ val histogram = factory.buildHistogram(testEntity, "my-histogram")
+ val mmCounter = factory.buildMinMaxCounter(testEntity, "my-mm-counter")
+
+ histogram.dynamicRange.lowestDiscernibleValue shouldBe(100)
+ histogram.dynamicRange.highestTrackableValue shouldBe(5000)
+ histogram.dynamicRange.significantValueDigits shouldBe(2)
+
+ mmCounter.dynamicRange.lowestDiscernibleValue shouldBe(200)
+ mmCounter.dynamicRange.highestTrackableValue shouldBe(6000)
+ mmCounter.dynamicRange.significantValueDigits shouldBe(3)
+ mmCounter.sampleInterval shouldBe(Duration.ofMillis(647))
+ }
+
+ "accept custom settings when building instruments" in {
+ val factory = InstrumentFactory(baseConfiguration)
+ val histogram = factory.buildHistogram(testEntity, "my-histogram", DynamicRange.Loose)
+ val mmCounter = factory.buildMinMaxCounter(testEntity, "my-mm-counter", DynamicRange.Fine, Duration.ofMillis(500))
+
+ histogram.dynamicRange shouldBe(DynamicRange.Loose)
+
+ mmCounter.dynamicRange shouldBe(DynamicRange.Fine)
+ mmCounter.sampleInterval shouldBe(Duration.ofMillis(500))
+ }
+
+ "allow overriding any default and provided settings via the custom-settings configuration key" in {
+ val customConfig = ConfigFactory.parseString(
+ """
+ |custom-settings {
+ | custom-category {
+ | modified-histogram {
+ | lowest-discernible-value = 99
+ | highest-trackable-value = 999
+ | significant-value-digits = 7
+ | }
+ |
+ | modified-mm-counter {
+ | lowest-discernible-value = 784
+ | highest-trackable-value = 14785
+ | significant-value-digits = 1
+ | sample-interval = 3 seconds
+ | }
+ | }
+ |}
+ """.stripMargin
+ ).withFallback(baseConfiguration)
+
+ val factory = InstrumentFactory(customConfig)
+ val defaultHistogram = factory.buildHistogram(customEntity, "default-histogram")
+ val modifiedHistogram = factory.buildHistogram(customEntity, "modified-histogram", DynamicRange.Loose)
+
+ defaultHistogram.dynamicRange.lowestDiscernibleValue shouldBe(100)
+ defaultHistogram.dynamicRange.highestTrackableValue shouldBe(5000)
+ defaultHistogram.dynamicRange.significantValueDigits shouldBe(2)
+
+ modifiedHistogram.dynamicRange.lowestDiscernibleValue shouldBe(99)
+ modifiedHistogram.dynamicRange.highestTrackableValue shouldBe(999)
+ modifiedHistogram.dynamicRange.significantValueDigits shouldBe(7)
+
+
+ val defaultMMCounter = factory.buildMinMaxCounter(customEntity, "default-mm-counter")
+ val modifiedMMCounter = factory.buildMinMaxCounter(customEntity, "modified-mm-counter", DynamicRange.Loose)
+
+ defaultMMCounter.dynamicRange.lowestDiscernibleValue shouldBe(200)
+ defaultMMCounter.dynamicRange.highestTrackableValue shouldBe(6000)
+ defaultMMCounter.dynamicRange.significantValueDigits shouldBe(3)
+ defaultMMCounter.sampleInterval shouldBe(Duration.ofMillis(647))
+
+ modifiedMMCounter.dynamicRange.lowestDiscernibleValue shouldBe(784)
+ modifiedMMCounter.dynamicRange.highestTrackableValue shouldBe(14785)
+ modifiedMMCounter.dynamicRange.significantValueDigits shouldBe(1)
+ modifiedMMCounter.sampleInterval shouldBe(Duration.ofSeconds(3))
+ }
+ }
+}