aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Topolnjak <ivantopo@gmail.com>2018-06-11 11:18:07 +0200
committerIvan Topolnjak <ivantopo@gmail.com>2018-06-11 11:18:07 +0200
commiteeed5e1614eb0435163506a8a740142b71cbe1f5 (patch)
tree7c873bc5ed68476121b7d735a6394975ff517dad
parent62e2c1bf213b9fedba850262600229f5aa0c2705 (diff)
downloadKamon-eeed5e1614eb0435163506a8a740142b71cbe1f5.tar.gz
Kamon-eeed5e1614eb0435163506a8a740142b71cbe1f5.tar.bz2
Kamon-eeed5e1614eb0435163506a8a740142b71cbe1f5.zip
ensure that histograms snapshots are immutable
-rw-r--r--kamon-core/src/main/scala/kamon/metric/Histogram.scala8
1 files changed, 6 insertions, 2 deletions
diff --git a/kamon-core/src/main/scala/kamon/metric/Histogram.scala b/kamon-core/src/main/scala/kamon/metric/Histogram.scala
index 592dae7d..f06e58c4 100644
--- a/kamon-core/src/main/scala/kamon/metric/Histogram.scala
+++ b/kamon-core/src/main/scala/kamon/metric/Histogram.scala
@@ -117,7 +117,7 @@ private[kamon] trait SnapshotCreation {
val zigZagCounts = Array.ofDim[Byte](buffer.limit())
buffer.get(zigZagCounts)
- val distribution = new ZigZagCountsDistribution(totalCount, minIndex, maxIndex, ByteBuffer.wrap(zigZagCounts),
+ val distribution = new ZigZagCountsDistribution(totalCount, minIndex, maxIndex, ByteBuffer.wrap(zigZagCounts).asReadOnlyBuffer(),
protectedUnitMagnitude(), protectedSubBucketHalfCount(), protectedSubBucketHalfCountMagnitude())
MetricDistribution(name, tags, unit, dynamicRange, distribution)
@@ -130,7 +130,7 @@ private[kamon] object SnapshotCreation {
override def initialValue(): ByteBuffer = ByteBuffer.allocate(33792)
}
- class ZigZagCountsDistribution(val count: Long, minIndex: Int, maxIndex: Int, val zigZagCounts: ByteBuffer,
+ class ZigZagCountsDistribution(val count: Long, minIndex: Int, maxIndex: Int, zigZagCounts: ByteBuffer,
unitMagnitude: Int, subBucketHalfCount: Int, subBucketHalfCountMagnitude: Int) extends Distribution {
val min: Long = if(count == 0) 0 else bucketValueAtIndex(minIndex)
@@ -211,6 +211,10 @@ private[kamon] object SnapshotCreation {
builder.result()
}
+ def countsArray(): ByteBuffer = {
+ zigZagCounts.duplicate()
+ }
+
@inline private def bucketValueAtIndex(index: Int): Long = {
var bucketIndex: Int = (index >> subBucketHalfCountMagnitude) - 1
var subBucketIndex: Int = (index & (subBucketHalfCount - 1)) + subBucketHalfCount