diff --git a/backend/src/controller/crypto.rs b/backend/src/controller/crypto.rs index bf412ecc..3261e2ef 100644 --- a/backend/src/controller/crypto.rs +++ b/backend/src/controller/crypto.rs @@ -56,6 +56,7 @@ impl CryptoController { let salt = config.database.salt.as_bytes().to_vec(); Self { signer, salt } } + #[tracing::instrument(name="crypto_hasheq_controller",level = "debug",skip_all)] pub fn hash_eq(&self, src: &str, tar: &[u8]) -> bool { let hashed: Vec = self.hash(src).into(); let mut result = true; @@ -66,6 +67,7 @@ impl CryptoController { } result } + #[tracing::instrument(name="crypto_hash_controller",level = "debug",skip_all)] pub fn hash(&self, src: &str) -> HashValue { let hashed = digest::digest( &digest::SHA256, diff --git a/backend/src/controller/duplicate.rs b/backend/src/controller/duplicate.rs index 8fe9ad2e..1a6a2226 100644 --- a/backend/src/controller/duplicate.rs +++ b/backend/src/controller/duplicate.rs @@ -16,11 +16,13 @@ impl DupController { } } pub fn store(&self, user_id: i32, uuid: Uuid, result: i32) { + tracing::trace!(request_id=?uuid); #[cfg(feature = "single-instance")] self.dups.insert((user_id, uuid), result); } #[tracing::instrument(level = "debug", skip(self))] pub fn check(&self, user_id: i32, uuid: &Uuid) -> Option { + tracing::trace!(request_id=?uuid); #[cfg(feature = "single-instance")] if let Some(x) = self.dups.get(&(user_id, *uuid)) { log::debug!("duplicated request_id: {}, result: {}", uuid, x); diff --git a/backend/src/controller/token.rs b/backend/src/controller/token.rs index d715fcce..bcf820c7 100644 --- a/backend/src/controller/token.rs +++ b/backend/src/controller/token.rs @@ -65,7 +65,7 @@ pub struct TokenController { } impl TokenController { - #[tracing::instrument(parent = span,name="token_construct",level = "info",skip_all)] + #[tracing::instrument(parent = span,name="token_construct_controller",level = "info",skip_all)] pub fn new(span: &Span) -> Arc { log::debug!("Setup TokenController"); #[cfg(feature = "single-instance")] @@ -92,7 +92,7 @@ impl TokenController { }); self_ } - #[instrument(skip_all, name="token_create",fields(user = user.id))] + #[instrument(skip_all, name="token_create_controller",level="debug",fields(user = user.id))] pub async fn add( &self, user: &entity::user::Model, @@ -121,7 +121,7 @@ impl TokenController { )) } - #[instrument(skip_all, name = "token_verify")] + #[instrument(skip_all, name = "token_verify_controller",level="debug")] pub async fn verify(&self, token: &str) -> Result<(i32, UserPermBytes), Error> { let now = Local::now().naive_local(); let db = DB.get().unwrap(); @@ -179,7 +179,7 @@ impl TokenController { Ok((token.user_id, UserPermBytes(token.permission))) } - #[instrument(skip_all, name="token_removal", fields(token = token))] + #[instrument(skip_all, name="token_remove_controller",level="debug", fields(token = token))] pub async fn remove(&self, token: String) -> Result, Error> { let db = DB.get().unwrap(); @@ -197,7 +197,7 @@ impl TokenController { Ok(Some(())) } - #[instrument(skip_all, name="token_removal", fields(uid = user_id))] + #[instrument(skip_all, name="token_removal",level="debug", fields(uid = user_id))] pub async fn remove_by_user_id( &self, user_id: i32, diff --git a/backend/src/endpoint/token.rs b/backend/src/endpoint/token.rs index 6efef3eb..223c0aa6 100644 --- a/backend/src/endpoint/token.rs +++ b/backend/src/endpoint/token.rs @@ -45,6 +45,8 @@ impl TokenSet for Arc { .await .map_err(Into::::into)?; + tracing::trace!(token_count=tokens.len(),"retrieve_token"); + Ok(Response::new(Tokens { list: tokens.into_iter().map(Into::into).collect(), })) @@ -54,6 +56,8 @@ impl TokenSet for Arc { let db = DB.get().unwrap(); let (_, req) = self.parse_request(req).await?; + tracing::debug!(username=req.username); + let model = user::Entity::find() .filter(user::Column::Username.eq(req.username)) .one(db) @@ -76,6 +80,7 @@ impl TokenSet for Arc { expiry: into_prost(expiry), })) } else { + tracing::trace!("password_mismatch"); Err(Error::PremissionDeny("password").into()) } } diff --git a/backend/src/endpoint/user.rs b/backend/src/endpoint/user.rs index cab7060a..2dafc924 100644 --- a/backend/src/endpoint/user.rs +++ b/backend/src/endpoint/user.rs @@ -174,7 +174,7 @@ impl UserSet for Arc { let mut model: ActiveModel = Default::default(); - log::info!("creating user({})", req.info.username); + tracing::debug!(username= req.info.username); fill_active_model!(model, req.info, username); diff --git a/backend/src/init/db.rs b/backend/src/init/db.rs index 4523c15e..cb606226 100644 --- a/backend/src/init/db.rs +++ b/backend/src/init/db.rs @@ -1,6 +1,6 @@ use ring::digest; use sea_orm::{ - ActiveModelTrait, ActiveValue, Database, DatabaseConnection, EntityTrait, PaginatorTrait, + ActiveModelTrait, ActiveValue, Database, DatabaseConnection, EntityTrait, PaginatorTrait, DbBackend, Statement, ConnectionTrait, }; use tokio::sync::OnceCell; @@ -12,12 +12,13 @@ pub static DB: OnceCell = OnceCell::const_new(); pub async fn init(config: &config::Database) { // sqlite://database/backend.sqlite?mode=rwc - let uri = format!("sqlite://{}", config.path.clone()); + let uri = format!("sqlite://{}?mode=rwc&cache=private", config.path.clone()); let db = Database::connect(&uri) .await .expect("fail connecting to database"); init_user(config, &db).await; + DB.set(db).ok(); } fn hash(config: &config::Database, src: &str) -> Vec { diff --git a/backend/src/server.rs b/backend/src/server.rs index c51789b5..98d2403e 100644 --- a/backend/src/server.rs +++ b/backend/src/server.rs @@ -78,7 +78,7 @@ impl Server { } pub async fn start(self: Arc) { transport::Server::builder() - // .accept_http1(true) + .accept_http1(true) .tls_config(transport::ServerTlsConfig::new().identity(self.identity.clone())) .unwrap() .max_frame_size(Some(MAX_FRAME_SIZE)) @@ -90,6 +90,7 @@ impl Server { .add_service(tonic_web::enable(TestcaseSetServer::new(self.clone()))) .add_service(tonic_web::enable(SubmitSetServer::new(self.clone()))) .serve(self.config.bind_address.clone().parse().unwrap()) + .instrument(tracing::info_span!("server_serve")) .await .unwrap(); }