λ: import System.Metrics.Prometheus.Metric.Histogram as H
λ: h <- H.new []
λ: s1 <- H.sample h
λ: :print s1
s1 = HistogramSample (_t4::Buckets) 0.0 0
λ: H.observe 2.2 h
λ: H.observe 2.222 h
λ: H.observe 1232.222 h
λ: s2 <- H.sample h
λ: :print s2
s2 = (_t5::HistogramSample)
λ: :seti -XBangPatterns
λ: !s3 <- H.sample h
λ: :print s3
s3 = HistogramSample (_t6::Buckets) (_t7::Double) (_t8::Int)
λ: H.observe 7 h
λ: H.observe 420 h
λ: !s4 <- H.sample h
λ: :print s4
s4 = HistogramSample (_t9::Buckets) (_t10::Double) (_t11::Int)
As we observe, we can see thunks accumulating in the underlying HistogramSample. The prometheus library is not strict enough - a patch with some strictness annotations on the HistogramSample record should fix it.
By adding strictness annotations to the HistogramSample record & using Data.Map.Strict, we can now see that after calling observe multiple times, we are no longer leaking thunks:
λ: import System.Metrics.Prometheus.Metric.Histogram as H
λ: :seti -XBangPatterns
λ: h <- H.new []
λ: !s1 <- H.sample h
λ: :print s1
s1 = HistogramSample
(Data.Map.Internal.Bin
1 Infinity 0.0 Data.Map.Internal.Tip Data.Map.Internal.Tip)
0.0 0
λ: H.observe 2.2 h
λ: H.observe 55 h
λ: H.observe 7 h
λ: !s2 <- H.sample h
λ: :print s2
s2 = HistogramSample
(Data.Map.Internal.Bin
1 Infinity 3.0 Data.Map.Internal.Tip Data.Map.Internal.Tip)
64.2 3