diff --git a/Cargo.lock b/Cargo.lock index 579bd74b..ec9d1fff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4731,7 +4731,7 @@ dependencies = [ [[package]] name = "orb-update-agent" -version = "6.0.1" +version = "6.0.2" dependencies = [ "bytes", "can-rs 0.0.0 (git+https://github.com/worldcoin/orb-software?rev=f13df5b723272efc55abf22cacce3625bbd1af04)", @@ -4750,6 +4750,7 @@ dependencies = [ "orb-build-info 0.0.0", "orb-messages 0.0.0 (git+https://github.com/worldcoin/orb-messages?rev=c439077c7c1bc3a8eb6f224c32b5b4d60d094809)", "orb-slot-ctrl 0.3.0", + "orb-telemetry", "orb-update-agent-core", "orb-zbus-proxies", "polling 2.5.2", @@ -4764,8 +4765,6 @@ dependencies = [ "thiserror", "toml", "tracing", - "tracing-journald", - "tracing-subscriber", "url", "xz2", "zbus", diff --git a/telemetry/src/lib.rs b/telemetry/src/lib.rs index a33dd64f..98bb1ecb 100644 --- a/telemetry/src/lib.rs +++ b/telemetry/src/lib.rs @@ -46,12 +46,7 @@ impl TelemetryConfig { } } - /// Initializes the telemetry config. Call this only once, at the beginning of the - /// program. - /// - /// Calling this more than once or when another tracing subscriber is registered - /// will cause a panic. - pub fn init(self) { + pub fn try_init(self) -> Result<(), tracing_subscriber::util::TryInitError> { let registry = tracing_subscriber::registry(); // The type is only there to get it to compile. let tokio_console_layer: Option = None; @@ -82,6 +77,15 @@ impl TelemetryConfig { .with(stderr_layer) .with(journald_layer) .with(self.global_filter) - .init(); + .try_init() + } + + /// Initializes the telemetry config. Call this only once, at the beginning of the + /// program. + /// + /// Calling this more than once or when another tracing subscriber is registered + /// will cause a panic. + pub fn init(self) { + self.try_init().expect("failed to initialize orb-telemetry") } } diff --git a/update-agent/Cargo.toml b/update-agent/Cargo.toml index fa65e02a..b5766970 100644 --- a/update-agent/Cargo.toml +++ b/update-agent/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "orb-update-agent" -version = "6.0.1" +version = "6.0.2" authors = [ "Richard Janis Goldschmidt", "Galileo Daras ", @@ -19,8 +19,8 @@ can-update-test = [] skip-manifest-signature-verification = ["orb-update-agent-core/skip-manifest-signature-verification"] [dependencies] -bytes = "1.3.0" -clap = { version = "4", features = ["derive"] } +bytes.workspace = true +clap = { workspace = true, features = ["derive"] } const_format = "0.2.30" crc32fast = "1.3" eyre.workspace = true @@ -29,10 +29,11 @@ flume = "0.11.0" gpt.workspace = true hex = "0.4.3" jod-thread = "0.1.2" -libc = "0.2" -nix = { version = "0.28", default-features = false, features = ["fs"] } +libc.workspace = true +nix = { workspace = true, default-features = false, features = ["fs"] } once_cell = "1.17.0" orb-build-info.workspace = true +orb-telemetry.workspace = true orb-update-agent-core.workspace = true orb-zbus-proxies = { workspace = true, features = ["login1"] } polling = "2.2.0" @@ -44,8 +45,6 @@ sha2.workspace = true tap = "1.0.1" tempfile = "3.8.0" thiserror.workspace = true -tracing-journald.workspace = true -tracing-subscriber = { workspace = true, features = ["registry", "env-filter", "std"] } tracing.workspace = true url = "2.2.2" xz2 = "0.1.6" diff --git a/update-agent/src/lib.rs b/update-agent/src/lib.rs index 4f82ce45..5c4b5705 100644 --- a/update-agent/src/lib.rs +++ b/update-agent/src/lib.rs @@ -3,7 +3,6 @@ pub mod client; pub mod component; pub mod dbus; pub mod json; -pub mod logging; pub mod manifest; pub mod mount; pub mod settings; diff --git a/update-agent/src/logging.rs b/update-agent/src/logging.rs deleted file mode 100644 index dfc3792d..00000000 --- a/update-agent/src/logging.rs +++ /dev/null @@ -1,66 +0,0 @@ -use std::io::IsTerminal; - -use eyre::{self, WrapErr}; -use tracing::warn; -use tracing_subscriber::{ - self, - filter::{EnvFilter, LevelFilter}, - prelude::*, - Layer, -}; - -const SYSLOG_IDENTIFIER: &str = "worldcoin-update-agent"; - -fn try_init_journal() -> eyre::Result<()> { - let filter = EnvFilter::builder() - .with_default_directive(LevelFilter::INFO.into()) - .from_env_lossy(); - - let journal = tracing_journald::layer() - .wrap_err("Failed to initialize journald logger")? - .with_syslog_identifier(SYSLOG_IDENTIFIER.to_owned()) - .with_filter(filter); - tracing_subscriber::registry().with(journal).try_init()?; - Ok(()) -} - -fn try_init_stdout_logger() -> eyre::Result<()> { - let filter = EnvFilter::builder() - .with_default_directive(LevelFilter::INFO.into()) - .from_env_lossy(); - - let stdout_log = tracing_subscriber::fmt::layer() - .compact() - .with_writer(std::io::stdout) - .with_filter(filter); - let stderr_log = tracing_subscriber::fmt::layer() - .compact() - .with_writer(std::io::stderr); - - tracing_subscriber::registry() - .with( - stderr_log - .with_filter(LevelFilter::WARN) - .and_then(stdout_log), - ) - .try_init()?; - - Ok(()) -} - -/// Initialize the logger -pub fn init() { - let mut err: Option = None; - let istty = std::io::stdin().is_terminal(); - if !istty { - err = try_init_journal().err(); - } - - if istty || err.is_some() { - err = try_init_stdout_logger().err(); - } - - if let Some(e) = err { - warn!("failed to initialize journald logger: {}", e); - } -} diff --git a/update-agent/src/main.rs b/update-agent/src/main.rs index 27035cc8..110c77d2 100644 --- a/update-agent/src/main.rs +++ b/update-agent/src/main.rs @@ -41,17 +41,19 @@ use slot_ctrl::EfiVar; use tracing::{debug, error, info, warn}; mod update_agent_result; -use orb_update_agent::logging; use update_agent_result::UpdateAgentResult; const CFG_DEFAULT_PATH: &str = "/etc/orb_update_agent.conf"; const ENV_VAR_PREFIX: &str = "ORB_UPDATE_AGENT_"; const CFG_ENV_VAR: &str = const_format::concatcp!(ENV_VAR_PREFIX, "CONFIG"); +const SYSLOG_IDENTIFIER: &str = "worldcoin-update-agent"; fn main() -> UpdateAgentResult { - let args = Args::parse(); + orb_telemetry::TelemetryConfig::new() + .with_journald(SYSLOG_IDENTIFIER) + .init(); - logging::init(); + let args = Args::parse(); match run(&args) { Ok(_) => UpdateAgentResult::Success, diff --git a/update-agent/src/update/mod.rs b/update-agent/src/update/mod.rs index 84648a0a..33cab211 100644 --- a/update-agent/src/update/mod.rs +++ b/update-agent/src/update/mod.rs @@ -25,7 +25,6 @@ impl Update for Component { } } -#[cfg(feature = "can-update-test")] #[cfg(test)] mod tests; diff --git a/update-agent/src/update/tests.rs b/update-agent/src/update/tests.rs index ecc46311..8bda3c1b 100644 --- a/update-agent/src/update/tests.rs +++ b/update-agent/src/update/tests.rs @@ -4,9 +4,10 @@ use crate::update::Update; /// test updating the main mcu #[test] +//#[cfg(feature = "can-update-test")] #[ignore = "needs vcan interface"] pub fn try_can_update() -> eyre::Result<()> { - crate::logging::init(); + orb_telemetry::TelemetryConfig::new().try_init().ok(); let mut file = File::open("/mnt/scratch/app_mcu_main_test.bin")?; diff --git a/update-agent/tests/main.rs b/update-agent/tests/main.rs index ab096f32..eacbdd59 100644 --- a/update-agent/tests/main.rs +++ b/update-agent/tests/main.rs @@ -3,12 +3,10 @@ use std::{ io::{Read, Seek}, }; -use orb_update_agent::logging; - #[ignore = "requires specific block device"] #[test] fn test_blockdevice_size() { - logging::init(); + orb_telemetry::TelemetryConfig::new().init(); let mut block_device: File = std::fs::OpenOptions::new() .read(true)