Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

## 2.4.0

* Add a `reset` function to the
`System.Metrics.Prometheus.Metric.Histogram` module, which zeroes the
bucket counts, sum, and observation count while leaving the bucket bounds
unchanged. This is useful for resetting metrics between tests.
[#55](https://github.com/bitnomial/prometheus/issues/55)

## 2.3.1

* Relax the `http-client-tls` upper bound to allow `0.4.*`.
Expand Down
2 changes: 1 addition & 1 deletion prometheus.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: prometheus
version: 2.3.1
version: 2.4.0
synopsis: Prometheus Haskell Client
homepage: http://github.com/bitnomial/prometheus
bug-reports: http://github.com/bitnomial/prometheus/issues
Expand Down
22 changes: 22 additions & 0 deletions src/System/Metrics/Prometheus/Metric/Histogram.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
observe,
sample,
observeAndSample,
reset,
) where

import Control.Applicative ((<$>))

Check warning on line 15 in src/System/Metrics/Prometheus/Metric/Histogram.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack-9.2.yaml / ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 15 in src/System/Metrics/Prometheus/Metric/Histogram.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.2.8 / ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 15 in src/System/Metrics/Prometheus/Metric/Histogram.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack-8.10.yaml / ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 15 in src/System/Metrics/Prometheus/Metric/Histogram.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack-9.0.yaml / ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 15 in src/System/Metrics/Prometheus/Metric/Histogram.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-8.10.7 / ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 15 in src/System/Metrics/Prometheus/Metric/Histogram.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.0.2 / ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 15 in src/System/Metrics/Prometheus/Metric/Histogram.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack-9.6.yaml / ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 15 in src/System/Metrics/Prometheus/Metric/Histogram.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack-9.8.yaml / ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 15 in src/System/Metrics/Prometheus/Metric/Histogram.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack-9.10.yaml / ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 15 in src/System/Metrics/Prometheus/Metric/Histogram.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.10.3 / ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 15 in src/System/Metrics/Prometheus/Metric/Histogram.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.4.8 / ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 15 in src/System/Metrics/Prometheus/Metric/Histogram.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.12.4 / ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 15 in src/System/Metrics/Prometheus/Metric/Histogram.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.6.6 / ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 15 in src/System/Metrics/Prometheus/Metric/Histogram.hs

View workflow job for this annotation

GitHub Actions / stack --stack-yaml ./stack-9.4.yaml / ubuntu-latest

The import of ‘Control.Applicative’ is redundant

Check warning on line 15 in src/System/Metrics/Prometheus/Metric/Histogram.hs

View workflow job for this annotation

GitHub Actions / cabal / ghc-9.8.2 / ubuntu-latest

The import of ‘Control.Applicative’ is redundant
import Control.Monad (void)
import Data.Bool (bool)
import Data.IORef (
Expand Down Expand Up @@ -71,3 +72,24 @@

sample :: Histogram -> IO HistogramSample
sample = readIORef . unHistogram


-- | Reset the histogram back to its initial state: every bucket count, the
-- sum, and the observation count return to 0. The bucket upper bounds are left
-- unchanged.
--
-- This is /not/ part of the Prometheus client library specification, which
-- only defines @observe@ for histograms. It is intended for resetting metrics
-- between tests when they are defined as top-level values. On a live, scraped
-- metric a reset looks like a counter reset (e.g. a process restart) to
-- Prometheus, which its @rate@/@increase@ functions handle, so prefer
-- 'observe' there and reserve 'reset' for test isolation.
reset :: Histogram -> IO ()
reset (Histogram ref) = atomicModifyIORef' ref $ \histData ->
( histData
{ histBuckets = 0 <$ histBuckets histData
, histSum = 0
, histCount = 0
}
, ()
)
Loading