Browse Source

Fix remaining conflict markers from rebase

pull/6202/head
Ross Golder 2 months ago
parent
commit
b50d71cc41
  1. 29
      src/api/middleware.rs
  2. 17
      src/metrics.rs

29
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
@ -112,4 +124,3 @@ mod tests {
assert!(!is_uuid("123")); // Too short
}
}
}

17
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<IntGaugeVec> = Lazy::new(|| {
.unwrap()
});
<<<<<<< HEAD
=======
#[cfg(feature = "enable_metrics")]
static DB_QUERY_DURATION_SECONDS: Lazy<HistogramVec> = Lazy::new(|| {
register_histogram_vec!(
@ -61,8 +60,6 @@ static DB_QUERY_DURATION_SECONDS: Lazy<HistogramVec> = Lazy::new(|| {
)
.unwrap()
});
>>>>>>> dfe102f5 (feat: add comprehensive Prometheus metrics support)
// Authentication metrics
#[cfg(feature = "enable_metrics")]
static AUTH_ATTEMPTS_TOTAL: Lazy<IntCounterVec> = Lazy::new(|| {
@ -74,15 +71,11 @@ static AUTH_ATTEMPTS_TOTAL: Lazy<IntCounterVec> = Lazy::new(|| {
.unwrap()
});
<<<<<<< HEAD
=======
#[cfg(feature = "enable_metrics")]
static USER_SESSIONS_ACTIVE: Lazy<IntGaugeVec> = 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<IntGaugeVec> =
@ -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();

Loading…
Cancel
Save