diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2017-07-12 12:35:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-12 12:35:33 +0200 |
commit | ac3b72e27765ceec4cc3958b0fa7eaba0299f017 (patch) | |
tree | 11cfe2100a59ab6af800293707ab6266dd2195ec /kamon-core/src/test | |
parent | 52c4503b6aea2309feeb550b7db2e5fa627dedc8 (diff) | |
parent | 6c0a8fb6395fca11b48f7ad1cd2bd774f90ee7fd (diff) | |
download | Kamon-ac3b72e27765ceec4cc3958b0fa7eaba0299f017.tar.gz Kamon-ac3b72e27765ceec4cc3958b0fa7eaba0299f017.tar.bz2 Kamon-ac3b72e27765ceec4cc3958b0fa7eaba0299f017.zip |
Merge pull request #479 from mladens/kamon-1.0-develop
Kamon 1.0 develop
Diffstat (limited to 'kamon-core/src/test')
-rw-r--r-- | kamon-core/src/test/scala/kamon/trace/SpanMetrics.scala | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/kamon-core/src/test/scala/kamon/trace/SpanMetrics.scala b/kamon-core/src/test/scala/kamon/trace/SpanMetrics.scala new file mode 100644 index 00000000..a4ce9882 --- /dev/null +++ b/kamon-core/src/test/scala/kamon/trace/SpanMetrics.scala @@ -0,0 +1,66 @@ +package kamon.trace + +import kamon.Kamon +import kamon.Kamon.buildSpan +import kamon.metric._ +import org.scalatest.{Matchers, WordSpecLike} + +class SpanMetrics extends WordSpecLike with Matchers { + import SpanMetricsTestHelper._ + + val errorTag = "error" -> Span.BooleanTagTrueValue + val histogramMetric: HistogramMetric = Kamon.histogram("span.elapsed-time") + + "Span Metrics" should { + "be recorded for successeful execution" in { + val operation = "span-success" + val operationTag = "operation" -> operation + + val span = buildSpan(operation).startManual() + span.finish() + + + val histogram = histogramMetric.refine(operationTag) + histogram.distribution().count === 1 + + val errorHistogram = histogramMetric.refine(operationTag, errorTag).distribution() + errorHistogram.count === 0 + + } + + "record correctly error latency and count" in { + val operation = "span-failure" + val operationTag = "operation" -> operation + + val span = buildSpan(operation).startManual() + span.setTag("error", Span.BooleanTagTrueValue) + span.finish() + + val histogram = histogramMetric.refine(operationTag) + histogram.distribution().count === 0 + + val errorHistogram = histogramMetric.refine(operationTag, errorTag).distribution() + errorHistogram.count === 1 + + } + } + +} + +object SpanMetricsTestHelper { + + implicit class HistogramMetricSyntax(histogram: Histogram) { + def distribution(resetState: Boolean = true): Distribution = + histogram match { + case hm: HistogramMetric => hm.refine(Map.empty[String, String]).distribution(resetState) + case h: AtomicHdrHistogram => h.snapshot(resetState).distribution + case h: HdrHistogram => h.snapshot(resetState).distribution + } + } + + + +} + + + |