Browse Source

Fix clippy warnings: remove unused async and format code

- Remove async from update_health_metrics since it doesn't await
- Remove .await from call site in alive handler
- Add clippy allow attributes for Rocket handler
- Apply rustfmt formatting
pull/6202/head
Ross Golder 2 months ago
parent
commit
71e39c1095
  1. 10
      src/api/identity.rs
  2. 4
      src/api/metrics.rs
  3. 3
      src/api/web.rs
  4. 8
      src/metrics.rs

10
src/api/identity.rs

@ -30,9 +30,9 @@ use crate::{
DbConn,
},
error::MapResult,
mail, sso,
mail, metrics, sso,
sso::{OIDCCode, OIDCCodeChallenge, OIDCCodeVerifier, OIDCState},
util, CONFIG, metrics,
util, CONFIG,
};
pub fn routes() -> Vec<Route> {
@ -106,7 +106,11 @@ async fn login(
};
// Record authentication metrics
let auth_status = if login_result.is_ok() { "success" } else { "failed" };
let auth_status = if login_result.is_ok() {
"success"
} else {
"failed"
};
metrics::increment_auth_attempts(&auth_method, auth_status);
if let Some(user_id) = user_id {

4
src/api/metrics.rs

@ -103,7 +103,7 @@ async fn get_metrics(_token: MetricsToken, mut conn: DbConn) -> Result<RawText<S
/// Health check endpoint that also updates some basic metrics
#[cfg(feature = "enable_metrics")]
pub async fn update_health_metrics(_conn: &mut DbConn) {
pub fn update_health_metrics(_conn: &mut DbConn) {
// Update basic system metrics
use std::time::SystemTime;
static START_TIME: std::sync::OnceLock<SystemTime> = std::sync::OnceLock::new();
@ -117,4 +117,4 @@ pub async fn update_health_metrics(_conn: &mut DbConn) {
}
#[cfg(not(feature = "enable_metrics"))]
pub async fn update_health_metrics(_conn: &mut DbConn) {}
pub fn update_health_metrics(_conn: &mut DbConn) {}

3
src/api/web.rs

@ -179,9 +179,10 @@ async fn attachments(cipher_id: CipherId, file_id: AttachmentId, token: String)
// We use DbConn here to let the alive healthcheck also verify the database connection.
use crate::db::DbConn;
#[get("/alive")]
#[allow(clippy::let_unit_value, clippy::unused_async)]
async fn alive(mut conn: DbConn) -> Json<String> {
// Update basic health metrics if metrics are enabled
let _ = crate::api::metrics::update_health_metrics(&mut conn).await;
crate::api::metrics::update_health_metrics(&mut conn);
now()
}

8
src/metrics.rs

@ -4,14 +4,14 @@
use once_cell::sync::Lazy;
#[cfg(feature = "enable_metrics")]
use prometheus::{
register_gauge_vec, register_histogram_vec, register_int_counter_vec, register_int_gauge_vec,
Encoder, GaugeVec, HistogramVec, IntCounterVec, IntGaugeVec, TextEncoder,
register_gauge_vec, register_histogram_vec, register_int_counter_vec, register_int_gauge_vec, Encoder, GaugeVec,
HistogramVec, IntCounterVec, IntGaugeVec, TextEncoder,
};
use crate::{db::DbConn, error::Error, CONFIG};
use std::time::SystemTime;
#[cfg(feature = "enable_metrics")]
use std::sync::{Arc, RwLock};
use std::time::SystemTime;
#[cfg(feature = "enable_metrics")]
use std::time::UNIX_EPOCH;
@ -138,8 +138,6 @@ 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")]
pub fn update_user_sessions(user_type: &str, count: i64) {

Loading…
Cancel
Save