From 84525c089d2a72e5087b29d2a6ee373f5f9f20ef Mon Sep 17 00:00:00 2001 From: Ryan Butler Date: Wed, 11 Dec 2024 16:49:31 -0600 Subject: [PATCH] refactor(update-verifier): use orb-telemetry (#327) --- Cargo.lock | 36 ++++++++--------- Cargo.toml | 2 + update-verifier/Cargo.toml | 22 +++++------ update-verifier/src/checks/mcu.rs | 11 +++--- update-verifier/src/lib.rs | 1 + update-verifier/src/main.rs | 18 ++++----- update-verifier/src/telemetry.rs | 64 ------------------------------- 7 files changed, 44 insertions(+), 110 deletions(-) delete mode 100644 update-verifier/src/telemetry.rs diff --git a/Cargo.lock b/Cargo.lock index ec9d1fff..19438c0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1564,8 +1564,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86ed14aa9c9f927213c6e4f3ef75faaad3406134efe84ba2cb7983431d5f0931" dependencies = [ "futures-core", - "prost 0.13.3", - "prost-types 0.13.3", + "prost 0.13.4", + "prost-types 0.13.4", "tonic", "tracing-core", ] @@ -1583,8 +1583,8 @@ dependencies = [ "hdrhistogram", "humantime", "hyper-util", - "prost 0.13.3", - "prost-types 0.13.3", + "prost 0.13.4", + "prost-types 0.13.4", "serde", "serde_json", "thread_local", @@ -4339,7 +4339,7 @@ version = "0.2.10" dependencies = [ "color-eyre", "data-encoding", - "event-listener 2.5.3", + "event-listener 5.3.1", "eyre", "futures", "orb-attest-dbus", @@ -4793,19 +4793,19 @@ dependencies = [ [[package]] name = "orb-update-verifier" -version = "0.2.5" +version = "0.2.6" dependencies = [ "can-rs 0.0.0", "clap", - "eyre", + "color-eyre", "flume", "httpmock", "jod-thread", "libc", - "log", "orb-build-info 0.0.0", "orb-messages 0.0.0 (git+https://github.com/worldcoin/orb-messages?rev=787ab78581b705af0946bcfe3a0453b64af2193f)", "orb-slot-ctrl 0.3.1", + "orb-telemetry", "polling 2.5.2", "prost 0.12.6", "prost-build", @@ -4816,8 +4816,6 @@ dependencies = [ "tap", "thiserror", "tracing", - "tracing-journald", - "tracing-subscriber", "zbus", "zbus_systemd", ] @@ -5251,12 +5249,12 @@ dependencies = [ [[package]] name = "prost" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b0487d90e047de87f984913713b85c601c05609aad5b0df4b4573fbf69aa13f" +checksum = "2c0fef6c4230e4ccf618a35c59d7ede15dea37de8427500f50aff708806e42ec" dependencies = [ "bytes", - "prost-derive 0.13.3", + "prost-derive 0.13.4", ] [[package]] @@ -5295,9 +5293,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9552f850d5f0964a4e4d0bf306459ac29323ddfbae05e35a7c0d35cb0803cc5" +checksum = "157c5a9d7ea5c2ed2d9fb8f495b64759f7816c7eaea54ba3978f0d63000162e3" dependencies = [ "anyhow", "itertools 0.12.1", @@ -5317,11 +5315,11 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4759aa0d3a6232fb8dbdb97b61de2c20047c68aca932c7ed76da9d788508d670" +checksum = "cc2f1e56baa61e93533aebc21af4d2134b70f66275e0fcdf3cbe43d77ff7e8fc" dependencies = [ - "prost 0.13.3", + "prost 0.13.4", ] [[package]] @@ -6850,7 +6848,7 @@ dependencies = [ "hyper-util", "percent-encoding", "pin-project", - "prost 0.13.3", + "prost 0.13.4", "socket2", "tokio", "tokio-stream", diff --git a/Cargo.toml b/Cargo.toml index 08206562..020a02f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,6 +65,8 @@ hex-literal = "0.4.1" jose-jwk = { version = "0.1.2", default-features = false } libc = "0.2.153" nix = { version = "0.28", default-features = false, features = [] } +prost = "0.13.4" +prost-build = "0.13.4" reqwest = { version = "0.11", default-features = false, features = ["rustls-tls", "stream"] } ring = "0.16" rustix = "0.38.37" diff --git a/update-verifier/Cargo.toml b/update-verifier/Cargo.toml index 96029038..d96002df 100644 --- a/update-verifier/Cargo.toml +++ b/update-verifier/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "orb-update-verifier" -version = "0.2.5" +version = "0.2.6" description = """ Checks general system health and manages the slot and rootfs state of the Orb. """ @@ -18,22 +18,20 @@ rust-version.workspace = true [dependencies] can-rs.workspace = true clap = { workspace = true, features = ["derive"] } -eyre = "0.6.8" +color-eyre.workspace = true flume = "0.11.0" jod-thread = "0.1.2" -libc = "0.2.137" -log = "0.4.18" +libc.workspace = true orb-build-info.workspace = true orb-messages.workspace = true orb-slot-ctrl.workspace = true +orb-telemetry.workspace = true polling = "2.2.0" -prost = "0.12.4" +prost = "0.12.6" semver = "1.0.22" tap = "1.0.1" -thiserror = "1.0.37" -tracing = "0.1.37" -tracing-journald.workspace = true -tracing-subscriber = { workspace = true, features = ["env-filter"] } +thiserror.workspace = true +tracing.workspace = true zbus.workspace = true zbus_systemd = { workspace = true, features = ["login1"] } @@ -46,11 +44,11 @@ features = ["blocking", "json"] orb-build-info = { workspace = true, features = ["build-script"] } [dev-dependencies] -serde = { version = "1.0.147", features = ["derive"] } # isahc = { version = "1.7", features = ["static-ssl"] } httpmock = "0.7" -serde_json = "1.0.94" -prost-build = "0.12.4" +prost-build = "0.12.6" +serde = { workspace = true, features = ["derive"] } +serde_json.workspace = true [package.metadata.orb] unsupported_targets = [ diff --git a/update-verifier/src/checks/mcu.rs b/update-verifier/src/checks/mcu.rs index 2994c633..f08035ae 100644 --- a/update-verifier/src/checks/mcu.rs +++ b/update-verifier/src/checks/mcu.rs @@ -2,8 +2,7 @@ use crate::checks::mcu::Device::{JetsonFromMain, JetsonFromSecurity}; use can_rs::stream::FrameStream; use can_rs::CANFD_DATA_LEN; use can_rs::{Frame, Id}; -use eyre::WrapErr as _; -use log::warn; +use color_eyre::eyre::WrapErr as _; use orb_messages::mcu_main as main_messages; use orb_messages::mcu_sec as sec_messages; use polling::{Event, Poller}; @@ -12,7 +11,7 @@ use std::{ time, time::{Duration, SystemTime}, }; -use tracing::{error, info}; +use tracing::{error, info, warn}; use zbus::blocking::{Connection, Proxy}; const ARBITRARY_EVENT_KEY: usize = 1337; @@ -339,7 +338,7 @@ impl super::Check for Mcu { } } -fn trigger_shutdown() -> eyre::Result<()> { +fn trigger_shutdown() -> color_eyre::eyre::Result<()> { let connection = Connection::system()?; let proxy: Proxy<'_> = zbus::blocking::proxy::Builder::new(&connection) @@ -383,7 +382,7 @@ struct MessageStream { // that `_thread` can drop without blocking. ack_rx: flume::Receiver, msg_rx: flume::Receiver, - _thread: jod_thread::JoinHandle>, + _thread: jod_thread::JoinHandle>, } impl MessageStream { @@ -587,7 +586,7 @@ impl MessageStream { remote: Device, ack_tx: &flume::Sender, msg_tx: &flume::Sender, - ) -> eyre::Result<()> { + ) -> color_eyre::eyre::Result<()> { let poller = Poller::new().wrap_err("failed creating a new event poller")?; poller .add(stream, Event::readable(ARBITRARY_EVENT_KEY)) diff --git a/update-verifier/src/lib.rs b/update-verifier/src/lib.rs index 438ec465..4f51a636 100644 --- a/update-verifier/src/lib.rs +++ b/update-verifier/src/lib.rs @@ -3,6 +3,7 @@ use crate::checks::mcu::{Error, Mcu}; use crate::checks::Check; +use color_eyre::eyre; use orb_build_info::{make_build_info, BuildInfo}; use orb_slot_ctrl::OrbSlotCtrl; use tracing::{error, info, instrument, warn}; diff --git a/update-verifier/src/main.rs b/update-verifier/src/main.rs index a680a35d..ed1631e7 100644 --- a/update-verifier/src/main.rs +++ b/update-verifier/src/main.rs @@ -1,14 +1,13 @@ -mod telemetry; - -use crate::telemetry::ExecContext; use clap::{ builder::{styling::AnsiColor, Styles}, Parser, }; -use eyre::{self, Context}; +use color_eyre::eyre::{self, Context}; use orb_slot_ctrl::{EfiVarDb, OrbSlotCtrl}; use orb_update_verifier::BUILD_INFO; -use tracing::{error, metadata::LevelFilter}; +use tracing::error; + +const SYSLOG_IDENTIFIER: &str = "worldcoin-update-verifier"; #[derive(Parser, Debug)] #[clap( @@ -26,14 +25,15 @@ fn clap_v3_styles() -> Styles { .placeholder(AnsiColor::Green.on_default()) } -fn main() -> eyre::Result<()> { +fn main() -> color_eyre::Result<()> { + color_eyre::install()?; + orb_telemetry::TelemetryConfig::new() + .with_journald(SYSLOG_IDENTIFIER) + .init(); run().inspect_err(|error| error!(?error, "failed to run update-verifier")) } fn run() -> eyre::Result<()> { - telemetry::start::(LevelFilter::INFO, std::io::stdout) - .wrap_err("update verifier encountered error while starting telemetry")?; - let _args = Cli::parse(); let efi_var_db = EfiVarDb::from_rootfs("/")?; diff --git a/update-verifier/src/telemetry.rs b/update-verifier/src/telemetry.rs deleted file mode 100644 index 647af77e..00000000 --- a/update-verifier/src/telemetry.rs +++ /dev/null @@ -1,64 +0,0 @@ -use tap::prelude::*; -use tracing::metadata::LevelFilter; -use tracing_subscriber::{filter, fmt::MakeWriter, prelude::*, util::TryInitError}; - -const SYSLOG_IDENTIFIER: &str = "worldcoin-update-verifier"; - -fn is_tty_interactive() -> bool { - unsafe { libc::isatty(libc::STDIN_FILENO) == 1 } -} - -pub struct ExecContext; -pub struct TestContext; - -pub trait Context: private::Sealed { - const ENABLE_TELEMETRY: bool = false; -} - -impl Context for ExecContext { - const ENABLE_TELEMETRY: bool = true; -} -impl Context for TestContext {} - -mod private { - use super::{ExecContext, TestContext}; - pub trait Sealed {} - - impl Sealed for ExecContext {} - impl Sealed for TestContext {} -} - -pub fn start( - env_filter: LevelFilter, - sink: W, -) -> Result<(), TryInitError> -where - W: for<'a> MakeWriter<'a> + Send + Sync + 'static, -{ - let env_filter = filter::EnvFilter::builder() - .with_default_directive(env_filter.into()) - .from_env_lossy(); - - let mut fmt = None; - let mut journald = None; - - if C::ENABLE_TELEMETRY && !is_tty_interactive() { - journald = tracing_journald::layer() - .tap_err(|err| { - eprintln!( - "failed connecting to journald socket; will write to stdout: {err}" - ); - }) - .map(|layer| layer.with_syslog_identifier(SYSLOG_IDENTIFIER.into())) - .ok(); - } - if journald.is_none() { - fmt = Some(tracing_subscriber::fmt::layer().with_writer(sink)); - } - - tracing_subscriber::registry() - .with(fmt) - .with(journald) - .with(env_filter) - .try_init() -}