From b50d71cc4155ff59d4ec566eedf1797f877d5419 Mon Sep 17 00:00:00 2001 From: Ross Golder Date: Sun, 22 Feb 2026 18:14:28 +0700 Subject: [PATCH] Fix remaining conflict markers from rebase --- src/api/middleware.rs | 29 ++++++++++++++++++++--------- src/metrics.rs | 17 ++--------------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/api/middleware.rs b/src/api/middleware.rs index 7b651967..bc7308d6 100644 --- a/src/api/middleware.rs +++ b/src/api/middleware.rs @@ -52,7 +52,6 @@ fn normalize_path(path: &str) -> String { continue; } -<<<<<<< HEAD // Common patterns in Vaultwarden routes let normalized_segment = if is_uuid(segment) { "{id}" @@ -74,14 +73,27 @@ fn normalize_path(path: &str) -> String { } } -/// Check if a string looks like a UUID -fn is_uuid(s: &str) -> bool { - s.len() == 36 - && s.chars().enumerate().all(|(i, c)| match i { - 8 | 13 | 18 | 23 => c == '-', - _ => c.is_ascii_hexdigit(), - }) + // Common patterns in Vaultwarden routes + let normalized_segment = if is_uuid(segment) { + "{id}" + } else if segment.chars().all(|c| c.is_ascii_hexdigit()) && segment.len() > 10 { + "{hash}" + } else if segment.chars().all(|c| c.is_ascii_digit()) { + "{number}" + } else { + segment + }; + + normalized.push(normalized_segment); + } + + if normalized.is_empty() { + "/".to_string() + } else { + format!("/{}", normalized.join("/")) + } } + /// Check if a string looks like a UUID fn is_uuid(s: &str) -> bool { s.len() == 36 @@ -111,5 +123,4 @@ mod tests { assert!(!is_uuid("12345678123456781234567812345678")); // No dashes assert!(!is_uuid("123")); // Too short } - } } diff --git a/src/metrics.rs b/src/metrics.rs index fe651f7a..7a2e7550 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -9,10 +9,11 @@ use prometheus::{ }; use crate::{db::DbConn, error::Error, CONFIG}; +use std::time::SystemTime; #[cfg(feature = "enable_metrics")] use std::sync::{Arc, RwLock}; #[cfg(feature = "enable_metrics")] -use std::time::{SystemTime, UNIX_EPOCH}; +use std::time::UNIX_EPOCH; // HTTP request metrics #[cfg(feature = "enable_metrics")] @@ -49,8 +50,6 @@ static DB_CONNECTIONS_IDLE: Lazy = Lazy::new(|| { .unwrap() }); -<<<<<<< HEAD -======= #[cfg(feature = "enable_metrics")] static DB_QUERY_DURATION_SECONDS: Lazy = Lazy::new(|| { register_histogram_vec!( @@ -61,8 +60,6 @@ static DB_QUERY_DURATION_SECONDS: Lazy = Lazy::new(|| { ) .unwrap() }); - ->>>>>>> dfe102f5 (feat: add comprehensive Prometheus metrics support) // Authentication metrics #[cfg(feature = "enable_metrics")] static AUTH_ATTEMPTS_TOTAL: Lazy = Lazy::new(|| { @@ -74,15 +71,11 @@ static AUTH_ATTEMPTS_TOTAL: Lazy = Lazy::new(|| { .unwrap() }); -<<<<<<< HEAD -======= #[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() }); - ->>>>>>> dfe102f5 (feat: add comprehensive Prometheus metrics support) // Business metrics #[cfg(feature = "enable_metrics")] static USERS_TOTAL: Lazy = @@ -133,11 +126,6 @@ pub fn update_db_connections(database: &str, active: i64, idle: i64) { DB_CONNECTIONS_IDLE.with_label_values(&[database]).set(idle); } -<<<<<<< HEAD -/// Increment authentication attempts (success/failure tracking) -/// Tracks authentication success/failure by method (password, client_credentials, SSO, etc.) -/// Called from src/api/identity.rs login() after each authentication attempt -======= /// Observe database query duration #[cfg(feature = "enable_metrics")] pub fn observe_db_query_duration(operation: &str, duration_seconds: f64) { @@ -145,7 +133,6 @@ pub fn observe_db_query_duration(operation: &str, duration_seconds: f64) { } /// Increment authentication attempts ->>>>>>> dfe102f5 (feat: add comprehensive Prometheus metrics support) #[cfg(feature = "enable_metrics")] pub fn increment_auth_attempts(method: &str, status: &str) { AUTH_ATTEMPTS_TOTAL.with_label_values(&[method, status]).inc();