Skip to content

Commit

Permalink
Return just observed sample for Histogram observeAndSample
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cdepillabout committed Dec 19, 2023
1 parent c881277 commit d31723c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/System/Metrics/Prometheus/Metric/Histogram.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d31723c

Please sign in to comment.