Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tracing #390

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 92 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,7 @@ tempfile = "3.3.0"
thiserror = "1.0"
tokio = { version = "1.37.0", features = ["full"] }
tokio-test = "0.4.4"
tracing = "0.1.37"
tracing-subscriber = "0.3.16"
url = "2.5.0"
validator = "0.12"
1 change: 1 addition & 0 deletions crates/gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ starknet-types-core.workspace = true
test_utils = { path = "../test_utils", version = "0.0"}
thiserror.workspace = true
tokio.workspace = true
tracing.workspace = true
validator.workspace = true

[dev-dependencies]
Expand Down
3 changes: 2 additions & 1 deletion crates/gateway/src/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use starknet_api::transaction::TransactionHash;
use starknet_mempool_infra::component_runner::{ComponentRunner, ComponentStartError};
use starknet_mempool_types::communication::SharedMempoolClient;
use starknet_mempool_types::mempool_types::{Account, MempoolInput};
use tracing::info;

use crate::compilation::compile_contract_class;
use crate::config::{GatewayConfig, GatewayNetworkConfig, RpcStateReaderConfig};
Expand Down Expand Up @@ -146,7 +147,7 @@ pub fn create_gateway(
#[async_trait]
impl ComponentRunner for Gateway {
async fn start(&mut self) -> Result<(), ComponentStartError> {
println!("Gateway::start()");
info!("Gateway::start()");
self.run().await.map_err(|_| ComponentStartError::InternalComponentError)
}
}
1 change: 1 addition & 0 deletions crates/mempool_infra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ hyper.workspace = true
papyrus_config.workspace = true
thiserror.workspace = true
tokio.workspace = true
tracing.workspace = true

[dev-dependencies]
assert_matches.workspace = true
Expand Down
5 changes: 3 additions & 2 deletions crates/mempool_infra/src/component_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use hyper::{Body, Request as HyperRequest, Response as HyperResponse, Server, St
use serde::{Deserialize, Serialize};
use tokio::sync::mpsc::Receiver;
use tokio::sync::Mutex;
use tracing::{error, info};

use crate::component_definitions::{
ComponentRequestAndResponseSender, ComponentRequestHandler, ServerError,
Expand Down Expand Up @@ -152,8 +153,8 @@ impl<T: ComponentRunner + Send + Sync> EmptyServer<T> {
impl<T: ComponentRunner + Send + Sync> ComponentServerStarter for EmptyServer<T> {
async fn start(&mut self) {
match self.component.start().await {
Ok(_) => println!("ComponentServer::start() completed."),
Err(err) => println!("ComponentServer::start() failed: {:?}", err),
Ok(_) => info!("ComponentServer::start() completed."),
Err(err) => error!("ComponentServer::start() failed: {:?}", err),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/mempool_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ starknet_mempool_types = { path = "../mempool_types", version = "0.0" }
serde.workspace = true
papyrus_config.workspace = true
tokio.workspace = true
tracing.workspace = true
tracing-subscriber = { workspace = true, features = ["env-filter"] }
validator.workspace = true

[dev-dependencies]
Expand Down
22 changes: 20 additions & 2 deletions crates/mempool_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,35 @@ use starknet_mempool_node::communication::{create_node_channels, create_node_cli
use starknet_mempool_node::components::create_components;
use starknet_mempool_node::config::MempoolNodeConfig;
use starknet_mempool_node::servers::{create_servers, run_server_components};
use tracing::metadata::LevelFilter;
use tracing::{error, info};
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter};

const DEFAULT_LEVEL: LevelFilter = LevelFilter::INFO;

fn configure_tracing() {
let fmt_layer = fmt::layer().compact().with_target(false);
let level_filter_layer =
EnvFilter::builder().with_default_directive(DEFAULT_LEVEL.into()).from_env_lossy();

// This sets a single subscriber to all of the threads. We may want to implement different
// subscriber for some threads and use set_global_default instead of init.
tracing_subscriber::registry().with(fmt_layer).with(level_filter_layer).init();
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
configure_tracing();

let config = MempoolNodeConfig::load_and_process(args().collect());
if let Err(ConfigError::CommandInput(clap_err)) = config {
clap_err.exit();
}

let config = config?;
if let Err(error) = config_validate(&config) {
println!("Error: {}", error);
error!("{}", error);
exit(1);
}

Expand All @@ -26,7 +44,7 @@ async fn main() -> anyhow::Result<()> {
let components = create_components(&config, &clients);
let servers = create_servers(&config, channels, components);

println!("Info: Starting components!");
info!("Starting components!");
run_server_components(&config, servers).await?;

Ok(())
Expand Down
7 changes: 4 additions & 3 deletions crates/mempool_node/src/servers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use futures::{Future, FutureExt};
use starknet_gateway::communication::{create_gateway_server, GatewayServer};
use starknet_mempool::communication::{create_mempool_server, MempoolServer};
use starknet_mempool_infra::component_server::ComponentServerStarter;
use tracing::error;

use crate::communication::MempoolNodeCommunication;
use crate::components::Components;
Expand Down Expand Up @@ -57,15 +58,15 @@ pub async fn run_server_components(

tokio::select! {
res = gateway_handle => {
println!("Error: Gateway Server stopped.");
error!("Gateway Server stopped.");
res?
}
res = mempool_handle => {
println!("Error: Mempool Server stopped.");
error!("Mempool Server stopped.");
res?
}
};
println!("Error: Servers ended with unexpected Ok.");
error!("Servers ended with unexpected Ok.");

Ok(())
}
Expand Down
Loading