Skip to content

Commit

Permalink
chore(mempool_infra): add tracing
Browse files Browse the repository at this point in the history
commit-id:fafff049
  • Loading branch information
Itay-Tsabary-Starkware committed Oct 6, 2024
1 parent b912ed4 commit 074cf6d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::any::type_name;

use tokio::sync::mpsc::{channel, Sender};
use tracing::info;

use crate::component_definitions::ComponentRequestAndResponseSender;

Expand Down Expand Up @@ -78,6 +81,16 @@ where
}
}

impl<Request, Response> Drop for LocalComponentClient<Request, Response>
where
Request: Send + Sync,
Response: Send + Sync,
{
fn drop(&mut self) {
info!("Dropping LocalComponentClient {}.", type_name::<Self>());
}
}

// Can't derive because derive forces the generics to also be `Clone`, which we prefer not to do
// since it'll require transactions to be cloneable.
impl<Request, Response> Clone for LocalComponentClient<Request, Response>
Expand Down
2 changes: 1 addition & 1 deletion crates/mempool_infra/src/component_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub trait ComponentRequestHandler<Request, Response> {
#[async_trait]
pub trait ComponentStarter {
async fn start(&mut self) -> Result<(), ComponentError> {
info!("Starting component {}.", type_name::<Self>());
info!("Starting component {} with the default starter.", type_name::<Self>());
Ok(())
}
}
Expand Down
4 changes: 4 additions & 0 deletions crates/mempool_infra/src/component_server/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub async fn request_response_loop<Request, Response, Component>(
Request: Send + Sync,
Response: Send + Sync,
{
info!("Starting server loop for component {}", type_name::<Component>());

// TODO(Tsabary): Make requests and responses implement `std::fmt::Display`, and add the request
// to the log.
// TODO(Tsabary): Move this function to be part of the `local_server` module.
Expand All @@ -34,6 +36,8 @@ pub async fn request_response_loop<Request, Response, Component>(

tx.send(res).await.expect("Response connection should be open.");
}

info!("Finished server loop for component {}", type_name::<Component>());
}

// TODO(Tsabary): Create an error module and move this error there.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ impl<Component: ComponentStarter + Send + Sync> ComponentServerStarter
for WrapperServer<Component>
{
async fn start(&mut self) -> Result<(), ComponentServerError> {
info!("Starting empty component server for {}.", type_name::<Component>());
self.component.start().await.map_err(ComponentServerError::ComponentError)
info!("Starting WrapperServer for {}.", type_name::<Component>());
let res = self.component.start().await.map_err(ComponentServerError::ComponentError);
info!("Finished running WrapperServer for {}.", type_name::<Component>());
res
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::any::type_name;
use std::marker::PhantomData;

use async_trait::async_trait;
use tokio::sync::mpsc::Receiver;
use tracing::error;
use tracing::{error, info};

use super::definitions::request_response_loop;
use crate::component_definitions::{
Expand Down Expand Up @@ -123,8 +124,10 @@ where
Response: Send + Sync,
{
async fn start(&mut self) -> Result<(), ComponentServerError> {
info!("Starting LocalComponentServer for {}.", type_name::<Component>());
self.component.start().await?;
request_response_loop(&mut self.rx, &mut self.component).await;
info!("Finished LocalComponentServer for {}.", type_name::<Component>());
Ok(())
}
}
Expand Down

0 comments on commit 074cf6d

Please sign in to comment.