Struct metrics_util::registry::Recency

source ·
pub struct Recency<K> { /* private fields */ }
Available on crate features registry and recency only.
Expand description

Tracks recency of metric updates by their registry generation and time.

In many cases, a user may have a long-running process where metrics are stored over time using labels that change for some particular reason, leaving behind versions of that metric with labels that are no longer relevant to the current process state. This can lead to cases where metrics that no longer matter are still present in rendered output, adding bloat.

When coupled with Registry, Recency can be used to track when the last update to a metric has occurred for the purposes of removing idle metrics from the registry. In addition, it will remove the value from the registry itself to reduce the aforementioned bloat.

Recency is separate from Registry specifically to avoid imposing any slowdowns when tracking recency does not matter, despite their otherwise tight coupling.

Implementations§

source§

impl<K> Recency<K>
where K: Clone + Eq + Hashable,

source

pub fn new( clock: Clock, mask: MetricKindMask, idle_timeout: Option<Duration> ) -> Self

Creates a new Recency.

If idle_timeout is None, no recency checking will occur. Otherwise, any metric that has not been updated for longer than idle_timeout will be subject for deletion the next time the metric is checked.

The provided clock is used for tracking time, while mask controls which metrics are covered by the recency logic. For example, if mask only contains counters and histograms, then gauges will not be considered for recency, and thus will never be deleted.

Refer to the documentation for MetricKindMask for more information on defining a metric kind mask.

source

pub fn should_store_counter<S>( &self, key: &K, gen: Generation, registry: &Registry<K, S> ) -> bool
where S: Storage<K>,

Checks if the given counter should be stored, based on its known recency.

If the given key has been updated recently enough, and should continue to be stored, this method will return true and will update the last update time internally. If the given key has not been updated recently enough, the key will be removed from the given registry if the given generation also matches.

source

pub fn should_store_gauge<S>( &self, key: &K, gen: Generation, registry: &Registry<K, S> ) -> bool
where S: Storage<K>,

Checks if the given gauge should be stored, based on its known recency.

If the given key has been updated recently enough, and should continue to be stored, this method will return true and will update the last update time internally. If the given key has not been updated recently enough, the key will be removed from the given registry if the given generation also matches.

source

pub fn should_store_histogram<S>( &self, key: &K, gen: Generation, registry: &Registry<K, S> ) -> bool
where S: Storage<K>,

Checks if the given histogram should be stored, based on its known recency.

If the given key has been updated recently enough, and should continue to be stored, this method will return true and will update the last update time internally. If the given key has not been updated recently enough, the key will be removed from the given registry if the given generation also matches.

Auto Trait Implementations§

§

impl<K> !Freeze for Recency<K>

§

impl<K> RefUnwindSafe for Recency<K>

§

impl<K> Send for Recency<K>
where K: Send,

§

impl<K> Sync for Recency<K>
where K: Send,

§

impl<K> Unpin for Recency<K>
where K: Unpin,

§

impl<K> UnwindSafe for Recency<K>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.