Skip to content

Commit

Permalink
Merge pull request #207 from metrics-rs/tlawrence_registry_enhancements
Browse files Browse the repository at this point in the history
registry: add clear method
  • Loading branch information
tobz committed May 18, 2021
2 parents 6fad083 + c31ee01 commit eaa49a0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions metrics-util/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>::compare_and_set` to `compare_exchange`.
Expand Down
12 changes: 12 additions & 0 deletions metrics-util/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down

0 comments on commit eaa49a0

Please sign in to comment.