Skip to content

Commit 79e5424

Browse files
committed
coderabbit suggestion
1 parent ac24570 commit 79e5424

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/stats.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use std::collections::HashMap;
2020
use std::sync::Arc;
2121

22-
use itertools::Itertools;
2322
use prometheus::core::Collector;
2423
use prometheus::proto::MetricFamily;
2524
use prometheus::IntGaugeVec;
@@ -199,16 +198,12 @@ fn delete_with_label_prefix(metrics: &IntGaugeVec, prefix: &[&str]) {
199198
.map(|l| (l.get_name(), l.get_value()))
200199
.collect();
201200

202-
let mut should_continue = false;
203-
prefix.iter().for_each(|p| {
204-
// label map doesn't have the key present in prefix, hence continue
205-
if !label_map.values().contains(p) {
206-
should_continue = true;
207-
}
208-
});
209-
if !should_continue {
201+
// Check if all prefix elements are present in label values
202+
let all_prefixes_found = prefix.iter().all(|p| label_map.values().any(|v| v == p));
203+
204+
if all_prefixes_found {
210205
if let Err(err) = metrics.remove(&label_map) {
211-
warn!("Error = {err}");
206+
warn!("Error removing metric with labels {:?}: {err}", label_map);
212207
}
213208
}
214209
}

0 commit comments

Comments
 (0)