From c881277f8d1d4885594500ca08f3e2f82cb4beb4 Mon Sep 17 00:00:00 2001 From: Dennis Gosnell Date: Tue, 19 Dec 2023 16:34:37 +0900 Subject: [PATCH 1/3] Make all Sample types showable This commit derives `Show` for all of our *Sample types: - `CounterSample` - `GaugeSample` - `HistogramSample` - `SummarySample` --- src/System/Metrics/Prometheus/Metric/Counter.hs | 2 +- src/System/Metrics/Prometheus/Metric/Gauge.hs | 2 +- src/System/Metrics/Prometheus/Metric/Histogram.hs | 1 + src/System/Metrics/Prometheus/Metric/Summary.hs | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/System/Metrics/Prometheus/Metric/Counter.hs b/src/System/Metrics/Prometheus/Metric/Counter.hs index f76a3edcd..70d8148f4 100644 --- a/src/System/Metrics/Prometheus/Metric/Counter.hs +++ b/src/System/Metrics/Prometheus/Metric/Counter.hs @@ -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 diff --git a/src/System/Metrics/Prometheus/Metric/Gauge.hs b/src/System/Metrics/Prometheus/Metric/Gauge.hs index 76610e221..3c0852e2c 100644 --- a/src/System/Metrics/Prometheus/Metric/Gauge.hs +++ b/src/System/Metrics/Prometheus/Metric/Gauge.hs @@ -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 diff --git a/src/System/Metrics/Prometheus/Metric/Histogram.hs b/src/System/Metrics/Prometheus/Metric/Histogram.hs index fbd26528a..438f01994 100644 --- a/src/System/Metrics/Prometheus/Metric/Histogram.hs +++ b/src/System/Metrics/Prometheus/Metric/Histogram.hs @@ -36,6 +36,7 @@ data HistogramSample = HistogramSample , histSum :: !Double , histCount :: !Int } + deriving Show new :: [UpperBound] -> IO Histogram diff --git a/src/System/Metrics/Prometheus/Metric/Summary.hs b/src/System/Metrics/Prometheus/Metric/Summary.hs index 98f2498ef..feff1b230 100644 --- a/src/System/Metrics/Prometheus/Metric/Summary.hs +++ b/src/System/Metrics/Prometheus/Metric/Summary.hs @@ -8,3 +8,4 @@ data SummarySample = SummarySample , sumSum :: !Int , sumCount :: !Int } + deriving Show From d31723cc9bef9cba43a82c5f5161da051e8366a8 Mon Sep 17 00:00:00 2001 From: Dennis Gosnell Date: Tue, 19 Dec 2023 16:41:18 +0900 Subject: [PATCH 2/3] 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 From 099dcaaa3423f15cb41e60b1033c0b1d2c6aeae5 Mon Sep 17 00:00:00 2001 From: Dennis Gosnell Date: Tue, 19 Dec 2023 17:19:09 +0900 Subject: [PATCH 3/3] Bump version from 2.2.4 to 2.3.0 --- CHANGELOG.md | 8 ++++++++ prometheus.cabal | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..1bf30d848 --- /dev/null +++ b/CHANGELOG.md @@ -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) diff --git a/prometheus.cabal b/prometheus.cabal index fb91b64fb..1feb401c1 100644 --- a/prometheus.cabal +++ b/prometheus.cabal @@ -1,5 +1,5 @@ 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 @@ -7,7 +7,7 @@ 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