Skip to content

Commit

Permalink
Merge pull request #51 from bitnomial/histogram-bug
Browse files Browse the repository at this point in the history
Fix bug with observeAndSample function from Histogram
  • Loading branch information
wraithm authored Dec 19, 2023
2 parents 42be28d + 099dcaa commit 6ccbc9d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

## 2.3.0

* Change the `observeAndSample` function from the
`System.Metrics.Prometheus.Metric.Histogram` module to return the value of
the sample that was just added, instead of the previous sample.
This change matches similar functions for `Counter`s and `Gauge`s.
[#51](https://github.com/bitnomial/prometheus/pull/51)
4 changes: 2 additions & 2 deletions prometheus.cabal
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: prometheus
version: 2.2.4
version: 2.3.0
synopsis: Prometheus Haskell Client
homepage: http://github.com/bitnomial/prometheus
bug-reports: http://github.com/bitnomial/prometheus/issues
license: BSD3
license-file: LICENSE
author: Luke Hoersten
maintainer: luke@bitnomial.com, opensource@bitnomial.com
copyright: Bitnomial, Inc. (c) 2016-2019
copyright: Bitnomial, Inc. (c) 2016-2023
category: Metrics, Monitoring, Web, System
build-type: Simple
cabal-version: >=1.10
Expand Down
2 changes: 1 addition & 1 deletion src/System/Metrics/Prometheus/Metric/Counter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Data.Atomics.Counter (AtomicCounter, incrCounter, newCounter, writeCounte


newtype Counter = Counter {unCounter :: AtomicCounter}
newtype CounterSample = CounterSample {unCounterSample :: Int}
newtype CounterSample = CounterSample {unCounterSample :: Int} deriving Show


new :: IO Counter
Expand Down
2 changes: 1 addition & 1 deletion src/System/Metrics/Prometheus/Metric/Gauge.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Data.IORef (IORef, atomicModifyIORef', newIORef)


newtype Gauge = Gauge {unGauge :: IORef Double}
newtype GaugeSample = GaugeSample {unGaugeSample :: Double}
newtype GaugeSample = GaugeSample {unGaugeSample :: Double} deriving Show


new :: IO Gauge
Expand Down
3 changes: 2 additions & 1 deletion src/System/Metrics/Prometheus/Metric/Histogram.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ data HistogramSample = HistogramSample
, histSum :: !Double
, histCount :: !Int
}
deriving Show


new :: [UpperBound] -> IO Histogram
Expand All @@ -49,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
1 change: 1 addition & 0 deletions src/System/Metrics/Prometheus/Metric/Summary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ data SummarySample = SummarySample
, sumSum :: !Int
, sumCount :: !Int
}
deriving Show

0 comments on commit 6ccbc9d

Please sign in to comment.