Skip to content

Commit

Permalink
Add support for Filter aggregator
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoballekens committed Nov 28, 2019
1 parent 0855adc commit 40f0b18
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ env:
- secure: AIavbCKXnhwX+sEsCUMYo9Oom+eMC/FzjhbiT/O5ufgGhnZKQBYNTX4z6bJ3zGhwC8UkYbGehcJJD0+pAI9JcqaWURbFKNpYfl8YsRkhNp32PRNMKYGCHOVrqMuXNb9XxueQpZv0Shb4bHDZypK7vZm3Zp9ptemt0pc1fsjDE877hYwveWOzHJ6yKgUnvSIFG03kfXi8AmgljHjTo/qJ5CCzKEO1MAgZDztPEvDDrI4j7spHgtHfvZLCNNWoe41FJkOFJqecEv9jLwC2Vng66NRjkpf8g7bhpFbiSTT/9sRUaYdA4AKyaoN4jlj3X77Ee5T55i9aM7gHNbKJVEH2r85Jwz0pkz2/HDuNDd3Bl+pagQG9pL/VPCVtCAWdX9MFkDmMONR4TbDx2T9JdsfN8GChfll9q4Ziwou0B/1t/h646lUSCL3fMdMozhwHXlfo+8KiRmf9RjSfGBgCsIOAE0cm/RJTc9WdUS5fawAsx9V0c1xUz+9k5sNqBuT+IVe8PJjhvGrHdFzLvAbyWpMTUOo21NsuEI+LfTv2NZBo/Ym7EOCwV9GwXsPchcazphG+OwQs+VdbccaIUeTHUZrTheJSwkNvDwy4Z9PnqPX/9sZTfTw0QBVu8C6AwRTT8CQQKvcn6aYYPU2Ke91vWVlsR9Lklc8xv4B9vkOi5DX3u/M=

after_success:
- '[[ $TRAVIS_BRANCH == "master" ]] && { sbt publish; };'
- '[[ $TRAVIS_BRANCH == "master" ]] && { sbt +publish; };'
- sbt coverageReport coveralls
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,8 @@ object Aggregator {
case class SaveAs(metricName: MetricName, tags: Seq[Tag], ttl: FiniteDuration) extends Aggregator { // TODO ttl should be Option?
override val name = "save_as"
}

case class Filter(operator:String, threshold:KairosCompatibleType) extends Aggregator {
override val name: String = "filter"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ object Formats {

case rangeAgg: RangeAggregator =>
rangeAggregatorWrites.writes(rangeAgg)

case filter:Filter=>
Json.obj(
"name" -> filter.name,
"filter_op" -> filter.operator,
"threshold" -> filter.threshold
)
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/test/scala/unit/AggregatorWritesSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import io.waylay.kairosdb.driver.models.json.Formats._
import io.waylay.kairosdb.driver.models.Aggregator.Trim.{TrimBoth, TrimFirst, TrimLast}
import io.waylay.kairosdb.driver.models.{MetricName, Tag}
import io.waylay.kairosdb.driver.models.Aggregator._
import io.waylay.kairosdb.driver.models.KairosCompatibleType.{KNumber, KString}
import io.waylay.kairosdb.driver.models.RangeAggregator.Align._
import io.waylay.kairosdb.driver.models.TimeSpan.AbsoluteStartTime
import org.specs2.mutable.Specification
Expand Down Expand Up @@ -453,4 +454,21 @@ class AggregatorWritesSpec extends Specification {
)
}
}

"Filter aggregator" should {
"correctly serialize with number threshold" in {
Json.toJson(Filter("lt", KNumber(3.7997))) should be equalTo Json.obj(
"name" -> "filter",
"filter_op" -> "lt",
"threshold" -> 3.7997
)
}
"correctly serialize with string threshold" in {
Json.toJson(Filter("eq", KString("3.7997"))) should be equalTo Json.obj(
"name" -> "filter",
"filter_op" -> "eq",
"threshold" -> "3.7997"
)
}
}
}

0 comments on commit 40f0b18

Please sign in to comment.