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(node): file-based observability configuration #1078

Merged
merged 33 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ccde386
feat: introduce metrics crate
karlem Jul 4, 2024
6facf63
feat: improve library with macros, add top down events
karlem Jul 5, 2024
1dcf517
feat: emit metrics
karlem Jul 8, 2024
d34590d
feat: add remaining top down events
karlem Jul 9, 2024
75e45e4
feat: remove unused code & fix build
karlem Jul 9, 2024
c2465bc
feat: address comments
karlem Jul 10, 2024
599bcc3
feat: use latency wrapper instead
karlem Jul 10, 2024
e80f3df
feat: add config filters
karlem Jul 11, 2024
79de523
feat: add config as a cmd flags
karlem Jul 12, 2024
2f40eef
feat: fix comments
karlem Jul 15, 2024
a97b16d
feat: add consensus traces
karlem Jul 12, 2024
f16f8c5
feat: add execution metrics
karlem Jul 12, 2024
a164472
feat: add proposals metrics & reason
karlem Jul 15, 2024
1f5a38a
feat: add mempool event
karlem Jul 16, 2024
da84485
feat: remove
karlem Jul 16, 2024
c1ded52
feat: address comments
karlem Jul 16, 2024
59f3ea7
feat: address comments
karlem Jul 16, 2024
13bb9c6
feat: fix clippy
karlem Jul 16, 2024
d3b22d6
minor cleanup.
raulk Jul 16, 2024
094e9b6
feat: fix typo
karlem Jul 16, 2024
27e7e36
feat: standartize mpool trace
karlem Jul 16, 2024
e6e79f3
feat: address comments
karlem Jul 18, 2024
01843f0
lint: clippy
karlem Jul 18, 2024
6f67fe1
feat: revert risky changes & small cleanup
karlem Jul 19, 2024
4295027
feat: use tracing config
karlem Jul 17, 2024
b77bc36
feat: add tracing to each command
karlem Jul 18, 2024
edb7dc2
feat: introduce cleanups
karlem Jul 19, 2024
4e7d1c6
feat: adress comments
karlem Jul 19, 2024
ad1bd14
feat: fix after rebase
karlem Jul 22, 2024
c544c46
fix: rebase && comments
karlem Jul 22, 2024
22a065a
fix: select proper default
karlem Jul 22, 2024
68b2dbc
feat: setup tracing in single place
karlem Jul 22, 2024
73a4f4d
fix: do no register tracing twice in eth
karlem Jul 22, 2024
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
4 changes: 4 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions fendermint/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ fendermint_vm_snapshot = { path = "../vm/snapshot" }
fendermint_vm_topdown = { path = "../vm/topdown" }



fvm = { workspace = true }
fvm_ipld_blockstore = { workspace = true }
fvm_ipld_car = { workspace = true }
Expand Down
16 changes: 16 additions & 0 deletions fendermint/app/config/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ host = "127.0.0.1"
# The default port where the Prometheus exporter makes the metrics available.
port = 9184

[tracing]

[tracing.console]
enabled = true

[tracing.file]
enabled = false

[snapshots]
# Enable the export and import of snapshots.
enabled = false
Expand Down Expand Up @@ -160,6 +168,14 @@ allowed_methods = []
# Suggested headers if allowing origins: "Accept", "Authorization", "Content-Type", "Origin"
allowed_headers = []

[eth.tracing]

[eth.tracing.console]
enabled = true

[eth.tracing.file]
enabled = false

# IPLD Resolver Configuration
[resolver]
# Time to wait between attempts to resolve a CID after an error.
Expand Down
115 changes: 0 additions & 115 deletions fendermint/app/options/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use clap::{Args, Parser, Subcommand};
use config::ConfigArgs;
use debug::DebugArgs;
use fvm_shared::address::Network;
use ipc_observability::traces::FileLayerConfig;
use lazy_static::lazy_static;
use tracing_subscriber::EnvFilter;

