diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2017-11-06 13:20:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-06 13:20:35 +0100 |
commit | 7a21134e8e0b2296ec98061643ada2e3f68d479a (patch) | |
tree | c6444e09010d6132c23bcf3edabb08e931efd015 /kamon-testkit/src/main | |
parent | aa115a2b348036b7dc7fb9afafe58240b1dd9193 (diff) | |
parent | 0b5d9100c63f56fbf2a14b4de1a22357e588d03b (diff) | |
download | Kamon-7a21134e8e0b2296ec98061643ada2e3f68d479a.tar.gz Kamon-7a21134e8e0b2296ec98061643ada2e3f68d479a.tar.bz2 Kamon-7a21134e8e0b2296ec98061643ada2e3f68d479a.zip |
Merge pull request #487 from mladens/kamon-1.0-develop
Additional metric inspections
Diffstat (limited to 'kamon-testkit/src/main')
-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) { |