From 4e063554ecc7768b15076dffe43f3fd48134a554 Mon Sep 17 00:00:00 2001 From: Hauser Zhi Date: Fri, 6 Nov 2026 00:15:43 +0800 Subject: [PATCH] fix(observability): keep lock PID resource attribution Remove only the process_pid datapoint label from RustFS process metrics, leaving the shared process.pid resource available to sibling metrics and lock histograms. Lock metrics continue using resource-to-telemetry conversion without mutating the shared resource. Co-Authored-By: heihutu Co-Authored-By: zhi22915 --- .../observability/otel-collector-config.yaml | 6 ++--- crates/io-metrics/src/lock_metrics.rs | 26 +++---------------- 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/.docker/observability/otel-collector-config.yaml b/.docker/observability/otel-collector-config.yaml index 8f714e090..c9c2670f7 100644 --- a/.docker/observability/otel-collector-config.yaml +++ b/.docker/observability/otel-collector-config.yaml @@ -32,11 +32,11 @@ processors: error_mode: ignore metric_statements: # RustFS process metrics already expose process_pid as a metric label. - # Keep process.pid on other metrics (including lock histograms) so their - # Prometheus series remain attributable across process restarts. + # Remove only the duplicate datapoint label and keep the shared resource + # process.pid available to sibling metrics and lock histograms. - context: metric statements: - - delete_key(resource.attributes, "process.pid") where IsMatch(name, "^rustfs_system_process_") + - delete_key(attributes, "process_pid") where IsMatch(name, "^rustfs_system_process_") transform/logs: error_mode: ignore log_statements: diff --git a/crates/io-metrics/src/lock_metrics.rs b/crates/io-metrics/src/lock_metrics.rs index 9b289a86a..cc9d78f8a 100644 --- a/crates/io-metrics/src/lock_metrics.rs +++ b/crates/io-metrics/src/lock_metrics.rs @@ -14,12 +14,8 @@ //! Lock optimization metrics recording functions. -use std::sync::LazyLock; use std::time::Duration; -const PROCESS_PID_LABEL: &str = "process_pid"; -static PROCESS_PID_VALUE: LazyLock = LazyLock::new(|| std::process::id().to_string()); - /// Record lock optimization enabled. #[inline(always)] pub fn record_lock_optimization_enabled(enabled: bool) { @@ -153,8 +149,7 @@ pub fn record_object_lock_diag_acquire_duration(op: &'static str, mode: &'static histogram!( "rustfs_object_lock_diag_acquire_duration_seconds", "op" => op, - "mode" => mode, - PROCESS_PID_LABEL => PROCESS_PID_VALUE.as_str() + "mode" => mode ) .record(duration.as_secs_f64()); } @@ -166,8 +161,7 @@ pub fn record_object_lock_diag_hold_duration(op: &'static str, mode: &'static st histogram!( "rustfs_object_lock_diag_hold_duration_seconds", "op" => op, - "mode" => mode, - PROCESS_PID_LABEL => PROCESS_PID_VALUE.as_str() + "mode" => mode ) .record(duration.as_secs_f64()); } @@ -179,8 +173,7 @@ pub fn record_object_lock_diag_slow_acquire(op: &'static str, mode: &'static str counter!( "rustfs_object_lock_diag_slow_acquire_total", "op" => op, - "mode" => mode, - PROCESS_PID_LABEL => PROCESS_PID_VALUE.as_str() + "mode" => mode ) .increment(1); } @@ -192,8 +185,7 @@ pub fn record_object_lock_diag_slow_hold(op: &'static str, mode: &'static str) { counter!( "rustfs_object_lock_diag_slow_hold_total", "op" => op, - "mode" => mode, - PROCESS_PID_LABEL => PROCESS_PID_VALUE.as_str() + "mode" => mode ) .increment(1); } @@ -439,16 +431,6 @@ mod tests { recorder.saw_histogram_named("rustfs_object_lock_diag_acquire_duration_seconds"), "expected object lock diagnostics acquire histogram to be emitted" ); - let histogram_keys = recorder.histograms.lock().expect("histogram keys should be lockable"); - let key = histogram_keys - .iter() - .find(|key| key.name() == "rustfs_object_lock_diag_acquire_duration_seconds") - .expect("acquire histogram key should be registered"); - assert!( - key.labels() - .any(|label| label.key() == PROCESS_PID_LABEL && label.value() == std::process::id().to_string()), - "lock histogram must carry the emitting process PID" - ); } #[test]