use self::{
eth::EthArgs, genesis::GenesisArgs, key::KeyArgs, materializer::MaterializerArgs, rpc::RpcArgs,
Expand All @@ -25,10 +23,8 @@ pub mod materializer;
pub mod rpc;
pub mod run;

mod log;
mod parse;

use log::{parse_log_level, parse_rotation_kind, LogLevel, RotationKind};
use parse::parse_network;

lazy_static! {
Expand Down Expand Up @@ -103,70 +99,10 @@ pub struct Options {
#[arg(long, env = "FM_CONFIG_DIR")]
config_dir: Option<PathBuf>,

// TODO Karel - move all FM_LOG_FILE* flags to a configuration file instead

// Enable logging to a file.
#[arg(long, env = "FM_LOG_FILE_ENABLED")]
pub log_file_enabled: Option<bool>,

/// Set a custom directory for ipc log files.
#[arg(long, env = "FM_LOG_FILE_DIR")]
pub log_dir: Option<PathBuf>,

#[arg(long, env = "FM_LOG_FILE_MAX_FILES")]
pub max_log_files: Option<usize>,

#[arg(
long,
default_value = "daily",
value_enum,
env = "FM_LOG_FILE_ROTATION",
help = "The kind of rotation to use for log files. Options: minutely, hourly, daily, never.",
value_parser = parse_rotation_kind,
)]
pub log_files_rotation: Option<RotationKind>,

#[arg(
long,
env = "FM_LOG_FILE_DOMAINS_FILTER",
help = "Filter log events by domains. Only events from the specified domains will be logged. Comma separated.",
value_delimiter = ','
)]
pub domains_filter: Option<Vec<String>>,

#[arg(
long,
env = "FM_LOG_FILE_EVENTS_FILTER",
help = "Filter log events by name. Only events with the specified names will be logged. Comma separated.",
value_delimiter = ','
)]
pub events_filter: Option<Vec<String>>,

/// Optionally override the default configuration.
#[arg(short, long, default_value = "dev")]
pub mode: String,

/// Set the logging level of the console.
#[arg(
short = 'l',
long,
default_value = "info",
value_enum,
env = "FM_LOG_LEVEL",
help = "Standard log levels, or a comma separated list of filters, e.g. 'debug,tower_abci=warn,libp2p::gossipsub=info'",
value_parser = parse_log_level,
)]
log_level: LogLevel,

/// Set the logging level of the log file. If missing, it defaults to the same level as the console.
#[arg(
long,
value_enum,
env = "FM_LOG_FILE_LEVEL",
value_parser = parse_log_level,
)]
log_file_level: Option<LogLevel>,

/// Global options repeated here for discoverability, so they show up in `--help` among the others.
#[command(flatten)]
pub global: GlobalArgs,
Expand All @@ -176,35 +112,6 @@ pub struct Options {
}

