pub struct Recency<K> { /* private fields */ }
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>
impl<K> Recency<K>
sourcepub fn new(
clock: Clock,
mask: MetricKindMask,
idle_timeout: Option<Duration>,
) -> Self
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.
sourcepub fn should_store_counter<S>(
&self,
key: &K,
gen: Generation,
registry: &Registry<K, S>,
) -> boolwhere
S: Storage<K>,
pub fn should_store_counter<S>(
&self,
key: &K,
gen: Generation,
registry: &Registry<K, S>,
) -> boolwhere
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.
sourcepub fn should_store_gauge<S>(
&self,
key: &K,
gen: Generation,
registry: &Registry<K, S>,
) -> boolwhere
S: Storage<K>,
pub fn should_store_gauge<S>(
&self,
key: &K,
gen: Generation,
registry: &Registry<K, S>,
) -> boolwhere
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.
sourcepub fn should_store_histogram<S>(
&self,
key: &K,
gen: Generation,
registry: &Registry<K, S>,
) -> boolwhere
S: Storage<K>,
pub fn should_store_histogram<S>(
&self,
key: &K,
gen: Generation,
registry: &Registry<K, S>,
) -> boolwhere
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.