From bc263701e252aaffa3b68819827de47020bc1d48 Mon Sep 17 00:00:00 2001 From: asonix Date: Tue, 1 Nov 2022 15:57:33 -0500 Subject: [PATCH] Log cleanup --- src/config.rs | 7 ++++--- src/data/actor.rs | 8 ++++---- src/data/media.rs | 12 ++++++------ src/data/node.rs | 12 +++++++----- src/data/state.rs | 3 ++- src/jobs/apub/announce.rs | 5 +++-- src/jobs/apub/follow.rs | 24 +++++++++++++++++------- src/jobs/apub/forward.rs | 2 +- src/jobs/apub/reject.rs | 7 +++++-- src/jobs/apub/undo.rs | 5 +++-- src/jobs/cache_media.rs | 2 +- src/jobs/deliver.rs | 2 +- src/jobs/deliver_many.rs | 2 +- src/jobs/instance.rs | 2 +- src/jobs/nodeinfo.rs | 2 +- src/jobs/process_listeners.rs | 5 +++-- src/middleware/verifier.rs | 2 +- src/requests.rs | 9 +++++---- src/routes/actor.rs | 2 +- src/routes/inbox.rs | 2 +- src/routes/index.rs | 2 +- src/routes/nodeinfo.rs | 2 +- 22 files changed, 70 insertions(+), 49 deletions(-) diff --git a/src/config.rs b/src/config.rs index c61bc2b..dc030b9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -229,11 +229,12 @@ impl Config { self.do_generate_url(kind).expect("Generated valid IRI") } - #[tracing::instrument(fields(base_uri = tracing::field::debug(&self.base_uri), kind = tracing::field::debug(&kind)))] + #[tracing::instrument(level = "debug", skip_all, fields(base_uri = tracing::field::debug(&self.base_uri), kind = tracing::field::debug(&kind)))] fn do_generate_url(&self, kind: UrlKind) -> Result { let iri = match kind { - UrlKind::Activity => FixedBaseResolver::new(self.base_uri.as_ref()) - .try_resolve(IriRelativeStr::new(&format!("activity/{}", Uuid::new_v4()))?.as_ref())?, + UrlKind::Activity => FixedBaseResolver::new(self.base_uri.as_ref()).try_resolve( + IriRelativeStr::new(&format!("activity/{}", Uuid::new_v4()))?.as_ref(), + )?, UrlKind::Actor => FixedBaseResolver::new(self.base_uri.as_ref()) .try_resolve(IriRelativeStr::new("actor")?.as_ref())?, UrlKind::Followers => FixedBaseResolver::new(self.base_uri.as_ref()) diff --git a/src/data/actor.rs b/src/data/actor.rs index 59c5c2f..fe35a41 100644 --- a/src/data/actor.rs +++ b/src/data/actor.rs @@ -37,7 +37,7 @@ impl ActorCache { ActorCache { db } } - #[tracing::instrument(name = "Get Actor", fields(id = id.to_string().as_str(), requests))] + #[tracing::instrument(name = "Get Actor", skip_all, fields(id = id.to_string().as_str(), requests))] pub(crate) async fn get( &self, id: &IriString, @@ -54,18 +54,18 @@ impl ActorCache { .map(MaybeCached::Fetched) } - #[tracing::instrument(name = "Add Connection")] + #[tracing::instrument(name = "Add Connection", skip(self))] pub(crate) async fn add_connection(&self, actor: Actor) -> Result<(), Error> { self.db.add_connection(actor.id.clone()).await?; self.db.save_actor(actor).await } - #[tracing::instrument(name = "Remove Connection")] + #[tracing::instrument(name = "Remove Connection", skip(self))] pub(crate) async fn remove_connection(&self, actor: &Actor) -> Result<(), Error> { self.db.remove_connection(actor.id.clone()).await } - #[tracing::instrument(name = "Fetch remote actor", fields(id = id.to_string().as_str(), requests))] + #[tracing::instrument(name = "Fetch remote actor", skip_all, fields(id = id.to_string().as_str(), requests))] pub(crate) async fn get_no_cache( &self, id: &IriString, diff --git a/src/data/media.rs b/src/data/media.rs index f504a03..18bc6e4 100644 --- a/src/data/media.rs +++ b/src/data/media.rs @@ -19,17 +19,17 @@ impl MediaCache { MediaCache { db } } - #[tracing::instrument(name = "Get media uuid", fields(url = url.to_string().as_str()))] + #[tracing::instrument(name = "Get media uuid", skip_all, fields(url = url.to_string().as_str()))] pub(crate) async fn get_uuid(&self, url: IriString) -> Result, Error> { self.db.media_id(url).await } - #[tracing::instrument(name = "Get media url")] + #[tracing::instrument(name = "Get media url", skip(self))] pub(crate) async fn get_url(&self, uuid: Uuid) -> Result, Error> { self.db.media_url(uuid).await } - #[tracing::instrument(name = "Is media outdated")] + #[tracing::instrument(name = "Is media outdated", skip(self))] pub(crate) async fn is_outdated(&self, uuid: Uuid) -> Result { if let Some(meta) = self.db.media_meta(uuid).await? { if meta.saved_at + MEDIA_DURATION > SystemTime::now() { @@ -40,7 +40,7 @@ impl MediaCache { Ok(true) } - #[tracing::instrument(name = "Get media bytes")] + #[tracing::instrument(name = "Get media bytes", skip(self))] pub(crate) async fn get_bytes(&self, uuid: Uuid) -> Result, Error> { if let Some(meta) = self.db.media_meta(uuid).await? { if meta.saved_at + MEDIA_DURATION > SystemTime::now() { @@ -55,7 +55,7 @@ impl MediaCache { Ok(None) } - #[tracing::instrument(name = "Store media url", fields(url = url.to_string().as_str()))] + #[tracing::instrument(name = "Store media url", skip_all, fields(url = url.to_string().as_str()))] pub(crate) async fn store_url(&self, url: IriString) -> Result { let uuid = Uuid::new_v4(); @@ -64,7 +64,7 @@ impl MediaCache { Ok(uuid) } - #[tracing::instrument(name = "store media bytes", skip(bytes))] + #[tracing::instrument(name = "store media bytes", skip(self, bytes))] pub(crate) async fn store_bytes( &self, uuid: Uuid, diff --git a/src/data/node.rs b/src/data/node.rs index 42a2260..c101a0a 100644 --- a/src/data/node.rs +++ b/src/data/node.rs @@ -34,7 +34,7 @@ impl NodeCache { NodeCache { db } } - #[tracing::instrument(name = "Get nodes")] + #[tracing::instrument(name = "Get nodes", skip(self))] pub(crate) async fn nodes(&self) -> Result, Error> { let infos = self.db.connected_info().await?; let instances = self.db.connected_instance().await?; @@ -57,7 +57,7 @@ impl NodeCache { Ok(vec) } - #[tracing::instrument(name = "Is NodeInfo Outdated", fields(actor_id = actor_id.to_string().as_str()))] + #[tracing::instrument(name = "Is NodeInfo Outdated", skip_all, fields(actor_id = actor_id.to_string().as_str()))] pub(crate) async fn is_nodeinfo_outdated(&self, actor_id: IriString) -> bool { self.db .info(actor_id) @@ -66,7 +66,7 @@ impl NodeCache { .unwrap_or(true) } - #[tracing::instrument(name = "Is Contact Outdated", fields(actor_id = actor_id.to_string().as_str()))] + #[tracing::instrument(name = "Is Contact Outdated", skip_all, fields(actor_id = actor_id.to_string().as_str()))] pub(crate) async fn is_contact_outdated(&self, actor_id: IriString) -> bool { self.db .contact(actor_id) @@ -75,7 +75,7 @@ impl NodeCache { .unwrap_or(true) } - #[tracing::instrument(name = "Is Instance Outdated", fields(actor_id = actor_id.to_string().as_str()))] + #[tracing::instrument(name = "Is Instance Outdated", skip_all, fields(actor_id = actor_id.to_string().as_str()))] pub(crate) async fn is_instance_outdated(&self, actor_id: IriString) -> bool { self.db .instance(actor_id) @@ -84,7 +84,7 @@ impl NodeCache { .unwrap_or(true) } - #[tracing::instrument(name = "Save node info", fields(actor_id = actor_id.to_string().as_str(), software, version, reg))] + #[tracing::instrument(name = "Save node info", skip_all, fields(actor_id = actor_id.to_string().as_str(), software, version, reg))] pub(crate) async fn set_info( &self, actor_id: IriString, @@ -107,6 +107,7 @@ impl NodeCache { #[tracing::instrument( name = "Save instance info", + skip_all, fields( actor_id = actor_id.to_string().as_str(), title, @@ -142,6 +143,7 @@ impl NodeCache { #[tracing::instrument( name = "Save contact info", + skip_all, fields( actor_id = actor_id.to_string().as_str(), username, diff --git a/src/data/state.rs b/src/data/state.rs index f205b82..a9dcd49 100644 --- a/src/data/state.rs +++ b/src/data/state.rs @@ -50,6 +50,7 @@ impl State { #[tracing::instrument( name = "Get inboxes for other domains", + skip_all, fields( existing_inbox = existing_inbox.to_string().as_str(), authority @@ -85,7 +86,7 @@ impl State { self.object_cache.write().await.put(object_id, actor_id); } - #[tracing::instrument(name = "Building state")] + #[tracing::instrument(name = "Building state", skip_all)] pub(crate) async fn build(db: Db) -> Result { let private_key = if let Ok(Some(key)) = db.private_key().await { info!("Using existing key"); diff --git a/src/jobs/apub/announce.rs b/src/jobs/apub/announce.rs index 69b3e72..d03f48e 100644 --- a/src/jobs/apub/announce.rs +++ b/src/jobs/apub/announce.rs @@ -31,7 +31,7 @@ impl Announce { Announce { object_id, actor } } - #[tracing::instrument(name = "Announce")] + #[tracing::instrument(name = "Announce", skip(state))] async fn perform(self, state: JobState) -> Result<(), Error> { let activity_id = state.config.generate_url(UrlKind::Activity); @@ -39,7 +39,8 @@ impl Announce { let inboxes = get_inboxes(&state.state, &self.actor, &self.object_id).await?; state .job_server - .queue(DeliverMany::new(inboxes, announce)?).await?; + .queue(DeliverMany::new(inboxes, announce)?) + .await?; state.state.cache(self.object_id, activity_id).await; Ok(()) diff --git a/src/jobs/apub/follow.rs b/src/jobs/apub/follow.rs index 3663276..e76f0ca 100644 --- a/src/jobs/apub/follow.rs +++ b/src/jobs/apub/follow.rs @@ -7,8 +7,8 @@ use crate::{ }; use activitystreams::{ activity::{Accept as AsAccept, Follow as AsFollow}, - prelude::*, iri_string::types::IriString, + prelude::*, }; use background_jobs::ActixJob; use std::{future::Future, pin::Pin}; @@ -24,7 +24,7 @@ impl Follow { Follow { input, actor } } - #[tracing::instrument(name = "Follow")] + #[tracing::instrument(name = "Follow", skip(state))] async fn perform(self, state: JobState) -> Result<(), Error> { let my_id = state.config.generate_url(UrlKind::Actor); @@ -35,7 +35,8 @@ impl Follow { let follow = generate_follow(&state.config, &self.actor.id, &my_id)?; state .job_server - .queue(Deliver::new(self.actor.inbox.clone(), follow)?).await?; + .queue(Deliver::new(self.actor.inbox.clone(), follow)?) + .await?; } state.actors.add_connection(self.actor.clone()).await?; @@ -49,20 +50,29 @@ impl Follow { state .job_server - .queue(Deliver::new(self.actor.inbox, accept)?).await?; + .queue(Deliver::new(self.actor.inbox, accept)?) + .await?; state .job_server - .queue(QueryInstance::new(self.actor.id.clone())).await?; + .queue(QueryInstance::new(self.actor.id.clone())) + .await?; - state.job_server.queue(QueryNodeinfo::new(self.actor.id)).await?; + state + .job_server + .queue(QueryNodeinfo::new(self.actor.id)) + .await?; Ok(()) } } // Generate a type that says "I want to follow you" -fn generate_follow(config: &Config, actor_id: &IriString, my_id: &IriString) -> Result { +fn generate_follow( + config: &Config, + actor_id: &IriString, + my_id: &IriString, +) -> Result { let follow = AsFollow::new(my_id.clone(), actor_id.clone()); prepare_activity( diff --git a/src/jobs/apub/forward.rs b/src/jobs/apub/forward.rs index 1a6c613..e790826 100644 --- a/src/jobs/apub/forward.rs +++ b/src/jobs/apub/forward.rs @@ -19,7 +19,7 @@ impl Forward { Forward { input, actor } } - #[tracing::instrument(name = "Forward")] + #[tracing::instrument(name = "Forward", skip(state))] async fn perform(self, state: JobState) -> Result<(), Error> { let object_id = self .input diff --git a/src/jobs/apub/reject.rs b/src/jobs/apub/reject.rs index 969140f..43a8553 100644 --- a/src/jobs/apub/reject.rs +++ b/src/jobs/apub/reject.rs @@ -11,14 +11,17 @@ use std::{future::Future, pin::Pin}; pub(crate) struct Reject(pub(crate) Actor); impl Reject { - #[tracing::instrument(name = "Reject")] + #[tracing::instrument(name = "Reject", skip(state))] async fn perform(self, state: JobState) -> Result<(), Error> { state.actors.remove_connection(&self.0).await?; let my_id = state.config.generate_url(UrlKind::Actor); let undo = generate_undo_follow(&state.config, &self.0.id, &my_id)?; - state.job_server.queue(Deliver::new(self.0.inbox, undo)?).await?; + state + .job_server + .queue(Deliver::new(self.0.inbox, undo)?) + .await?; Ok(()) } diff --git a/src/jobs/apub/undo.rs b/src/jobs/apub/undo.rs index afb320f..e6fd1d1 100644 --- a/src/jobs/apub/undo.rs +++ b/src/jobs/apub/undo.rs @@ -19,7 +19,7 @@ impl Undo { Undo { input, actor } } - #[tracing::instrument(name = "Undo")] + #[tracing::instrument(name = "Undo", skip(state))] async fn perform(self, state: JobState) -> Result<(), Error> { let was_following = state.state.db.is_connected(self.actor.id.clone()).await?; @@ -30,7 +30,8 @@ impl Undo { let undo = generate_undo_follow(&state.config, &self.actor.id, &my_id)?; state .job_server - .queue(Deliver::new(self.actor.inbox, undo)?).await?; + .queue(Deliver::new(self.actor.inbox, undo)?) + .await?; } Ok(()) diff --git a/src/jobs/cache_media.rs b/src/jobs/cache_media.rs index 640cfca..718a059 100644 --- a/src/jobs/cache_media.rs +++ b/src/jobs/cache_media.rs @@ -13,7 +13,7 @@ impl CacheMedia { CacheMedia { uuid } } - #[tracing::instrument(name = "Cache media")] + #[tracing::instrument(name = "Cache media", skip(state))] async fn perform(self, state: JobState) -> Result<(), Error> { if !state.media.is_outdated(self.uuid).await? { return Ok(()); diff --git a/src/jobs/deliver.rs b/src/jobs/deliver.rs index ee3ce48..eb86ab8 100644 --- a/src/jobs/deliver.rs +++ b/src/jobs/deliver.rs @@ -29,7 +29,7 @@ impl Deliver { }) } - #[tracing::instrument(name = "Deliver")] + #[tracing::instrument(name = "Deliver", skip(state))] async fn permform(self, state: JobState) -> Result<(), Error> { state.requests.deliver(self.to, &self.data).await?; Ok(()) diff --git a/src/jobs/deliver_many.rs b/src/jobs/deliver_many.rs index c131168..e37a12d 100644 --- a/src/jobs/deliver_many.rs +++ b/src/jobs/deliver_many.rs @@ -40,7 +40,7 @@ impl DeliverMany { }) } - #[tracing::instrument(name = "Deliver many")] + #[tracing::instrument(name = "Deliver many", skip(state))] async fn perform(self, state: JobState) -> Result<(), Error> { for inbox in self.to { state diff --git a/src/jobs/instance.rs b/src/jobs/instance.rs index dd143bf..df09ad8 100644 --- a/src/jobs/instance.rs +++ b/src/jobs/instance.rs @@ -25,7 +25,7 @@ impl QueryInstance { QueryInstance { actor_id } } - #[tracing::instrument(name = "Query instance")] + #[tracing::instrument(name = "Query instance", skip(state))] async fn perform(self, state: JobState) -> Result<(), Error> { let contact_outdated = state .node_cache diff --git a/src/jobs/nodeinfo.rs b/src/jobs/nodeinfo.rs index ae2e500..ccaa48d 100644 --- a/src/jobs/nodeinfo.rs +++ b/src/jobs/nodeinfo.rs @@ -24,7 +24,7 @@ impl QueryNodeinfo { QueryNodeinfo { actor_id } } - #[tracing::instrument(name = "Query node info")] + #[tracing::instrument(name = "Query node info", skip(state))] async fn perform(self, state: JobState) -> Result<(), Error> { if !state .node_cache diff --git a/src/jobs/process_listeners.rs b/src/jobs/process_listeners.rs index dc8cbc6..bba4e00 100644 --- a/src/jobs/process_listeners.rs +++ b/src/jobs/process_listeners.rs @@ -9,12 +9,13 @@ use std::{future::Future, pin::Pin}; pub(crate) struct Listeners; impl Listeners { - #[tracing::instrument(name = "Spawn query instances")] + #[tracing::instrument(name = "Spawn query instances", skip(state))] async fn perform(self, state: JobState) -> Result<(), Error> { for actor_id in state.state.db.connected_ids().await? { state .job_server - .queue(QueryInstance::new(actor_id.clone())).await?; + .queue(QueryInstance::new(actor_id.clone())) + .await?; state.job_server.queue(QueryNodeinfo::new(actor_id)).await?; } diff --git a/src/middleware/verifier.rs b/src/middleware/verifier.rs index 7e05f10..b371fbd 100644 --- a/src/middleware/verifier.rs +++ b/src/middleware/verifier.rs @@ -16,7 +16,7 @@ use std::{future::Future, pin::Pin}; pub(crate) struct MyVerify(pub Requests, pub ActorCache, pub State); impl MyVerify { - #[tracing::instrument("Verify signature")] + #[tracing::instrument("Verify signature", skip(self))] async fn verify( &self, algorithm: Option, diff --git a/src/requests.rs b/src/requests.rs index 245211e..74ccb95 100644 --- a/src/requests.rs +++ b/src/requests.rs @@ -203,7 +203,7 @@ impl Requests { self.consecutive_errors.swap(0, Ordering::Relaxed); } - #[tracing::instrument(name = "Fetch Json")] + #[tracing::instrument(name = "Fetch Json", skip(self))] pub(crate) async fn fetch_json(&self, url: &str) -> Result where T: serde::de::DeserializeOwned, @@ -211,7 +211,7 @@ impl Requests { self.do_fetch(url, "application/json").await } - #[tracing::instrument(name = "Fetch Activity+Json")] + #[tracing::instrument(name = "Fetch Activity+Json", skip(self))] pub(crate) async fn fetch(&self, url: &str) -> Result where T: serde::de::DeserializeOwned, @@ -278,7 +278,7 @@ impl Requests { Ok(serde_json::from_slice(body.as_ref())?) } - #[tracing::instrument(name = "Fetch Bytes")] + #[tracing::instrument(name = "Fetch Bytes", skip(self))] pub(crate) async fn fetch_bytes(&self, url: &str) -> Result<(String, Bytes), Error> { let parsed_url = url.parse::()?; @@ -350,7 +350,8 @@ impl Requests { #[tracing::instrument( "Deliver to Inbox", - fields(self, inbox = inbox.to_string().as_str(), item) + skip_all, + fields(inbox = inbox.to_string().as_str(), item) )] pub(crate) async fn deliver(&self, inbox: IriString, item: &T) -> Result<(), Error> where diff --git a/src/routes/actor.rs b/src/routes/actor.rs index 5c2e5f9..1faba2b 100644 --- a/src/routes/actor.rs +++ b/src/routes/actor.rs @@ -15,7 +15,7 @@ use activitystreams_ext::Ext1; use actix_web::{web, Responder}; use rsa::pkcs8::EncodePublicKey; -#[tracing::instrument(name = "Actor")] +#[tracing::instrument(name = "Actor", skip(config, state))] pub(crate) async fn route( state: web::Data, config: web::Data, diff --git a/src/routes/inbox.rs b/src/routes/inbox.rs index e75f8f5..b3f151e 100644 --- a/src/routes/inbox.rs +++ b/src/routes/inbox.rs @@ -17,7 +17,7 @@ use actix_web::{web, HttpResponse}; use http_signature_normalization_actix::prelude::{DigestVerified, SignatureVerified}; use tracing::error; -#[tracing::instrument(name = "Inbox")] +#[tracing::instrument(name = "Inbox", skip(config, state))] pub(crate) async fn route( state: web::Data, actors: web::Data, diff --git a/src/routes/index.rs b/src/routes/index.rs index 4064086..2154a3e 100644 --- a/src/routes/index.rs +++ b/src/routes/index.rs @@ -8,7 +8,7 @@ use rand::{seq::SliceRandom, thread_rng}; use std::io::BufWriter; use tracing::error; -#[tracing::instrument(name = "Index")] +#[tracing::instrument(name = "Index", skip(config, state))] pub(crate) async fn route( state: web::Data, config: web::Data, diff --git a/src/routes/nodeinfo.rs b/src/routes/nodeinfo.rs index 005f9d8..2619849 100644 --- a/src/routes/nodeinfo.rs +++ b/src/routes/nodeinfo.rs @@ -5,7 +5,7 @@ use crate::{ use actix_web::{web, Responder}; use actix_webfinger::Link; -#[tracing::instrument(name = "Well Known NodeInfo")] +#[tracing::instrument(name = "Well Known NodeInfo", skip(config))] pub(crate) async fn well_known(config: web::Data) -> impl Responder { web::Json(Links { links: vec![Link {