aboutsummaryrefslogtreecommitdiff
path: root/kamon-core/src/test/scala/kamon/metric/FilterSpec.scala
diff options
context:
space:
mode:
authorIvan Topolnjak <ivantopo@gmail.com>2017-05-25 16:52:52 +0200
committerIvan Topolnjak <ivantopo@gmail.com>2017-05-25 16:52:52 +0200
commita3d78ef61a277b0b62dc93daf84756dfa7625d3d (patch)
tree4fee7ce93ecfb4e32c7aaaa22efb75ed07c667f6 /kamon-core/src/test/scala/kamon/metric/FilterSpec.scala
parent22379d3f318b2cd3a4c995ff1c45bda33d935a46 (diff)
downloadKamon-a3d78ef61a277b0b62dc93daf84756dfa7625d3d.tar.gz
Kamon-a3d78ef61a277b0b62dc93daf84756dfa7625d3d.tar.bz2
Kamon-a3d78ef61a277b0b62dc93daf84756dfa7625d3d.zip
trying to flatten out the structure and eliminate the notion of entitites
Diffstat (limited to 'kamon-core/src/test/scala/kamon/metric/FilterSpec.scala')
-rw-r--r--kamon-core/src/test/scala/kamon/metric/FilterSpec.scala69
1 files changed, 69 insertions, 0 deletions
diff --git a/kamon-core/src/test/scala/kamon/metric/FilterSpec.scala b/kamon-core/src/test/scala/kamon/metric/FilterSpec.scala
new file mode 100644
index 00000000..095c9426
--- /dev/null
+++ b/kamon-core/src/test/scala/kamon/metric/FilterSpec.scala
@@ -0,0 +1,69 @@
+package kamon
+package metric
+
+import com.typesafe.config.ConfigFactory
+import org.scalatest.{Matchers, WordSpec}
+
+
+class FilterSpec extends WordSpec with Matchers {
+ val testConfig = ConfigFactory.parseString(
+ """
+ |kamon.metric.filters {
+ | accept-unmatched-categories = false
+ |
+ | some-category {
+ | includes = ["**"]
+ | excludes = ["not-me"]
+ | }
+ |
+ | only-includes {
+ | includes = ["only-me"]
+ | }
+ |
+ | only-excludes {
+ | excludes = ["not-me"]
+ | }
+ |
+ | specific-rules {
+ | includes = ["glob:/user/**", "regex:test-[0-5]"]
+ | }
+ |}
+ """.stripMargin
+ )
+
+ "the entity filters" should {
+ "use the accept-unmatched-categories setting when there is no configuration for a given category" in {
+ val acceptUnmatched = Filter.fromConfig(ConfigFactory.parseString("kamon.metric.filters.accept-unmatched-categories=true"))
+ val rejectUnmatched = Filter.fromConfig(ConfigFactory.parseString("kamon.metric.filters.accept-unmatched-categories=false"))
+
+ acceptUnmatched.accept(Entity("a", "b", Map.empty)) shouldBe true
+ rejectUnmatched.accept(Entity("a", "b", Map.empty)) shouldBe false
+ }
+
+ "accept entities that are matched by any include and none exclude filters" in {
+ val entityFilter = Filter.fromConfig(testConfig)
+
+ entityFilter.accept(Entity("anything", "anything", Map.empty)) shouldBe false
+ entityFilter.accept(Entity("anything", "some-category", Map.empty)) shouldBe true
+ entityFilter.accept(Entity("not-me", "some-category", Map.empty)) shouldBe false
+ }
+
+ "allow configuring includes only or excludes only for any category" in {
+ val entityFilter = Filter.fromConfig(testConfig)
+
+ entityFilter.accept(Entity("only-me", "only-includes", Map.empty)) shouldBe true
+ entityFilter.accept(Entity("anything", "only-includes", Map.empty)) shouldBe false
+ entityFilter.accept(Entity("any-other", "only-excludes", Map.empty)) shouldBe false
+ entityFilter.accept(Entity("not-me", "only-excludes", Map.empty)) shouldBe false
+ }
+
+ "allow to explicitly decide whether patterns are treated as Glob or Regex" in {
+ val entityFilter = Filter.fromConfig(testConfig)
+
+ entityFilter.accept(Entity("/user/accepted", "specific-rules", Map.empty)) shouldBe true
+ entityFilter.accept(Entity("/other/rejected/", "specific-rules", Map.empty)) shouldBe false
+ entityFilter.accept(Entity("test-5", "specific-rules", Map.empty)) shouldBe true
+ entityFilter.accept(Entity("test-6", "specific-rules", Map.empty)) shouldBe false
+ }
+ }
+} \ No newline at end of file