pub struct LabelGuardedMetricVec<T: MetricVecBuilder> {
inner: MetricVec<T>,
info: Arc<Mutex<LabelGuardedMetricsInfo>>,
labels: Box<[&'static str]>,
}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>>§labels: Box<[&'static str]>Implementations§
Source§impl<T: MetricVecBuilder> LabelGuardedMetricVec<T>
impl<T: MetricVecBuilder> LabelGuardedMetricVec<T>
pub fn new(inner: MetricVec<T>, labels: &[&'static str]) -> Self
Sourcepub fn with_guarded_label_values<V: AsRef<str> + Debug>(
&self,
labels: &[V],
) -> LabelGuardedMetric<T::M>
pub fn with_guarded_label_values<V: AsRef<str> + Debug>( &self, labels: &[V], ) -> LabelGuardedMetric<T::M>
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<const N: usize>(&self) -> LabelGuardedMetric<T::M>
Source§impl LabelGuardedMetricVec<impl MetricVecBuilder<M = GenericCounter<AtomicU64>>>
impl LabelGuardedMetricVec<impl MetricVecBuilder<M = GenericCounter<AtomicU64>>>
pub fn test_int_counter_vec<const N: usize>() -> Self
Source§impl LabelGuardedMetricVec<impl MetricVecBuilder<M = GenericGauge<AtomicI64>>>
impl LabelGuardedMetricVec<impl MetricVecBuilder<M = GenericGauge<AtomicI64>>>
pub fn test_int_gauge_vec<const N: usize>() -> Self
Source§impl LabelGuardedMetricVec<impl MetricVecBuilder<M = GenericGauge<AtomicF64>>>
impl LabelGuardedMetricVec<impl MetricVecBuilder<M = GenericGauge<AtomicF64>>>
pub fn test_gauge_vec<const N: usize>() -> Self
Source§impl LabelGuardedMetricVec<impl MetricVecBuilder<M = Histogram>>
impl LabelGuardedMetricVec<impl MetricVecBuilder<M = Histogram>>
pub fn test_histogram_vec<const N: usize>() -> Self
Trait Implementations§
Source§impl<T: Clone + MetricVecBuilder> Clone for LabelGuardedMetricVec<T>
impl<T: Clone + MetricVecBuilder> Clone for LabelGuardedMetricVec<T>
Source§fn clone(&self) -> LabelGuardedMetricVec<T>
fn clone(&self) -> LabelGuardedMetricVec<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: MetricVecBuilder> Collector for LabelGuardedMetricVec<T>
impl<T: MetricVecBuilder> Collector for LabelGuardedMetricVec<T>
Auto Trait Implementations§
impl<T> Freeze for LabelGuardedMetricVec<T>
impl<T> !RefUnwindSafe for LabelGuardedMetricVec<T>
impl<T> Send for LabelGuardedMetricVec<T>
impl<T> Sync for LabelGuardedMetricVec<T>
impl<T> Unpin for LabelGuardedMetricVec<T>
impl<T> !UnwindSafe for LabelGuardedMetricVec<T>
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,
§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::RequestSource§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.