aboutsummaryrefslogtreecommitdiff
path: root/kamon-core/src/test/scala/kamon/metric/EntityFilterSpec.scala
diff options
context:
space:
mode:
authorIvan Topolnjak <ivantopo@gmail.com>2017-05-20 14:06:03 +0200
committerIvan Topolnjak <ivantopo@gmail.com>2017-05-20 14:06:03 +0200
commite1e7853255131f26702229735e37e160c38f2d08 (patch)
tree98202bb2b62a9c0dd29d0fb7f020da232703844a /kamon-core/src/test/scala/kamon/metric/EntityFilterSpec.scala
parent77f2666650726352a9e15dcf6019064d91393b2e (diff)
downloadKamon-e1e7853255131f26702229735e37e160c38f2d08.tar.gz
Kamon-e1e7853255131f26702229735e37e160c38f2d08.tar.bz2
Kamon-e1e7853255131f26702229735e37e160c38f2d08.zip
implement entity filters
Diffstat (limited to 'kamon-core/src/test/scala/kamon/metric/EntityFilterSpec.scala')
-rw-r--r--kamon-core/src/test/scala/kamon/metric/EntityFilterSpec.scala69
1 files changed, 69 insertions, 0 deletions
diff --git a/kamon-core/src/test/scala/kamon/metric/EntityFilterSpec.scala b/kamon-core/src/test/scala/kamon/metric/EntityFilterSpec.scala
new file mode 100644
index 00000000..15dfc5ff
--- /dev/null
+++ b/kamon-core/src/test/scala/kamon/metric/EntityFilterSpec.scala
@@ -0,0 +1,69 @@
+package kamon
+package metric
+
+import com.typesafe.config.ConfigFactory
+import org.scalatest.{Matchers, WordSpec}
+
+
+class EntityFilterSpec extends WordSpec with Matchers {
+ val testConfig = ConfigFactory.parseString(
+ """
+ |kamon.metric.filters {
+ | accept-unmatched = 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 setting when there is no configuration for a given category" in {
+ val acceptUnmatched = EntityFilter.fromConfig(ConfigFactory.parseString("kamon.metric.filters.accept-unmatched=true"))
+ val rejectUnmatched = EntityFilter.fromConfig(ConfigFactory.parseString("kamon.metric.filters.accept-unmatched=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 = EntityFilter.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 = EntityFilter.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 = EntityFilter.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