diff options
author | mladens <mladens42@gmail.com> | 2017-10-31 16:07:07 +0100 |
---|---|---|
committer | mladens <mladens42@gmail.com> | 2017-10-31 16:07:07 +0100 |
commit | 0b5d9100c63f56fbf2a14b4de1a22357e588d03b (patch) | |
tree | 3adfaa85eea05e7c1741712d1238c9e93b75e0c4 /kamon-testkit/src/main/scala/kamon/testkit | |
parent | ead4fd7743895ffe1d34e37c23eceab575fb907e (diff) | |
download | Kamon-0b5d9100c63f56fbf2a14b4de1a22357e588d03b.tar.gz Kamon-0b5d9100c63f56fbf2a14b4de1a22357e588d03b.tar.bz2 Kamon-0b5d9100c63f56fbf2a14b4de1a22357e588d03b.zip |
Additional metric inspections
Diffstat (limited to 'kamon-testkit/src/main/scala/kamon/testkit')
-rw-r--r-- | kamon-testkit/src/main/scala/kamon/testkit/MetricInspection.scala | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/kamon-testkit/src/main/scala/kamon/testkit/MetricInspection.scala b/kamon-testkit/src/main/scala/kamon/testkit/MetricInspection.scala index bb6d27f9..be340df9 100644 --- a/kamon-testkit/src/main/scala/kamon/testkit/MetricInspection.scala +++ b/kamon-testkit/src/main/scala/kamon/testkit/MetricInspection.scala @@ -15,7 +15,7 @@ package kamon.testkit -import kamon.metric._ +import kamon.metric.{BaseMetric, _} import _root_.scala.collection.concurrent.TrieMap @@ -30,6 +30,27 @@ trait MetricInspection { val instrumentsWithTheTag = instruments.keys.filter(_.keys.exists(_ == tag)) instrumentsWithTheTag.map(t => t(tag)).toSeq } + + def partialRefine(tags: Map[String, String]): Seq[Map[String, String]] = { + val instrumentsField = classOf[BaseMetric[_, _]].getDeclaredField("instruments") + instrumentsField.setAccessible(true) + + val instruments = instrumentsField.get(metric).asInstanceOf[TrieMap[Map[String, String], _]] + + instruments.keys.filter { metricKey => + tags.toSeq.forall { case (k, v) => + metricKey.contains(k) && metricKey(k) == v + } + }.toSeq + } + + def partialRefineKeys(tags: Set[String]): Seq[Map[String, String]] = { + val instrumentsField = classOf[BaseMetric[_, _]].getDeclaredField("instruments") + instrumentsField.setAccessible(true) + + val instruments = instrumentsField.get(metric).asInstanceOf[TrieMap[Map[String, String], _]] + instruments.keys.filter(key => tags.subsetOf(key.keySet)).toSeq + } } implicit class HistogramMetricSyntax(histogram: Histogram) { |