impl Options {
/// Tracing filter for the console.
///
/// Coalescing everything into a filter instead of either a level or a filter
/// because the `tracing_subscriber` setup methods like `with_filter` and `with_level`
/// produce different static types and it's not obvious how to use them as alternatives.
pub fn log_console_filter(&self) -> anyhow::Result<EnvFilter> {
self.log_level.to_filter()
}

/// Tracing filter for the log file.
pub fn log_file_filter(&self) -> anyhow::Result<EnvFilter> {
if let Some(ref level) = self.log_file_level {
level.to_filter()
} else {
self.log_console_filter()
}
}

pub fn log_file_config(&self) -> FileLayerConfig {
FileLayerConfig {
enabled: self.log_file_enabled.unwrap_or(false),
directory: self.log_dir.clone(),
max_log_files: self.max_log_files,
rotation: self.log_files_rotation.clone(),
domain_filter: self.domains_filter.clone(),
events_filter: self.events_filter.clone(),
}
}

/// Path to the configuration directories.
///
/// If not specified then returns the default under the home directory.
Expand Down Expand Up @@ -248,7 +155,6 @@ mod tests {
use crate::*;
use clap::Parser;
use fvm_shared::address::Network;
use tracing::level_filters::LevelFilter;

/// Set some env vars, run a fallible piece of code, then unset the variables otherwise they would affect the next test.
pub fn with_env_vars<F, T>(vars: &[(&str, &str)], f: F) -> T
Expand Down Expand Up @@ -318,27 +224,6 @@ mod tests {
assert!(e.to_string().contains("Usage:"), "unexpected help: {e}");
}

#[test]
fn parse_log_level() {
let parse_filter = |cmd: &str| {
let opts: Options = Options::parse_from(cmd.split_ascii_whitespace());
opts.log_console_filter().expect("filter should parse")
};

let assert_level = |cmd: &str, level: LevelFilter| {
let filter = parse_filter(cmd);
assert_eq!(filter.max_level_hint(), Some(level))
};

assert_level("fendermint --log-level debug run", LevelFilter::DEBUG);
assert_level("fendermint --log-level off run", LevelFilter::OFF);
assert_level(
"fendermint --log-level libp2p=warn,error run",
LevelFilter::WARN,
);
assert_level("fendermint --log-level info run", LevelFilter::INFO);
}

#[test]
fn parse_invalid_log_level() {
// NOTE: `nonsense` in itself is interpreted as a target. Maybe we should mandate at least `=` in it?
Expand Down
93 changes: 0 additions & 93 deletions fendermint/app/options/src/log.rs

This file was deleted.

1 change: 1 addition & 0 deletions fendermint/app/settings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ fvm_shared = { workspace = true }
fvm_ipld_encoding = { workspace = true }
ipc-api = { workspace = true }
ipc-provider = { workspace = true }
ipc-observability = { workspace = true }

fendermint_vm_encoding = { path = "../../vm/encoding" }
fendermint_vm_topdown = { path = "../../vm/topdown" }
3 changes: 3 additions & 0 deletions fendermint/app/settings/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use serde_with::{serde_as, DurationSeconds};
use std::time::Duration;
use tower_http::cors::{AllowHeaders, AllowMethods, AllowOrigin};

use ipc_observability::config::TracingSettings;

use crate::{IsHumanReadable, MetricsSettings, SocketAddress};

/// Ethereum API facade settings.
Expand All @@ -24,6 +26,7 @@ pub struct EthSettings {
pub max_nonce_gap: u64,
pub metrics: MetricsSettings,
pub cors: CorsOpt,
pub tracing: TracingSettings,
}

#[serde_as]
Expand Down
2 changes: 2 additions & 0 deletions fendermint/app/settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use fendermint_vm_topdown::BlockHeight;
use self::eth::EthSettings;
use self::fvm::FvmSettings;
use self::resolver::ResolverSettings;
use ipc_observability::config::TracingSettings;
use ipc_provider::config::deserialize::deserialize_eth_address_from_str;

pub mod eth;
Expand Down Expand Up @@ -286,6 +287,7 @@ pub struct Settings {
pub broadcast: BroadcastSettings,
pub ipc: IpcSettings,
pub testing: Option<TestingSettings>,
pub tracing: TracingSettings,
}

impl Settings {
Expand Down
7 changes: 6 additions & 1 deletion fendermint/app/src/cmd/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use fendermint_app_options::debug::{
DebugArgs, DebugCommands, DebugExportTopDownEventsArgs, DebugIpcCommands,
};
use fendermint_vm_topdown::proxy::IPCProviderProxy;
use ipc_observability::config::TracingSettings;
use ipc_observability::traces::set_global_tracing_subscriber;
use ipc_provider::{
config::subnet::{EVMSubnet, SubnetConfig},
IpcProvider,
Expand All @@ -23,9 +25,12 @@ cmd! {

cmd! {
DebugIpcCommands(self) {
let _trace_file_guard = set_global_tracing_subscriber(&TracingSettings::default());

match self {
DebugIpcCommands::ExportTopDownEvents(args) =>
DebugIpcCommands::ExportTopDownEvents(args) => {
export_topdown_events(args).await
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion fendermint/app/src/cmd/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::time::Duration;

use anyhow::Context;
use fendermint_eth_api::HybridClient;
use ipc_observability::traces::set_global_tracing_subscriber;
use tracing::info;

use crate::{
Expand All @@ -15,9 +16,10 @@ use crate::{

cmd! {
EthArgs(self, settings: EthSettings) {
let _trace_file_guard = set_global_tracing_subscriber(&settings.tracing);

match self.command.clone() {
EthCommands::Run { ws_url, http_url, connect_retry_delay } => {

let (client, driver) = HybridClient::new(http_url, ws_url, Duration::from_secs(connect_retry_delay)).context("failed to create HybridClient")?;

let driver_handle = tokio::spawn(async move { driver.run().await });
Expand Down
Loading
Loading