From 6b196b2626f618e452a25e9437c944ff4138636c Mon Sep 17 00:00:00 2001 From: Ivan Topolnjak Date: Tue, 5 Dec 2017 02:11:34 +0100 Subject: rename MinMaxCounter to RangeSampler --- .../test/scala/kamon/metric/MetricLookupSpec.scala | 20 ++-- .../scala/kamon/metric/MinMaxCounterSpec.scala | 90 ---------------- .../test/scala/kamon/metric/RangeSamplerSpec.scala | 90 ++++++++++++++++ .../scala/kamon/metric/RecorderRegistrySpec.scala | 58 ----------- .../metric/instrument/InstrumentFactorySpec.scala | 114 --------------------- 5 files changed, 100 insertions(+), 272 deletions(-) delete mode 100644 kamon-core-tests/src/test/scala/kamon/metric/MinMaxCounterSpec.scala create mode 100644 kamon-core-tests/src/test/scala/kamon/metric/RangeSamplerSpec.scala delete mode 100644 kamon-core-tests/src/test/scala/kamon/metric/RecorderRegistrySpec.scala delete mode 100644 kamon-core-tests/src/test/scala/kamon/metric/instrument/InstrumentFactorySpec.scala (limited to 'kamon-core-tests') diff --git a/kamon-core-tests/src/test/scala/kamon/metric/MetricLookupSpec.scala b/kamon-core-tests/src/test/scala/kamon/metric/MetricLookupSpec.scala index 4df2397b..f6c27b5b 100644 --- a/kamon-core-tests/src/test/scala/kamon/metric/MetricLookupSpec.scala +++ b/kamon-core-tests/src/test/scala/kamon/metric/MetricLookupSpec.scala @@ -42,10 +42,10 @@ class MetricLookupSpec extends WordSpec with Matchers { gaugeOne shouldBe theSameInstanceAs(gaugeTwo) } - "always return the same min-max-counter metric" in { - val minMaxCounterOne = Kamon.minMaxCounter("min-max-counter-lookup") - val minMaxCounterTwo = Kamon.minMaxCounter("min-max-counter-lookup") - minMaxCounterOne shouldBe theSameInstanceAs(minMaxCounterTwo) + "always return the same range sampler metric" in { + val rangeSamplerOne = Kamon.rangeSampler("range-sampler-lookup") + val rangeSamplerTwo = Kamon.rangeSampler("range-sampler-lookup") + rangeSamplerOne shouldBe theSameInstanceAs(rangeSamplerTwo) } } @@ -77,13 +77,13 @@ class MetricLookupSpec extends WordSpec with Matchers { gaugeOne shouldBe theSameInstanceAs(gaugeThree) } - "always return the same min-max-counter for a set of tags" in { - val minMaxCounterOne = Kamon.minMaxCounter("min-max-counter-lookup").refine("tag" -> "value") - val minMaxCounterTwo = Kamon.minMaxCounter("min-max-counter-lookup").refine("tag" -> "value") - val minMaxCounterThree = Kamon.minMaxCounter("min-max-counter-lookup").refine(javaMap("tag", "value")) + "always return the same range-sampler for a set of tags" in { + val rangeSamplerOne = Kamon.rangeSampler("range-sampler-lookup").refine("tag" -> "value") + val rangeSamplerTwo = Kamon.rangeSampler("range-sampler-lookup").refine("tag" -> "value") + val rangeSamplerThree = Kamon.rangeSampler("range-sampler-lookup").refine(javaMap("tag", "value")) - minMaxCounterOne shouldBe theSameInstanceAs(minMaxCounterTwo) - minMaxCounterOne shouldBe theSameInstanceAs(minMaxCounterThree) + rangeSamplerOne shouldBe theSameInstanceAs(rangeSamplerTwo) + rangeSamplerOne shouldBe theSameInstanceAs(rangeSamplerThree) } } } diff --git a/kamon-core-tests/src/test/scala/kamon/metric/MinMaxCounterSpec.scala b/kamon-core-tests/src/test/scala/kamon/metric/MinMaxCounterSpec.scala deleted file mode 100644 index 0ad3c45c..00000000 --- a/kamon-core-tests/src/test/scala/kamon/metric/MinMaxCounterSpec.scala +++ /dev/null @@ -1,90 +0,0 @@ -/* ========================================================================================= - * Copyright © 2013-2017 the kamon project - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the - * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions - * and limitations under the License. - * ========================================================================================= - */ - - -package kamon.metric - -import java.time.Duration - -import org.scalatest.{Matchers, WordSpec} - -case class TemporalBucket(value: Long, frequency: Long) extends Bucket - -class MinMaxCounterSpec extends WordSpec with Matchers { - - "a MinMaxCounter" should { - "track ascending tendencies" in { - val mmCounter = buildMinMaxCounter("track-ascending") - mmCounter.increment() - mmCounter.increment(3) - mmCounter.increment() - - mmCounter.sample() - - val snapshot = mmCounter.snapshot() - - snapshot.distribution.min should be(0) - snapshot.distribution.max should be(5) - } - - "track descending tendencies" in { - val mmCounter = buildMinMaxCounter("track-descending") - mmCounter.increment(5) - mmCounter.decrement() - mmCounter.decrement(3) - mmCounter.decrement() - - mmCounter.sample() - - val snapshot = mmCounter.snapshot() - snapshot.distribution.min should be(0) - snapshot.distribution.max should be(5) - } - - "reset the min and max to the current value after taking a snapshot" in { - val mmCounter = buildMinMaxCounter("reset-min-max-to-current") - - mmCounter.increment(5) - mmCounter.decrement(3) - mmCounter.sample() - - val firstSnapshot = mmCounter.snapshot() - firstSnapshot.distribution.min should be(0) - firstSnapshot.distribution.max should be(5) - - mmCounter.sample() - - val secondSnapshot = mmCounter.snapshot() - secondSnapshot.distribution.min should be(2) - secondSnapshot.distribution.max should be(2) - } - - "report zero as the min and current values if the current value fell bellow zero" in { - val mmCounter = buildMinMaxCounter("report-zero") - - mmCounter.decrement(3) - - mmCounter.sample() - - val snapshot = mmCounter.snapshot() - - snapshot.distribution.min should be(0) - snapshot.distribution.max should be(0) - } - } - - def buildMinMaxCounter(name: String, tags: Map[String, String] = Map.empty, unit: MeasurementUnit = MeasurementUnit.none): SimpleMinMaxCounter = - new SimpleMinMaxCounter(name, tags, new AtomicHdrHistogram(name, tags, unit, dynamicRange = DynamicRange.Default), Duration.ofMillis(100)) -} \ No newline at end of file diff --git a/kamon-core-tests/src/test/scala/kamon/metric/RangeSamplerSpec.scala b/kamon-core-tests/src/test/scala/kamon/metric/RangeSamplerSpec.scala new file mode 100644 index 00000000..3aaf57a4 --- /dev/null +++ b/kamon-core-tests/src/test/scala/kamon/metric/RangeSamplerSpec.scala @@ -0,0 +1,90 @@ +/* ========================================================================================= + * Copyright © 2013-2017 the kamon project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + * ========================================================================================= + */ + + +package kamon.metric + +import java.time.Duration + +import org.scalatest.{Matchers, WordSpec} + +case class TemporalBucket(value: Long, frequency: Long) extends Bucket + +class RangeSamplerSpec extends WordSpec with Matchers { + + "a RangeSampler" should { + "track ascending tendencies" in { + val rangeSampler = buildRangeSampler("track-ascending") + rangeSampler.increment() + rangeSampler.increment(3) + rangeSampler.increment() + + rangeSampler.sample() + + val snapshot = rangeSampler.snapshot() + + snapshot.distribution.min should be(0) + snapshot.distribution.max should be(5) + } + + "track descending tendencies" in { + val rangeSampler = buildRangeSampler("track-descending") + rangeSampler.increment(5) + rangeSampler.decrement() + rangeSampler.decrement(3) + rangeSampler.decrement() + + rangeSampler.sample() + + val snapshot = rangeSampler.snapshot() + snapshot.distribution.min should be(0) + snapshot.distribution.max should be(5) + } + + "reset the min and max to the current value after taking a snapshot" in { + val rangeSampler = buildRangeSampler("reset-range-sampler-to-current") + + rangeSampler.increment(5) + rangeSampler.decrement(3) + rangeSampler.sample() + + val firstSnapshot = rangeSampler.snapshot() + firstSnapshot.distribution.min should be(0) + firstSnapshot.distribution.max should be(5) + + rangeSampler.sample() + + val secondSnapshot = rangeSampler.snapshot() + secondSnapshot.distribution.min should be(2) + secondSnapshot.distribution.max should be(2) + } + + "report zero as the min and current values if the current value fell bellow zero" in { + val rangeSampler = buildRangeSampler("report-zero") + + rangeSampler.decrement(3) + + rangeSampler.sample() + + val snapshot = rangeSampler.snapshot() + + snapshot.distribution.min should be(0) + snapshot.distribution.max should be(0) + } + } + + def buildRangeSampler(name: String, tags: Map[String, String] = Map.empty, unit: MeasurementUnit = MeasurementUnit.none): SimpleRangeSampler = + new SimpleRangeSampler(name, tags, new AtomicHdrHistogram(name, tags, unit, dynamicRange = DynamicRange.Default), Duration.ofMillis(100)) +} \ No newline at end of file diff --git a/kamon-core-tests/src/test/scala/kamon/metric/RecorderRegistrySpec.scala b/kamon-core-tests/src/test/scala/kamon/metric/RecorderRegistrySpec.scala deleted file mode 100644 index 1053aa5f..00000000 --- a/kamon-core-tests/src/test/scala/kamon/metric/RecorderRegistrySpec.scala +++ /dev/null @@ -1,58 +0,0 @@ -/* ========================================================================================= - * Copyright © 2013-2017 the kamon project - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the - * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions - * and limitations under the License. - * ========================================================================================= - */ - -package kamon.metric - -import com.typesafe.config.ConfigFactory -import org.scalatest.{Matchers, WordSpec} - -//class RecorderRegistrySpec extends WordSpec with Matchers { -// private val testConfig = ConfigFactory.parseString( -// """ -// |kamon.metric.filters { -// | accept-unmatched = false -// | -// | my-category { -// | includes = ["**"] -// | excludes = ["excluded"] -// | } -// |} -// """.stripMargin -// ) -// private val recorderRegistry = new RecorderRegistryImpl(testConfig.withFallback(ConfigFactory.load())) -// -// -// "the RecorderRegistry" should { -// "create entity recorders as requested and always return the same instance for a given entity" in { -// val myFirstEntityRecorder = recorderRegistry.getRecorder(Entity("my-entity", "my-category", Map.empty)) -// val mySecondEntityRecorder = recorderRegistry.getRecorder(Entity("my-entity", "my-category", Map.empty)) -// mySecondEntityRecorder shouldBe theSameInstanceAs(myFirstEntityRecorder) -// } -// -// "properly advice regarding entity filtering read from configuration" in { -// recorderRegistry.shouldTrack(Entity("my-entity", "my-category", Map.empty)) shouldBe true -// recorderRegistry.shouldTrack(Entity("other-eny", "my-category", Map.empty)) shouldBe true -// recorderRegistry.shouldTrack(Entity("excluded", "my-category", Map.empty)) shouldBe false -// } -// -// "allow removing entities" in { -// val myFirstEntityRecorder = recorderRegistry.getRecorder(Entity("my-entity", "my-category", Map.empty)) -// recorderRegistry.removeRecorder(Entity("my-entity", "my-category", Map.empty)) -// -// val mySecondEntityRecorder = recorderRegistry.getRecorder(Entity("my-entity", "my-category", Map.empty)) -// mySecondEntityRecorder shouldNot be theSameInstanceAs(myFirstEntityRecorder) -// } -// } -//} diff --git a/kamon-core-tests/src/test/scala/kamon/metric/instrument/InstrumentFactorySpec.scala b/kamon-core-tests/src/test/scala/kamon/metric/instrument/InstrumentFactorySpec.scala deleted file mode 100644 index 21fe2b4d..00000000 --- a/kamon-core-tests/src/test/scala/kamon/metric/instrument/InstrumentFactorySpec.scala +++ /dev/null @@ -1,114 +0,0 @@ -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( -// """ -// |kamon.metric.instrument-factory { -// | 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.fromConfig(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.fromConfig(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( -// """ -// |kamon.metric.instrument-factory.custom-settings { -// | custom-category { -// | modified-histogram { -// | lowest-discernible-value = 99 -// | highest-trackable-value = 999 -// | significant-value-digits = 4 -// | } -// | -// | 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.fromConfig(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(4) -// -// -// 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)) -// } -// } -//} -- cgit v1.2.3