pub struct LabelGuardedMetricVec<T: MetricVecBuilder, const N: usize> {
inner: MetricVec<T>,
info: Arc<Mutex<LabelGuardedMetricsInfo<N>>>,
labels: [&'static str; N],
}
Expand description
An RAII metrics vec with labels.
LabelGuardedMetricVec
enhances the [MetricVec
] to ensure the set of labels to be
correctly removed from the Prometheus client once being dropped. This is useful for metrics
that are associated with an object that can be dropped, such as streaming jobs, fragments,
actors, batch tasks, etc.
When a set labels is dropped, it will record it in the uncollected_removed_labels
set.
Once the metrics has been collected, it will finally remove the metrics of the labels.
See also LabelGuardedMetricsInfo
and LabelGuard::drop
.
§Arguments
T
- The type of the raw metrics vec.N
- The number of labels.
Fields§
§inner: MetricVec<T>
§info: Arc<Mutex<LabelGuardedMetricsInfo<N>>>
§labels: [&'static str; N]
Implementations§
source§impl<T: MetricVecBuilder, const N: usize> LabelGuardedMetricVec<T, N>
impl<T: MetricVecBuilder, const N: usize> LabelGuardedMetricVec<T, N>
pub fn new(inner: MetricVec<T>, labels: &[&'static str; N]) -> Self
sourcepub fn with_guarded_label_values(
&self,
labels: &[&str; N],
) -> LabelGuardedMetric<T::M, N>
pub fn with_guarded_label_values( &self, labels: &[&str; N], ) -> LabelGuardedMetric<T::M, N>
This is similar to the with_label_values
of the raw metrics vec.
We need to pay special attention that, unless for some special purpose,
we should not drop the returned LabelGuardedMetric
immediately after
using it, such as metrics.with_guarded_label_values(...).inc();
,
because after dropped the label will be regarded as not used any more,
and the internal raw metrics will be removed and reset.
Instead, we should store the returned LabelGuardedMetric
in a scope with longer
lifetime so that the labels can be regarded as being used in its whole life scope.
This is also the recommended way to use the raw metrics vec.
pub fn with_test_label(&self) -> LabelGuardedMetric<T::M, N>
source§impl<const N: usize> LabelGuardedMetricVec<impl MetricVecBuilder<M = GenericCounter<AtomicU64>>, N>
impl<const N: usize> LabelGuardedMetricVec<impl MetricVecBuilder<M = GenericCounter<AtomicU64>>, N>
pub fn test_int_counter_vec() -> Self
source§impl<const N: usize> LabelGuardedMetricVec<impl MetricVecBuilder<M = GenericGauge<AtomicI64>>, N>
impl<const N: usize> LabelGuardedMetricVec<impl MetricVecBuilder<M = GenericGauge<AtomicI64>>, N>
pub fn test_int_gauge_vec() -> Self
source§impl<const N: usize> LabelGuardedMetricVec<impl MetricVecBuilder<M = GenericGauge<AtomicF64>>, N>
impl<const N: usize> LabelGuardedMetricVec<impl MetricVecBuilder<M = GenericGauge<AtomicF64>>, N>
pub fn test_gauge_vec() -> Self
source§impl<const N: usize> LabelGuardedMetricVec<impl MetricVecBuilder<M = Histogram>, N>
impl<const N: usize> LabelGuardedMetricVec<impl MetricVecBuilder<M = Histogram>, N>
pub fn test_histogram_vec() -> Self
Trait Implementations§
source§impl<T: Clone + MetricVecBuilder, const N: usize> Clone for LabelGuardedMetricVec<T, N>
impl<T: Clone + MetricVecBuilder, const N: usize> Clone for LabelGuardedMetricVec<T, N>
source§fn clone(&self) -> LabelGuardedMetricVec<T, N>
fn clone(&self) -> LabelGuardedMetricVec<T, N>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T: MetricVecBuilder, const N: usize> Collector for LabelGuardedMetricVec<T, N>
impl<T: MetricVecBuilder, const N: usize> Collector for LabelGuardedMetricVec<T, N>
Auto Trait Implementations§
impl<T, const N: usize> Freeze for LabelGuardedMetricVec<T, N>
impl<T, const N: usize> !RefUnwindSafe for LabelGuardedMetricVec<T, N>
impl<T, const N: usize> Send for LabelGuardedMetricVec<T, N>
impl<T, const N: usize> Sync for LabelGuardedMetricVec<T, N>
impl<T, const N: usize> Unpin for LabelGuardedMetricVec<T, N>
impl<T, const N: usize> !UnwindSafe for LabelGuardedMetricVec<T, N>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
source§impl<M> MetricVecRelabelExt for M
impl<M> MetricVecRelabelExt for M
source§fn relabel(
self,
metric_level: MetricLevel,
relabel_threshold: MetricLevel,
) -> RelabeledMetricVec<M>
fn relabel( self, metric_level: MetricLevel, relabel_threshold: MetricLevel, ) -> RelabeledMetricVec<M>
RelabeledMetricVec::with_metric_level
.source§fn relabel_n(
self,
metric_level: MetricLevel,
relabel_threshold: MetricLevel,
relabel_num: usize,
) -> RelabeledMetricVec<M>
fn relabel_n( self, metric_level: MetricLevel, relabel_threshold: MetricLevel, relabel_num: usize, ) -> RelabeledMetricVec<M>
RelabeledMetricVec::with_metric_level_relabel_n
.source§fn relabel_debug_1(
self,
relabel_threshold: MetricLevel,
) -> RelabeledMetricVec<M>
fn relabel_debug_1( self, relabel_threshold: MetricLevel, ) -> RelabeledMetricVec<M>
RelabeledMetricVec::with_metric_level_relabel_n
with metric_level
set to
MetricLevel::Debug
and relabel_num
set to 1.