diff --git a/src/common/metrics/src/relabeled_metric.rs b/src/common/metrics/src/relabeled_metric.rs index e7b07155c06b0..d613256628e80 100644 --- a/src/common/metrics/src/relabeled_metric.rs +++ b/src/common/metrics/src/relabeled_metric.rs @@ -74,6 +74,47 @@ impl RelabeledMetricVec { } } +#[easy_ext::ext(MetricVecRelabelExt)] +impl M +where + M: Sized, +{ + /// Equivalent to [`RelabeledMetricVec::with_metric_level`]. + pub fn relabel( + self, + metric_level: MetricLevel, + relabel_threshold: MetricLevel, + ) -> RelabeledMetricVec { + RelabeledMetricVec::with_metric_level(metric_level, self, relabel_threshold) + } + + /// Equivalent to [`RelabeledMetricVec::with_metric_level_relabel_n`]. + pub fn relabel_n( + self, + metric_level: MetricLevel, + relabel_threshold: MetricLevel, + relabel_num: usize, + ) -> RelabeledMetricVec { + RelabeledMetricVec::with_metric_level_relabel_n( + metric_level, + self, + relabel_threshold, + relabel_num, + ) + } + + /// Equivalent to [`RelabeledMetricVec::with_metric_level_relabel_n`] with `metric_level` set to + /// `MetricLevel::Debug` and `relabel_num` set to 1. + pub fn relabel_debug_1(self, relabel_threshold: MetricLevel) -> RelabeledMetricVec { + RelabeledMetricVec::with_metric_level_relabel_n( + MetricLevel::Debug, + self, + relabel_threshold, + 1, + ) + } +} + impl RelabeledMetricVec> { pub fn with_label_values(&self, vals: &[&str]) -> T::M { if self.metric_level > self.relabel_threshold { @@ -89,8 +130,7 @@ impl RelabeledMetricVec> { } impl RelabeledMetricVec> { - // TODO: shall we rename this to `with_guarded_label_values`? - pub fn with_label_values(&self, vals: &[&str; N]) -> LabelGuardedMetric { + pub fn with_guarded_label_values(&self, vals: &[&str; N]) -> LabelGuardedMetric { if self.metric_level > self.relabel_threshold { // relabel first n labels to empty string let mut relabeled_vals = *vals; diff --git a/src/storage/src/monitor/local_metrics.rs b/src/storage/src/monitor/local_metrics.rs index 81bfb86fe3c73..3b287949f2091 100644 --- a/src/storage/src/monitor/local_metrics.rs +++ b/src/storage/src/monitor/local_metrics.rs @@ -256,30 +256,30 @@ impl LocalStoreMetrics { pub fn new(metrics: &HummockStateStoreMetrics, table_id_label: &str) -> Self { let cache_data_block_total = metrics .sst_store_block_request_counts - .with_label_values(&[table_id_label, "data_total"]) + .with_guarded_label_values(&[table_id_label, "data_total"]) .local(); let cache_data_block_miss = metrics .sst_store_block_request_counts - .with_label_values(&[table_id_label, "data_miss"]) + .with_guarded_label_values(&[table_id_label, "data_miss"]) .local(); let cache_meta_block_total = metrics .sst_store_block_request_counts - .with_label_values(&[table_id_label, "meta_total"]) + .with_guarded_label_values(&[table_id_label, "meta_total"]) .local(); let cache_data_prefetch_count = metrics .sst_store_block_request_counts - .with_label_values(&[table_id_label, "prefetch_count"]) + .with_guarded_label_values(&[table_id_label, "prefetch_count"]) .local(); let cache_data_prefetch_block_count = metrics .sst_store_block_request_counts - .with_label_values(&[table_id_label, "prefetch_data_count"]) + .with_guarded_label_values(&[table_id_label, "prefetch_data_count"]) .local(); let cache_meta_block_miss = metrics .sst_store_block_request_counts - .with_label_values(&[table_id_label, "meta_miss"]) + .with_guarded_label_values(&[table_id_label, "meta_miss"]) .local(); let remote_io_time = metrics @@ -289,22 +289,22 @@ impl LocalStoreMetrics { let processed_key_count = metrics .iter_scan_key_counts - .with_label_values(&[table_id_label, "processed"]) + .with_guarded_label_values(&[table_id_label, "processed"]) .local(); let skip_multi_version_key_count = metrics .iter_scan_key_counts - .with_label_values(&[table_id_label, "skip_multi_version"]) + .with_guarded_label_values(&[table_id_label, "skip_multi_version"]) .local(); let skip_delete_key_count = metrics .iter_scan_key_counts - .with_label_values(&[table_id_label, "skip_delete"]) + .with_guarded_label_values(&[table_id_label, "skip_delete"]) .local(); let total_key_count = metrics .iter_scan_key_counts - .with_label_values(&[table_id_label, "total"]) + .with_guarded_label_values(&[table_id_label, "total"]) .local(); let get_shared_buffer_hit_counts = metrics @@ -477,7 +477,7 @@ macro_rules! define_bloom_filter_metrics { pub fn new(metrics: &HummockStateStoreMetrics, table_id_label: &str, oper_type: &str) -> Self { // checks SST bloom filters Self { - $($x: metrics.$x.with_label_values(&[table_id_label, oper_type]).local(),)* + $($x: metrics.$x.with_guarded_label_values(&[table_id_label, oper_type]).local(),)* } } diff --git a/src/storage/src/monitor/monitored_storage_metrics.rs b/src/storage/src/monitor/monitored_storage_metrics.rs index 01419586f2eea..5813c20b4e9ef 100644 --- a/src/storage/src/monitor/monitored_storage_metrics.rs +++ b/src/storage/src/monitor/monitored_storage_metrics.rs @@ -287,27 +287,27 @@ impl MonitoredStorageMetrics { ) -> LocalIterMetricsInner { let iter_init_duration = self .iter_init_duration - .with_label_values(&[table_label, iter_type]) + .with_guarded_label_values(&[table_label, iter_type]) .local(); let iter_counts = self .iter_counts - .with_label_values(&[table_label, iter_type]) + .with_guarded_label_values(&[table_label, iter_type]) .local(); let iter_scan_duration = self .iter_scan_duration - .with_label_values(&[table_label, iter_type]) + .with_guarded_label_values(&[table_label, iter_type]) .local(); let iter_item = self .iter_item - .with_label_values(&[table_label, iter_type]) + .with_guarded_label_values(&[table_label, iter_type]) .local(); let iter_size = self .iter_size - .with_label_values(&[table_label, iter_type]) + .with_guarded_label_values(&[table_label, iter_type]) .local(); let iter_in_progress_counts = self .iter_in_progress_counts - .with_label_values(&[table_label, iter_type]); + .with_guarded_label_values(&[table_label, iter_type]); LocalIterMetricsInner { iter_init_duration, @@ -343,11 +343,17 @@ impl MonitoredStorageMetrics { } fn local_get_metrics(&self, table_label: &str) -> LocalGetMetrics { - let get_duration = self.get_duration.with_label_values(&[table_label]).local(); - let get_key_size = self.get_key_size.with_label_values(&[table_label]).local(); + let get_duration = self + .get_duration + .with_guarded_label_values(&[table_label]) + .local(); + let get_key_size = self + .get_key_size + .with_guarded_label_values(&[table_label]) + .local(); let get_value_size = self .get_value_size - .with_label_values(&[table_label]) + .with_guarded_label_values(&[table_label]) .local(); LocalGetMetrics { diff --git a/src/stream/src/executor/barrier_align.rs b/src/stream/src/executor/barrier_align.rs index a29bf91bb6660..e5b1e18836957 100644 --- a/src/stream/src/executor/barrier_align.rs +++ b/src/stream/src/executor/barrier_align.rs @@ -50,13 +50,13 @@ pub async fn barrier_align( ) { let actor_id = actor_id.to_string(); let fragment_id = fragment_id.to_string(); - let left_barrier_align_duration = metrics.barrier_align_duration.with_label_values(&[ + let left_barrier_align_duration = metrics.barrier_align_duration.with_guarded_label_values(&[ &actor_id, &fragment_id, "left", executor_name, ]); - let right_barrier_align_duration = metrics.barrier_align_duration.with_label_values(&[ + let right_barrier_align_duration = metrics.barrier_align_duration.with_guarded_label_values(&[ &actor_id, &fragment_id, "right", diff --git a/src/stream/src/executor/dispatch.rs b/src/stream/src/executor/dispatch.rs index 771cf8fc5b4a0..82d11db49513b 100644 --- a/src/stream/src/executor/dispatch.rs +++ b/src/stream/src/executor/dispatch.rs @@ -92,7 +92,7 @@ impl DispatchExecutorMetrics { actor_output_buffer_blocking_duration_ns: self .metrics .actor_output_buffer_blocking_duration_ns - .with_label_values(&[ + .with_guarded_label_values(&[ &self.actor_id_str, &self.fragment_id_str, dispatcher.dispatcher_id_str(), diff --git a/src/stream/src/executor/hash_join.rs b/src/stream/src/executor/hash_join.rs index d12117d74e0ab..e1a1b177bcfcc 100644 --- a/src/stream/src/executor/hash_join.rs +++ b/src/stream/src/executor/hash_join.rs @@ -810,7 +810,7 @@ impl HashJoinExecutor>::new(); let mut start_time = Instant::now(); - let barrier_align = metrics.barrier_align_duration.with_label_values(&[ + let barrier_align = metrics.barrier_align_duration.with_guarded_label_values(&[ &actor_id.to_string(), &fragment_id.to_string(), "",