fix tracing configuration issues (#432)

This commit is contained in:
Jane Lusby 2020-06-04 19:34:06 -07:00 committed by GitHub
parent eef76c7c84
commit 18b4dbc16c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 101 additions and 71 deletions

74
Cargo.lock generated
View File

@ -3,36 +3,34 @@
[[package]] [[package]]
name = "abscissa_core" name = "abscissa_core"
version = "0.5.2" version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/yaahc/abscissa.git?branch=develop#41d342a9344e38442b2211b07f28a89505892a21"
checksum = "6a07677093120a02583717b6dd1ef81d8de1e8d01bd226c83f0f9bdf3e56bb3a"
dependencies = [ dependencies = [
"abscissa_derive", "abscissa_derive",
"backtrace", "backtrace",
"canonical-path", "canonical-path",
"chrono", "chrono",
"color-backtrace 0.3.0", "color-backtrace",
"generational-arena", "generational-arena",
"gumdrop", "gumdrop",
"libc", "libc",
"once_cell", "once_cell",
"regex", "regex",
"secrecy", "secrecy",
"semver", "semver 0.10.0",
"serde", "serde",
"signal-hook", "signal-hook",
"termcolor", "termcolor",
"toml", "toml",
"tracing", "tracing",
"tracing-log", "tracing-log",
"tracing-subscriber 0.1.6", "tracing-subscriber",
"wait-timeout", "wait-timeout",
] ]
[[package]] [[package]]
name = "abscissa_derive" name = "abscissa_derive"
version = "0.5.0" version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/yaahc/abscissa.git?branch=develop#41d342a9344e38442b2211b07f28a89505892a21"
checksum = "74f5722bc48763cb9d81d8427ca05b6aa2842f6632cf8e4c0a29eef9baececcc"
dependencies = [ dependencies = [
"darling", "darling",
"ident_case", "ident_case",
@ -268,17 +266,6 @@ dependencies = [
"bitflags", "bitflags",
] ]
[[package]]
name = "color-backtrace"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65d13f1078cc63c791d0deba0dd43db37c9ec02b311f10bed10b577016f3a957"
dependencies = [
"atty",
"backtrace",
"termcolor",
]
[[package]] [[package]]
name = "color-backtrace" name = "color-backtrace"
version = "0.4.2" version = "0.4.2"
@ -298,7 +285,7 @@ checksum = "2aaa5f071a62a9c06ebab653ec2e2ba76cb936548a83e7af7f0c5dac525067ff"
dependencies = [ dependencies = [
"ansi_term", "ansi_term",
"backtrace", "backtrace",
"color-backtrace 0.4.2", "color-backtrace",
"color-spantrace", "color-spantrace",
"eyre", "eyre",
"indenter", "indenter",
@ -1081,15 +1068,6 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
[[package]]
name = "owning_ref"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ff55baddef9e4ad00f88b6c743a2a8062d4c6ade126c2a528644b8e444d52ce"
dependencies = [
"stable_deref_trait",
]
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
version = "0.9.0" version = "0.9.0"
@ -1378,7 +1356,7 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
dependencies = [ dependencies = [
"semver", "semver 0.9.0",
] ]
[[package]] [[package]]
@ -1439,6 +1417,15 @@ name = "semver"
version = "0.9.0" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
dependencies = [
"semver-parser",
]
[[package]]
name = "semver"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "394cec28fa623e00903caf7ba4fa6fb9a0e260280bb8cdbbba029611108a0190"
dependencies = [ dependencies = [
"semver-parser", "semver-parser",
"serde", "serde",
@ -1589,12 +1576,6 @@ dependencies = [
"tracing-futures", "tracing-futures",
] ]
[[package]]
name = "stable_deref_trait"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
[[package]] [[package]]
name = "strsim" name = "strsim"
version = "0.9.3" version = "0.9.3"
@ -1932,7 +1913,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4d7c0b83d4a500748fa5879461652b361edf5c9d51ede2a2ac03875ca185e24" checksum = "b4d7c0b83d4a500748fa5879461652b361edf5c9d51ede2a2ac03875ca185e24"
dependencies = [ dependencies = [
"tracing", "tracing",
"tracing-subscriber 0.2.5", "tracing-subscriber",
] ]
[[package]] [[package]]
@ -1966,23 +1947,6 @@ dependencies = [
"tracing-core", "tracing-core",
] ]
[[package]]
name = "tracing-subscriber"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "192ca16595cdd0661ce319e8eede9c975f227cdaabc4faaefdc256f43d852e45"
dependencies = [
"ansi_term",
"chrono",
"lazy_static",
"matchers",
"owning_ref",
"regex",
"smallvec 0.6.13",
"tracing-core",
"tracing-log",
]
[[package]] [[package]]
name = "tracing-subscriber" name = "tracing-subscriber"
version = "0.2.5" version = "0.2.5"
@ -2211,7 +2175,7 @@ dependencies = [
"tracing", "tracing",
"tracing-error", "tracing-error",
"tracing-futures", "tracing-futures",
"tracing-subscriber 0.2.5", "tracing-subscriber",
"zebra-chain", "zebra-chain",
"zebra-test-vectors", "zebra-test-vectors",
] ]
@ -2245,8 +2209,10 @@ dependencies = [
"toml", "toml",
"tower", "tower",
"tracing", "tracing",
"tracing-error",
"tracing-futures", "tracing-futures",
"tracing-log", "tracing-log",
"tracing-subscriber",
"zebra-chain", "zebra-chain",
"zebra-network", "zebra-network",
"zebra-state", "zebra-state",

View File

@ -15,4 +15,7 @@ members = [
panic = "abort" panic = "abort"
[profile.release] [profile.release]
panic = "abort" panic = "abort"
[patch.crates-io]
abscissa_core = { git = "https://github.com/yaahc/abscissa.git", branch = "develop" }

View File

@ -33,6 +33,8 @@ zebra-network = { path = "../zebra-network" }
eyre = "0.4.3" eyre = "0.4.3"
color-eyre = "0.3.4" color-eyre = "0.3.4"
zebra-state = { path = "../zebra-state" } zebra-state = { path = "../zebra-state" }
tracing-subscriber = { version = "0.2.5", features = ["tracing-log"] }
tracing-error = "0.1.2"
[dev-dependencies] [dev-dependencies]
abscissa_core = { version = "0.5", features = ["testing"] } abscissa_core = { version = "0.5", features = ["testing"] }

View File

@ -3,7 +3,10 @@
use crate::{commands::ZebradCmd, config::ZebradConfig}; use crate::{commands::ZebradCmd, config::ZebradConfig};
use abscissa_core::{ use abscissa_core::{
application::{self, AppCell}, application::{self, AppCell},
config, trace, Application, EntryPoint, FrameworkError, StandardPaths, config,
terminal::component::Terminal,
trace::Tracing,
Application, Component, EntryPoint, FrameworkError, StandardPaths,
}; };
/// Application state /// Application state
@ -76,6 +79,16 @@ impl Application for ZebradApp {
&mut self.state &mut self.state
} }
fn framework_components(
&mut self,
command: &Self::Cmd,
) -> Result<Vec<Box<dyn Component<Self>>>, FrameworkError> {
let terminal = Terminal::new(self.term_colors(command));
let tracing = self.tracing_component(command);
Ok(vec![Box::new(terminal), Box::new(tracing)])
}
/// Register all components used by this application. /// Register all components used by this application.
/// ///
/// If you would like to add additional components to your application /// If you would like to add additional components to your application
@ -99,21 +112,60 @@ impl Application for ZebradApp {
/// Called regardless of whether config is loaded to indicate this is the /// Called regardless of whether config is loaded to indicate this is the
/// time in app lifecycle when configuration would be loaded if /// time in app lifecycle when configuration would be loaded if
/// possible. /// possible.
fn after_config(&mut self, config: Self::Cfg) -> Result<(), FrameworkError> { fn after_config(
&mut self,
config: Self::Cfg,
command: &Self::Cmd,
) -> Result<(), FrameworkError> {
// Configure components // Configure components
self.state.components.after_config(&config)?; self.state.components.after_config(&config)?;
self.config = Some(config); self.config = Some(config);
let level = self.level(command);
self.state
.components
.get_downcast_mut::<Tracing>()
.expect("Tracing component should be available")
.reload_filter(level);
Ok(()) Ok(())
} }
}
/// Get logging configuration from command-line options impl ZebradApp {
fn tracing_config(&self, command: &EntryPoint<ZebradCmd>) -> trace::Config { fn level(&self, command: &EntryPoint<ZebradCmd>) -> String {
if let Ok(env) = std::env::var("ZEBRAD_LOG") { if let Ok(level) = std::env::var("ZEBRAD_LOG") {
trace::Config::from(env) level
} else if command.verbose { } else if command.verbose {
trace::Config::verbose() "debug".to_string()
} else if let Some(ZebradConfig {
tracing:
crate::config::TracingSection {
filter: Some(filter),
},
..
}) = &self.config
{
filter.clone()
} else { } else {
trace::Config::default() "info".to_string()
} }
} }
fn tracing_component(&self, command: &EntryPoint<ZebradCmd>) -> Tracing {
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
// Construct a tracing subscriber with the supplied filter and enable reloading.
let builder = tracing_subscriber::FmtSubscriber::builder()
.with_env_filter(self.level(command))
.with_filter_reloading();
let filter_handle = builder.reload_handle();
builder
.finish()
.with(tracing_error::ErrorLayer::default())
.init();
filter_handle.into()
}
} }

View File

@ -14,7 +14,11 @@ pub struct ConfigCmd {
impl Runnable for ConfigCmd { impl Runnable for ConfigCmd {
/// Start the application. /// Start the application.
fn run(&self) { fn run(&self) {
let default_config = ZebradConfig::default(); let default_config = ZebradConfig {
tracing: crate::config::TracingSection::populated(),
network: Default::default(),
metrics: Default::default(),
};
let mut output = r"# Default configuration values for zebrad. let mut output = r"# Default configuration values for zebrad.
# #
# This file is intended as a skeleton for custom configs. # This file is intended as a skeleton for custom configs.

View File

@ -29,7 +29,9 @@ impl Runnable for StartCmd {
fn run(&self) { fn run(&self) {
warn!("starting application"); warn!("starting application");
let config = app_config(); let config = app_config();
println!("filter: {}!", &config.tracing.filter); if let Some(filter) = &config.tracing.filter {
println!("filter: {}!", filter);
}
let default_config = ZebradConfig::default(); let default_config = ZebradConfig::default();
println!("Default config: {:?}", default_config); println!("Default config: {:?}", default_config);
@ -59,7 +61,7 @@ impl config::Override<ZebradConfig> for StartCmd {
// arguments. // arguments.
fn override_config(&self, mut config: ZebradConfig) -> Result<ZebradConfig, FrameworkError> { fn override_config(&self, mut config: ZebradConfig) -> Result<ZebradConfig, FrameworkError> {
if !self.filters.is_empty() { if !self.filters.is_empty() {
config.tracing.filter = self.filters.join(","); config.tracing.filter = Some(self.filters.join(","));
} }
Ok(config) Ok(config)

View File

@ -13,6 +13,7 @@ use zebra_network::Config as NetworkSection;
/// Zebrad Configuration /// Zebrad Configuration
#[derive(Clone, Default, Debug, Deserialize, Serialize)] #[derive(Clone, Default, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)] #[serde(deny_unknown_fields)]
#[serde(default)]
pub struct ZebradConfig { pub struct ZebradConfig {
/// Tracing configuration /// Tracing configuration
pub tracing: TracingSection, pub tracing: TracingSection,
@ -23,17 +24,17 @@ pub struct ZebradConfig {
} }
/// Tracing configuration section. /// Tracing configuration section.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[serde(deny_unknown_fields)] #[serde(deny_unknown_fields)]
pub struct TracingSection { pub struct TracingSection {
/// The filter used for tracing events. /// The filter used for tracing events.
pub filter: String, pub filter: Option<String>,
} }
impl Default for TracingSection { impl TracingSection {
fn default() -> Self { pub fn populated() -> Self {
Self { Self {
filter: "info".to_owned(), filter: Some("info".to_owned()),
} }
} }
} }