From 417976b197267f402da98809257f4554b74b2c8d Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Mon, 16 Mar 2026 17:04:53 -0700 Subject: [PATCH] Drop deleted collection metrics --- seaweed-volume/src/metrics.rs | 33 +++++++++++++++++++++++++++++ seaweed-volume/src/storage/store.rs | 1 + 2 files changed, 34 insertions(+) diff --git a/seaweed-volume/src/metrics.rs b/seaweed-volume/src/metrics.rs index 666c2caae..f1109effc 100644 --- a/seaweed-volume/src/metrics.rs +++ b/seaweed-volume/src/metrics.rs @@ -237,6 +237,14 @@ pub fn gather_metrics() -> String { String::from_utf8(buffer).expect("metrics are valid UTF-8") } +pub fn delete_collection_metrics(collection: &str) { + let _ = VOLUME_GAUGE.remove_label_values(&[collection, "volume"]); + let _ = VOLUME_GAUGE.remove_label_values(&[collection, "ec_shards"]); + let _ = READ_ONLY_VOLUME_GAUGE.remove_label_values(&[collection, "volume"]); + let _ = DISK_SIZE_GAUGE.remove_label_values(&[collection, "normal"]); + let _ = DISK_SIZE_GAUGE.remove_label_values(&[collection, "deleted_bytes"]); +} + pub fn build_pushgateway_url(address: &str, job: &str, instance: &str) -> String { let base = if address.starts_with("http://") || address.starts_with("https://") { address.to_string() @@ -340,4 +348,29 @@ mod tests { server.abort(); } + + #[test] + fn test_delete_collection_metrics_removes_collection_labelsets() { + register_metrics(); + + VOLUME_GAUGE.with_label_values(&["pics", "volume"]).set(2.0); + VOLUME_GAUGE.with_label_values(&["pics", "ec_shards"]).set(3.0); + READ_ONLY_VOLUME_GAUGE + .with_label_values(&["pics", "volume"]) + .set(1.0); + DISK_SIZE_GAUGE + .with_label_values(&["pics", "normal"]) + .set(10.0); + DISK_SIZE_GAUGE + .with_label_values(&["pics", "deleted_bytes"]) + .set(4.0); + + delete_collection_metrics("pics"); + + let output = gather_metrics(); + assert!(!output.contains("collection=\"pics\",type=\"volume\"")); + assert!(!output.contains("collection=\"pics\",type=\"ec_shards\"")); + assert!(!output.contains("collection=\"pics\",type=\"normal\"")); + assert!(!output.contains("collection=\"pics\",type=\"deleted_bytes\"")); + } } diff --git a/seaweed-volume/src/storage/store.rs b/seaweed-volume/src/storage/store.rs index f93fc7a0a..f679df02f 100644 --- a/seaweed-volume/src/storage/store.rs +++ b/seaweed-volume/src/storage/store.rs @@ -377,6 +377,7 @@ impl Store { for loc in &mut self.locations { loc.delete_collection(collection); } + crate::metrics::delete_collection_metrics(collection); } // ---- Metrics ----