Add reset function to Histogram#61
Merged
Merged
Conversation
Adds a `reset` to `System.Metrics.Prometheus.Metric.Histogram` that zeroes the bucket counts, sum, and observation count while leaving the bucket upper bounds unchanged. This mirrors `set 0` on `Counter`/`Gauge` and is useful for resetting metrics between tests when they are defined as top-level values. The reset uses `atomicModifyIORef'` for consistency with `observe`, so it is safe against concurrent observations. Closes #55 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
brandonchinn178
approved these changes
Jun 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
resetfunction toSystem.Metrics.Prometheus.Metric.Histogram, resolving #55.CounterandGaugecan already be reset withset 0, butHistogramhad no equivalent.resetzeroes the bucket counts, sum, and observation count while leaving the bucket upper bounds unchanged, putting the histogram back into the same state as a freshly-created one. The primary use case is resetting metrics between tests when they're defined as top-level values.Notes
atomicModifyIORef'(matchingobserve/observeAndSample) so it's safe against concurrent observations — the prototype in the issue used the non-atomicmodifyIORef'.lekeys, including+Inf) are preserved; only the accumulated values are zeroed, which keeps it within the Prometheus client-spec rule that buckets must not change after creation.resetis not part of the Prometheus client library spec (which only mandatesobservefor histograms). On a live scraped metric a reset reads as a counter reset / process restart to Prometheus, whichrate/increasehandle, but it's intended for test isolation. The Haddock spells this out.Test plan
reset, thensample, and confirm all bucket counts,histSum, andhistCountare 0 while the bucket keys are unchanged.🤖 Generated with Claude Code