From b8e13fb026ddbb241bf937edb16f70854b867804 Mon Sep 17 00:00:00 2001 From: Ross Golder Date: Mon, 23 Feb 2026 04:09:25 +0700 Subject: [PATCH] Fix duplicate static definitions and functions in metrics.rs to resolve compilation errors --- src/metrics.rs | 101 ------------------------------------------------- 1 file changed, 101 deletions(-) diff --git a/src/metrics.rs b/src/metrics.rs index 7a2e7550..70a67558 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -138,108 +138,7 @@ pub fn increment_auth_attempts(method: &str, status: &str) { AUTH_ATTEMPTS_TOTAL.with_label_values(&[method, status]).inc(); } -// Database metrics -#[cfg(feature = "enable_metrics")] -static DB_CONNECTIONS_ACTIVE: Lazy = Lazy::new(|| { - register_int_gauge_vec!("vaultwarden_db_connections_active", "Number of active database connections", &["database"]) - .unwrap() -}); - -#[cfg(feature = "enable_metrics")] -static DB_CONNECTIONS_IDLE: Lazy = Lazy::new(|| { - register_int_gauge_vec!("vaultwarden_db_connections_idle", "Number of idle database connections", &["database"]) - .unwrap() -}); - -#[cfg(feature = "enable_metrics")] -static DB_QUERY_DURATION_SECONDS: Lazy = Lazy::new(|| { - register_histogram_vec!( - "vaultwarden_db_query_duration_seconds", - "Database query duration in seconds", - &["operation"], - vec![0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0] - ) - .unwrap() -}); -// Authentication metrics -#[cfg(feature = "enable_metrics")] -static AUTH_ATTEMPTS_TOTAL: Lazy = Lazy::new(|| { - register_int_counter_vec!( - "vaultwarden_auth_attempts_total", - "Total number of authentication attempts", - &["method", "status"] - ) - .unwrap() -}); - -#[cfg(feature = "enable_metrics")] -static USER_SESSIONS_ACTIVE: Lazy = Lazy::new(|| { - register_int_gauge_vec!("vaultwarden_user_sessions_active", "Number of active user sessions", &["user_type"]) - .unwrap() -}); - -// Business metrics -#[cfg(feature = "enable_metrics")] -static USERS_TOTAL: Lazy = - Lazy::new(|| register_int_gauge_vec!("vaultwarden_users_total", "Total number of users", &["status"]).unwrap()); - -#[cfg(feature = "enable_metrics")] -static ORGANIZATIONS_TOTAL: Lazy = Lazy::new(|| { - register_int_gauge_vec!("vaultwarden_organizations_total", "Total number of organizations", &["status"]).unwrap() -}); - -#[cfg(feature = "enable_metrics")] -static VAULT_ITEMS_TOTAL: Lazy = Lazy::new(|| { - register_int_gauge_vec!("vaultwarden_vault_items_total", "Total number of vault items", &["type", "organization"]) - .unwrap() -}); - -#[cfg(feature = "enable_metrics")] -static COLLECTIONS_TOTAL: Lazy = Lazy::new(|| { - register_int_gauge_vec!("vaultwarden_collections_total", "Total number of collections", &["organization"]).unwrap() -}); - -// System metrics -#[cfg(feature = "enable_metrics")] -static UPTIME_SECONDS: Lazy = - Lazy::new(|| register_gauge_vec!("vaultwarden_uptime_seconds", "Uptime in seconds", &["version"]).unwrap()); - -#[cfg(feature = "enable_metrics")] -static BUILD_INFO: Lazy = Lazy::new(|| { - register_int_gauge_vec!("vaultwarden_build_info", "Build information", &["version", "revision", "branch"]).unwrap() -}); - -/// Increment HTTP request counter -#[cfg(feature = "enable_metrics")] -pub fn increment_http_requests(method: &str, path: &str, status: u16) { - HTTP_REQUESTS_TOTAL.with_label_values(&[method, path, &status.to_string()]).inc(); -} - -/// Observe HTTP request duration -#[cfg(feature = "enable_metrics")] -pub fn observe_http_request_duration(method: &str, path: &str, duration_seconds: f64) { - HTTP_REQUEST_DURATION_SECONDS.with_label_values(&[method, path]).observe(duration_seconds); -} - -/// Update database connection metrics -#[cfg(feature = "enable_metrics")] -pub fn update_db_connections(database: &str, active: i64, idle: i64) { - DB_CONNECTIONS_ACTIVE.with_label_values(&[database]).set(active); - DB_CONNECTIONS_IDLE.with_label_values(&[database]).set(idle); -} - -/// Observe database query duration -#[cfg(feature = "enable_metrics")] -pub fn observe_db_query_duration(operation: &str, duration_seconds: f64) { - DB_QUERY_DURATION_SECONDS.with_label_values(&[operation]).observe(duration_seconds); -} - -/// Increment authentication attempts -#[cfg(feature = "enable_metrics")] -pub fn increment_auth_attempts(method: &str, status: &str) { - AUTH_ATTEMPTS_TOTAL.with_label_values(&[method, status]).inc(); -} /// Update active user sessions #[cfg(feature = "enable_metrics")]