pub struct MappedMetric<H> { /* private fields */ }Expand description
A metric that is resolved dynamically by one or more label values.
Unlike a plain metric handle, a mapped metric does not hold a single handle. Instead it holds a concurrent map from a set of dynamic label values to the corresponding registered handle. Handles are registered lazily on first use and cached for subsequent lookups.
The underlying map (and the fixed label set) is shared across clones, so every clone of the containing metrics struct observes the same cache. Lookups are lock-free once a handle has been registered.
This type is an implementation detail of the static_metrics attribute macro and is not meant to be constructed
or used directly.
Implementations§
Source§impl<H> MappedMetric<H>where
H: Clone,
impl<H> MappedMetric<H>where
H: Clone,
Sourcepub fn new(labels: Arc<Vec<Label>>) -> Self
pub fn new(labels: Arc<Vec<Label>>) -> Self
Creates a new MappedMetric whose handles are registered with the given fixed labels.
Sourcepub fn get_or_register(
&self,
keys: &[&'static str],
values: &[SharedString],
register: impl FnOnce(&[Label]) -> H,
) -> H
pub fn get_or_register( &self, keys: &[&'static str], values: &[SharedString], register: impl FnOnce(&[Label]) -> H, ) -> H
Returns the handle for the given dynamic label values, registering and caching it on the first lookup.
keys are the dynamic label names and values their stringified values, in the same order and of the same
length. The register closure is invoked only on a cache miss and receives the full label set (the fixed
labels followed by the dynamic labels) with which to register the handle.