From 2842aa6d23f80c09eabf3c467772f9959fefae69 Mon Sep 17 00:00:00 2001 From: timedout Date: Mon, 16 Nov 2026 00:24:56 +0000 Subject: [PATCH] feat: Improve tracing --- src/service/rooms/queue/mod.rs | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/service/rooms/queue/mod.rs b/src/service/rooms/queue/mod.rs index a838d4194..10d72c64b 100644 --- a/src/service/rooms/queue/mod.rs +++ b/src/service/rooms/queue/mod.rs @@ -5,7 +5,9 @@ use std::{ }; use async_trait::async_trait; -use conduwuit::{Error, Server, debug, err, error, utils::millis_since_unix_epoch}; +use conduwuit::{ + Error, Result, Server, SyncMutex, debug, err, error, info, utils::millis_since_unix_epoch, +}; use opentelemetry::KeyValue; use ruma::{ CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, OwnedRoomId, OwnedServerName, @@ -30,7 +32,7 @@ pub struct Services { } pub struct Service { - queues: conduwuit::SyncMutex>>, + queues: SyncMutex>>, send: Sender, recv: tokio::sync::Mutex>, shutdown: Notify, @@ -39,13 +41,13 @@ pub struct Service { #[async_trait] impl crate::Service for Service { - fn build(args: Args<'_>) -> conduwuit::Result> + fn build(args: Args<'_>) -> Result> where Self: Sized, { let (send, recv) = mpsc::channel(1); Ok(Arc::new(Self { - queues: conduwuit::SyncMutex::new(HashMap::new()), + queues: SyncMutex::new(HashMap::new()), shutdown: Notify::new(), send, recv: tokio::sync::Mutex::new(recv), @@ -56,7 +58,7 @@ impl crate::Service for Service { })) } - async fn worker(self: Arc) -> conduwuit::Result<()> { + async fn worker(self: Arc) -> Result<()> { let mut recv = self.recv.lock().await; let mut handles = JoinSet::new(); let (yielder, mut yielding) = mpsc::channel(5); @@ -64,7 +66,7 @@ impl crate::Service for Service { loop { let job = tokio::select! { () = self.shutdown.notified() => { - conduwuit::info!("Shutting down"); + info!("Shutting down"); yielding.close(); recv.close(); break; @@ -78,7 +80,7 @@ impl crate::Service for Service { job = recv.recv() => job }; let Some(job) = job else { - conduwuit::debug!("No job (channel closed)"); + debug!("No job (channel closed)"); break; }; @@ -130,7 +132,7 @@ impl crate::Service for Service { } impl Service { - pub async fn new_job(&self, job: QueueJob) -> conduwuit::Result<()> { + pub async fn new_job(&self, job: QueueJob) -> Result<()> { self.send .send(job) .await @@ -144,29 +146,39 @@ impl Service { mut channel: UnboundedReceiver, yielder: Sender, ) { + debug!("Room worker starting up"); loop { let job = tokio::select! { () = self.shutdown.notified() => { + debug!("Room worker shutting down"); channel.close(); return; }, () = tokio::time::sleep(Duration::from_mins(5)) => { + debug!("Room worker self-reaping (no activity in 5 minutes)"); yielder.send(room_id).await.ok(); + debug!("Room worker reaped. Goodbye."); return; }, job = channel.recv() => job }; let Some(job) = job else { - conduwuit::debug!("No job (channel closed)"); + debug!("Room worker channel closed without shutdown?"); break; }; - conduwuit::debug!(event_id=%job.event_id, origin=%job.origin, "Handling incoming job"); + debug!( + event_id=%job.event_id, + origin=%job.origin, + backpressure=%channel.len(), + "Handling incoming job" + ); let _room_lock = self .services .event_handler .mutex_federation .lock(room_id.as_str()) .await; + debug!(event_id=%job.event_id, origin=%job.origin, "Acquired room federation lock"); let event_type = KeyValue::new( "type", @@ -206,6 +218,7 @@ impl Service { instruments .federation_incoming_pdus .add(1, &[event_type, outcome]); + debug!(event_id=%job.event_id, origin=%job.origin, "Job finished"); } } }