diff --git a/metrics-util/CHANGELOG.md b/metrics-util/CHANGELOG.md index 603b70c1..b7d053a6 100644 --- a/metrics-util/CHANGELOG.md +++ b/metrics-util/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - New layer -- `Router` -- for routing specific metrics to target downstream recorders. +- `Registry::clear` allows clearing all metrics from the registry. ### Changed - Updated all deprecated usages of `crossbeam_epoch::Atomic::compare_and_set` to `compare_exchange`. diff --git a/metrics-util/src/registry.rs b/metrics-util/src/registry.rs index c1ecdb81..cc8bdded 100644 --- a/metrics-util/src/registry.rs +++ b/metrics-util/src/registry.rs @@ -123,6 +123,18 @@ where (hash, shard) } + /// Removes all metrics from the registry. + /// + /// This operation is eventually consistent: metrics will be removed piecemeal, and this method + /// does not ensure that callers will see the registry as entirely empty at any given point. + pub fn clear(&self) { + for shard in &self.shards { + for subshard in shard { + subshard.write().clear(); + } + } + } + /// Perform an operation on a given key. /// /// The `op` function will be called for the handle under the given `key`.