From 2a2911c6a793a5e7379007af7b9564d36baf719a Mon Sep 17 00:00:00 2001 From: John Watson Date: Thu, 15 Aug 2024 22:18:54 +0100 Subject: [PATCH 1/2] feat: free up USR2 for other things --- lib/telemetry-application-rs/src/lib.rs | 16 +------- lib/telemetry-rs/src/lib.rs | 49 ++++++++----------------- 2 files changed, 18 insertions(+), 47 deletions(-) diff --git a/lib/telemetry-application-rs/src/lib.rs b/lib/telemetry-application-rs/src/lib.rs index 5fc097628b..721b4f90fc 100644 --- a/lib/telemetry-application-rs/src/lib.rs +++ b/lib/telemetry-application-rs/src/lib.rs @@ -548,7 +548,6 @@ struct TelemetrySignalHandlerTask { client: ApplicationTelemetryClient, shutdown_token: CancellationToken, sig_usr1: unix::Signal, - sig_usr2: unix::Signal, } impl TelemetrySignalHandlerTask { @@ -559,13 +558,11 @@ impl TelemetrySignalHandlerTask { shutdown_token: CancellationToken, ) -> io::Result { let sig_usr1 = unix::signal(SignalKind::user_defined1())?; - let sig_usr2 = unix::signal(SignalKind::user_defined2())?; Ok(Self { client, shutdown_token, sig_usr1, - sig_usr2, }) } @@ -577,20 +574,11 @@ impl TelemetrySignalHandlerTask { break; } Some(_) = self.sig_usr1.recv() => { - if let Err(err) = self.client.increase_verbosity().await { + if let Err(err) = self.client.modify_verbosity().await { warn!( task = Self::NAME, error = ?err, - "error while trying to increase verbosity", - ); - } - } - Some(_) = self.sig_usr2.recv() => { - if let Err(err) = self.client.decrease_verbosity().await { - warn!( - task = Self::NAME, - error = ?err, - "error while trying to decrease verbosity", + "error while trying to modify verbosity", ); } } diff --git a/lib/telemetry-rs/src/lib.rs b/lib/telemetry-rs/src/lib.rs index 30f4f5591e..209da21b48 100644 --- a/lib/telemetry-rs/src/lib.rs +++ b/lib/telemetry-rs/src/lib.rs @@ -161,8 +161,7 @@ impl SpanExt for tracing::Span { #[async_trait] pub trait TelemetryClient: Clone + Send + Sync + 'static { async fn set_verbosity(&mut self, updated: Verbosity) -> Result<(), ClientError>; - async fn increase_verbosity(&mut self) -> Result<(), ClientError>; - async fn decrease_verbosity(&mut self) -> Result<(), ClientError>; + async fn modify_verbosity(&mut self) -> Result<(), ClientError>; async fn set_custom_tracing( &mut self, directives: impl Into + Send + 'async_trait, @@ -214,10 +213,10 @@ impl ApplicationTelemetryClient { Ok(()) } - pub async fn increase_verbosity_and_wait(&mut self) -> Result<(), ClientError> { + pub async fn modify_verbosity_and_wait(&mut self) -> Result<(), ClientError> { let (tx, rx) = oneshot::channel(); - self.increase_verbosity_inner(Some(tx)).await?; + self.modify_verbosity_inner(Some(tx)).await?; if let Err(err) = rx.await { warn!( @@ -229,21 +228,6 @@ impl ApplicationTelemetryClient { Ok(()) } - pub async fn decrease_verbosity_and_wait(&mut self) -> Result<(), ClientError> { - let (tx, rx) = oneshot::channel(); - - self.decrease_verbosity_inner(Some(tx)).await?; - - if let Err(err) = rx.await { - warn!( - error = ?err, - "sender already closed while waiting on verbosity decrease change", - ); - } - - Ok(()) - } - pub async fn set_custom_tracing_and_wait( &mut self, directives: impl Into + Send, @@ -292,15 +276,18 @@ impl ApplicationTelemetryClient { Ok(()) } - async fn increase_verbosity_inner( + async fn modify_verbosity_inner( &mut self, wait: Option>, ) -> Result<(), ClientError> { let guard = self.tracing_level.lock().await; - match guard.deref() { TracingLevel::Verbosity { verbosity, .. } => { - let updated = verbosity.increase(); + let updated = match verbosity.is_max() { + true => Verbosity::InfoAll, + false => verbosity.increase(), + _ => Verbosity::InfoAll, + }; drop(guard); self.set_verbosity_inner(updated, wait).await } @@ -349,12 +336,8 @@ impl TelemetryClient for ApplicationTelemetryClient { self.set_verbosity_inner(updated, None).await } - async fn increase_verbosity(&mut self) -> Result<(), ClientError> { - self.increase_verbosity_inner(None).await - } - - async fn decrease_verbosity(&mut self) -> Result<(), ClientError> { - self.decrease_verbosity_inner(None).await + async fn modify_verbosity(&mut self) -> Result<(), ClientError> { + self.modify_verbosity_inner(None).await } async fn set_custom_tracing( @@ -385,11 +368,7 @@ impl TelemetryClient for NoopClient { Ok(()) } - async fn increase_verbosity(&mut self) -> Result<(), ClientError> { - Ok(()) - } - - async fn decrease_verbosity(&mut self) -> Result<(), ClientError> { + async fn modify_verbosity(&mut self) -> Result<(), ClientError> { Ok(()) } @@ -495,6 +474,10 @@ impl Verbosity { !matches!(self, Self::InfoAll) } + fn is_max(&self) -> bool { + matches!(self, Self::TraceAll) + } + #[inline] fn as_u8(self) -> u8 { self.into() From af733c8a6f0c1d5ac61461d56a2708e21c8e7239 Mon Sep 17 00:00:00 2001 From: John Watson Date: Thu, 15 Aug 2024 23:13:56 +0100 Subject: [PATCH 2/2] chore: remove dead code for decreasing verbosity --- lib/telemetry-rs/src/lib.rs | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/lib/telemetry-rs/src/lib.rs b/lib/telemetry-rs/src/lib.rs index 209da21b48..5b19dfd832 100644 --- a/lib/telemetry-rs/src/lib.rs +++ b/lib/telemetry-rs/src/lib.rs @@ -286,7 +286,6 @@ impl ApplicationTelemetryClient { let updated = match verbosity.is_max() { true => Verbosity::InfoAll, false => verbosity.increase(), - _ => Verbosity::InfoAll, }; drop(guard); self.set_verbosity_inner(updated, wait).await @@ -295,22 +294,6 @@ impl ApplicationTelemetryClient { } } - async fn decrease_verbosity_inner( - &mut self, - wait: Option>, - ) -> Result<(), ClientError> { - let guard = self.tracing_level.lock().await; - - match guard.deref() { - TracingLevel::Verbosity { verbosity, .. } => { - let updated = verbosity.decrease(); - drop(guard); - self.set_verbosity_inner(updated, wait).await - } - TracingLevel::Custom(_) => Err(ClientError::CustomHasNoVerbosity), - } - } - async fn set_custom_tracing_inner( &mut self, directives: impl Into + Send,