Skip to content

Commit

Permalink
feat: standardize logs
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoura committed Aug 24, 2023
1 parent 7fee56a commit 52506aa
Show file tree
Hide file tree
Showing 35 changed files with 322 additions and 98 deletions.
33 changes: 31 additions & 2 deletions offchain/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 offchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ members = [
"http-server",
"indexer",
"inspect-server",
"logs",
"redacted",
"rollups-events",
"rollups-http-client",
Expand Down Expand Up @@ -83,6 +84,7 @@ tonic = "0.9"
tonic-build = "0.9"
tonic-health = "0.9"
tracing = "0.1"
tracing-actix-web = "0.7"
tracing-subscriber = "0.3"
tracing-test = "0.2"
url = "2"
Expand Down
1 change: 1 addition & 0 deletions offchain/advance-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ path = "src/main.rs"
grpc-interfaces = { path = "../grpc-interfaces" }
http-health-check = { path = "../http-health-check" }
rollups-events = { path = "../rollups-events" }
logs = {path = "../logs"}

async-trait.workspace = true
backoff = { workspace = true, features = ["tokio"] }
Expand Down
9 changes: 9 additions & 0 deletions offchain/advance-runner/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::server_manager::ServerManagerCLIConfig;
pub use crate::server_manager::ServerManagerConfig;
pub use crate::snapshot::config::{FSManagerConfig, SnapshotConfig};
use crate::snapshot::config::{SnapshotCLIConfig, SnapshotConfigError};
use logs::{LogsConfig, LogsEnvCliConfig};
pub use rollups_events::{
BrokerCLIConfig, BrokerConfig, DAppMetadata, DAppMetadataCLIConfig,
};
Expand All @@ -19,6 +20,7 @@ pub struct AdvanceRunnerConfig {
pub broker_config: BrokerConfig,
pub dapp_metadata: DAppMetadata,
pub snapshot_config: SnapshotConfig,
pub logs_config: LogsConfig,
pub backoff_max_elapsed_duration: Duration,
pub healthcheck_port: u16,
}
Expand All @@ -36,11 +38,15 @@ impl AdvanceRunnerConfig {
let backoff_max_elapsed_duration =
Duration::from_millis(cli_config.backoff_max_elapsed_duration);
let healthcheck_port = cli_config.healthcheck_port;

let logs_config = LogsConfig::initialize(cli_config.logs_config);

Ok(Self {
server_manager_config,
broker_config,
dapp_metadata,
snapshot_config,
logs_config,
backoff_max_elapsed_duration,
healthcheck_port,
})
Expand All @@ -67,6 +73,9 @@ struct CLIConfig {
#[command(flatten)]
snapshot_cli_config: SnapshotCLIConfig,

#[command(flatten)]
pub logs_config: LogsEnvCliConfig,

/// The max elapsed time for backoff in ms
#[arg(long, env, default_value = "120000")]
backoff_max_elapsed_duration: u64,
Expand Down
10 changes: 4 additions & 6 deletions offchain/advance-runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

use advance_runner::config::AdvanceRunnerConfig;
use tracing_subscriber::filter::{EnvFilter, LevelFilter};
use tracing::info;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let filter = EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy();
tracing_subscriber::fmt().with_env_filter(filter).init();

let config = AdvanceRunnerConfig::parse()?;

logs::initialize_logs(&config.logs_config);

info!("Starting Advance Runner");
advance_runner::run(config).await.map_err(|e| e.into())
}
7 changes: 7 additions & 0 deletions offchain/advance-runner/tests/fixtures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use grpc_interfaces::cartesi_machine::{
ConcurrencyConfig, MachineRuntimeConfig,
};
use grpc_interfaces::cartesi_server_manager::{CyclesConfig, DeadlineConfig};
use logs::LogsConfig;
use rollups_events::{Address, BrokerEndpoint};
use std::cell::RefCell;
use std::path::Path;
Expand Down Expand Up @@ -90,13 +91,19 @@ impl AdvanceRunnerFixture {

let backoff_max_elapsed_duration = Duration::from_millis(1);

let logs_config = LogsConfig {
enable_color: false,
enable_timestamp: false,
};

let config = AdvanceRunnerConfig {
server_manager_config,
broker_config,
dapp_metadata,
snapshot_config,
backoff_max_elapsed_duration,
healthcheck_port: 0,
logs_config,
};
let handler = RefCell::new(Some(start_advance_runner(config.clone())));
Self { config, handler }
Expand Down
3 changes: 2 additions & 1 deletion offchain/authority-claimer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ test = false
[dependencies]
http-server = { path = "../http-server" }
rollups-events = { path = "../rollups-events" }
logs = { path = "../logs" }

async-trait.workspace = true
clap = { workspace = true, features = ["derive"] }
clap = { workspace = true, features = ["derive", "env"] }
eth-tx-manager.workspace = true
ethers.workspace = true
rusoto_core.workspace = true
Expand Down
7 changes: 7 additions & 0 deletions offchain/authority-claimer/src/config/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use eth_tx_manager::{
config::{TxEnvCLIConfig as TxManagerCLIConfig, TxManagerConfig},
Priority,
};
use logs::{LogsConfig, LogsEnvCliConfig};
use rollups_events::{BrokerCLIConfig, BrokerConfig};
use rusoto_core::Region;
use snafu::ResultExt;
Expand Down Expand Up @@ -37,6 +38,9 @@ pub(crate) struct AuthorityClaimerCLI {
#[command(flatten)]
broker_config: BrokerCLIConfig,

#[command(flatten)]
pub logs_config: LogsEnvCliConfig,

/// Path to a file with the deployment json of the dapp
#[arg(long, env, default_value = "./dapp_deployment.json")]
dapp_deployment_file: PathBuf,
Expand All @@ -61,11 +65,14 @@ impl TryFrom<AuthorityClaimerCLI> for AuthorityClaimerConfig {
let dapp_address = dapp_deployment.dapp_address;
let dapp_deploy_block_hash = dapp_deployment.dapp_deploy_block_hash;

let logs_config = LogsConfig::initialize(cli_config.logs_config);

Ok(AuthorityClaimerConfig {
tx_manager_config,
tx_signing_config,
tx_manager_priority: Priority::Normal,
broker_config,
logs_config,
dapp_address,
dapp_deploy_block_hash,
})
Expand Down
2 changes: 2 additions & 0 deletions offchain/authority-claimer/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub use error::{AuthorityClaimerConfigError, TxSigningConfigError};
use cli::AuthorityClaimerCLI;
use eth_tx_manager::{config::TxManagerConfig, Priority};
use http_server::HttpServerConfig;
use logs::LogsConfig;
use rollups_events::{Address, BrokerConfig, Hash};
use rusoto_core::Region;

Expand All @@ -25,6 +26,7 @@ pub struct AuthorityClaimerConfig {
pub tx_signing_config: TxSigningConfig,
pub tx_manager_priority: Priority,
pub broker_config: BrokerConfig,
pub logs_config: LogsConfig,
pub dapp_address: Address,
pub dapp_deploy_block_hash: Hash,
}
Expand Down
13 changes: 6 additions & 7 deletions offchain/authority-claimer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@

use authority_claimer::config::Config;
use std::error::Error;
use tracing_subscriber::filter::{EnvFilter, LevelFilter};
use tracing::info;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// Getting the configuration.
let config: Config = Config::new().map_err(Box::new)?;

// Settin up the logging environment.
let env_filter = EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy();
tracing_subscriber::fmt().with_env_filter(env_filter).init();
logs::initialize_logs(&config.authority_claimer_config.logs_config);

// Getting the configuration.
let config = Config::new().map_err(Box::new)?;
info!("Starting Authority Claimer");

authority_claimer::run(config).await
}
1 change: 1 addition & 0 deletions offchain/dispatcher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ contracts = { path = "../contracts" }
http-server = { path = "../http-server" }
rollups-events = { path = "../rollups-events" }
types = { path = "../types" }
logs = {path = "../logs"}

async-trait.workspace = true
axum.workspace = true
Expand Down
8 changes: 8 additions & 0 deletions offchain/dispatcher/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use eth_tx_manager::{
Priority,
};
use http_server::HttpServerConfig;
use logs::{LogsConfig, LogsEnvCliConfig};
use snafu::{ResultExt, Snafu};
use std::{fs::File, io::BufReader, path::PathBuf};

Expand Down Expand Up @@ -37,6 +38,9 @@ pub struct DispatcherEnvCLIConfig {
#[command(flatten)]
pub auth_config: AuthEnvCLIConfig,

#[command(flatten)]
pub logs_config: LogsEnvCliConfig,

/// Path to file with deployment json of dapp
#[arg(long, env, default_value = "./dapp_deployment.json")]
pub rd_dapp_deployment_file: PathBuf,
Expand All @@ -56,6 +60,7 @@ pub struct DispatcherConfig {
pub tx_config: TxManagerConfig,
pub broker_config: BrokerConfig,
pub auth_config: AuthConfig,
pub logs_config: LogsConfig,

pub dapp_deployment: DappDeployment,
pub rollups_deployment: RollupsDeployment,
Expand Down Expand Up @@ -114,6 +119,8 @@ impl Config {
let auth_config = AuthConfig::initialize(dispatcher_config.auth_config)
.context(AuthSnafu)?;

let logs_config = LogsConfig::initialize(dispatcher_config.logs_config);

let path = dispatcher_config.rd_dapp_deployment_file;
let dapp_deployment: DappDeployment = read_json(path)?;

Expand All @@ -133,6 +140,7 @@ impl Config {
tx_config,
broker_config,
auth_config,
logs_config,

dapp_deployment,
rollups_deployment,
Expand Down
12 changes: 6 additions & 6 deletions offchain/dispatcher/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

use tracing_subscriber::filter::{EnvFilter, LevelFilter};
use logs;
use tracing::info;

// NOTE: doesn't support History upgradability.
// NOTE: doesn't support changing epoch_duration in the middle of things.
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let filter = EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy();
tracing_subscriber::fmt().with_env_filter(filter).init();

let config = dispatcher::config::Config::initialize()?;

logs::initialize_logs(&config.dispatcher_config.logs_config);

info!("Starting Dispatcher");
dispatcher::run(config).await.map_err(|e| e.into())
}
Loading

0 comments on commit 52506aa

Please sign in to comment.