From b8e8363a729aa8aecd331e4c484f691e2072528f Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 17 Mar 2023 14:32:13 -0700 Subject: [PATCH] Add logging and metric for time spent hashing auth tokens Co-authored-by: Mikayla Maki --- crates/collab/src/auth.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/crates/collab/src/auth.rs b/crates/collab/src/auth.rs index 9819e600c3..9ce602c577 100644 --- a/crates/collab/src/auth.rs +++ b/crates/collab/src/auth.rs @@ -8,13 +8,24 @@ use axum::{ middleware::Next, response::IntoResponse, }; +use lazy_static::lazy_static; +use prometheus::{exponential_buckets, register_histogram, Histogram}; use rand::thread_rng; use scrypt::{ password_hash::{PasswordHash, PasswordHasher, PasswordVerifier, SaltString}, Scrypt, }; use serde::{Deserialize, Serialize}; -use std::sync::Arc; +use std::{sync::Arc, time::Instant}; + +lazy_static! { + static ref METRIC_ACCESS_TOKEN_HASHING_TIME: Histogram = register_histogram!( + "access_token_hashing_time", + "time spent hashing access tokens", + exponential_buckets(10.0, 2.0, 10).unwrap(), + ) + .unwrap(); +} pub async fn validate_header(mut req: Request, next: Next) -> impl IntoResponse { let mut auth_header = req @@ -129,7 +140,12 @@ pub async fn verify_access_token(token: &str, user_id: UserId, db: &Arc