Skip to content

Commit

Permalink
update logging
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc committed May 14, 2024
1 parent a4b6927 commit f0135e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/extensions/client/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ impl Endpoint {
connection_timeout: Duration,
health_config: Option<HealthCheckConfig>,
) -> Self {
tracing::info!("New endpoint: {url}");

let health = Arc::new(Health::new(url.clone()));
let connect_counter = Arc::new(AtomicU32::new(0));
let (message_tx, message_rx) = tokio::sync::mpsc::channel::<Message>(4096);
Expand Down Expand Up @@ -296,6 +298,7 @@ impl Endpoint {
fn start_health_monitor_task(&mut self, config: HealthCheckConfig) {
let message_tx = self.message_tx.clone();
let health = self.health.clone();
let url = self.url.clone();

let handler = tokio::spawn(async move {
let health_response = config.response.clone();
Expand All @@ -320,13 +323,13 @@ impl Endpoint {
.await;

if let Err(err) = res {
tracing::error!("Unexpected error in message channel: {err}");
tracing::error!("{url} Unexpected error in message channel: {err}");
}

let res = match response_rx.await {
Ok(resp) => resp,
Err(err) => {
tracing::error!("Unexpected error in response channel: {err}");
tracing::error!("{url} Unexpected error in response channel: {err}");
Err(jsonrpsee::core::Error::Custom("Internal server error".into()))
}
};
Expand All @@ -345,6 +348,7 @@ impl Endpoint {

// Check response time
if duration > healthy_response_time {
tracing::warn!("{url} response time is too long: {duration:?}");
health.update(Event::SlowResponse);
continue;
}
Expand Down
8 changes: 4 additions & 4 deletions src/extensions/client/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ impl Health {
}
self.score.store(new_score, Ordering::Relaxed);
tracing::trace!(
"Endpoint {:?} score updated from: {current_score} to: {new_score} because {event:?}",
"{:?} score updated from: {current_score} to: {new_score} because {event:?}",
self.url
);

// Notify waiters if the score has dropped below the threshold
if current_score >= THRESHOLD && new_score < THRESHOLD {
tracing::warn!("Endpoint {:?} became unhealthy", self.url);
tracing::warn!("{:?} became unhealthy", self.url);
self.unhealthy.notify_waiters();
}
}
Expand All @@ -75,11 +75,11 @@ impl Health {
// NOT SERVER ERROR
}
jsonrpsee::core::Error::RequestTimeout => {
tracing::warn!("Endpoint {:?} request timeout", self.url);
tracing::warn!("{:?} request timeout", self.url);
self.update(Event::RequestTimeout);
}
_ => {
tracing::warn!("Endpoint {:?} responded with error: {err:?}", self.url);
tracing::warn!("{:?} responded with error: {err:?}", self.url);
self.update(Event::ServerError);
}
};
Expand Down

0 comments on commit f0135e2

Please sign in to comment.