From d31723cc9bef9cba43a82c5f5161da051e8366a8 Mon Sep 17 00:00:00 2001 From: Dennis Gosnell Date: Tue, 19 Dec 2023 16:41:18 +0900 Subject: [PATCH] Return just observed sample for Histogram observeAndSample The Histogram metric has a function `observeAndSample`, which lets you add a new observation, and sample it at the same time. Before this commit, this `observeAndSample` function would return the _previous_ sample, _not_ the sample you just added. This commit changes the behavior of `observeAndSample` so that it returns the sample that was just added. This matches the behavior of `addAndSample` (from `Counter`), and `modifyAndSample` (from `Gauge`), which both return the value of the sample that was just added. --- src/System/Metrics/Prometheus/Metric/Histogram.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System/Metrics/Prometheus/Metric/Histogram.hs b/src/System/Metrics/Prometheus/Metric/Histogram.hs index 438f01994..39a49c26a 100644 --- a/src/System/Metrics/Prometheus/Metric/Histogram.hs +++ b/src/System/Metrics/Prometheus/Metric/Histogram.hs @@ -50,7 +50,7 @@ new buckets = Histogram <$> newIORef empty observeAndSample :: Double -> Histogram -> IO HistogramSample observeAndSample x = flip atomicModifyIORef' update . unHistogram where - update histData = (hist' histData, histData) + update histData = (hist' histData, hist' histData) hist' histData = histData { histBuckets = updateBuckets x $ histBuckets histData