From a372d7aec82bc9f7f233657d9e9e9036d6c21501 Mon Sep 17 00:00:00 2001 From: Ziy1-Tan Date: Fri, 25 Oct 2024 21:53:59 +0800 Subject: [PATCH] remove unused features --- vmm/common/Cargo.toml | 2 +- vmm/common/src/lib.rs | 2 +- vmm/common/src/signal.rs | 6 ++--- vmm/common/src/{tracer.rs => trace.rs} | 9 ++++--- vmm/sandbox/src/bin/cloud_hypervisor/main.rs | 6 ++--- vmm/sandbox/src/bin/qemu/main.rs | 6 ++--- vmm/sandbox/src/bin/stratovirt/main.rs | 6 ++--- vmm/task/Cargo.lock | 13 ---------- vmm/task/Cargo.toml | 2 +- vmm/task/src/main.rs | 25 +++++++++++--------- 10 files changed, 35 insertions(+), 42 deletions(-) rename vmm/common/src/{tracer.rs => trace.rs} (94%) diff --git a/vmm/common/Cargo.toml b/vmm/common/Cargo.toml index b15bcd25..674d8ee7 100644 --- a/vmm/common/Cargo.toml +++ b/vmm/common/Cargo.toml @@ -21,7 +21,7 @@ regex = "1.5.6" tracing = "0.1.40" tracing-opentelemetry = "0.21.0" -tracing-subscriber = { version = "0.3.18", features = ["env-filter", "tracing-log"] } +tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } opentelemetry = { version = "0.20.0", features = ["rt-tokio"] } opentelemetry-otlp = "0.13.0" diff --git a/vmm/common/src/lib.rs b/vmm/common/src/lib.rs index 72836627..4ed7c9dc 100644 --- a/vmm/common/src/lib.rs +++ b/vmm/common/src/lib.rs @@ -20,7 +20,7 @@ pub mod api; pub mod mount; pub mod signal; pub mod storage; -pub mod tracer; +pub mod trace; pub const KUASAR_STATE_DIR: &str = "/run/kuasar/state"; diff --git a/vmm/common/src/signal.rs b/vmm/common/src/signal.rs index 465a8724..4d56be3d 100644 --- a/vmm/common/src/signal.rs +++ b/vmm/common/src/signal.rs @@ -17,15 +17,15 @@ limitations under the License. use nix::libc::{SIGINT, SIGTERM, SIGUSR1}; use signal_hook::iterator::Signals; -use crate::tracer::{enabled, set_enabled, setup_tracing}; +use crate::trace; pub async fn handle_signals(log_level: &str, otlp_service_name: &str) { let mut signals = Signals::new([SIGTERM, SIGINT, SIGUSR1]).expect("new signal failed"); for sig in signals.forever() { if sig == SIGUSR1 { - set_enabled(!enabled()); - let _ = setup_tracing(log_level, otlp_service_name); + trace::set_enabled(!trace::is_enabled()); + let _ = trace::setup_tracing(log_level, otlp_service_name); } } } diff --git a/vmm/common/src/tracer.rs b/vmm/common/src/trace.rs similarity index 94% rename from vmm/common/src/tracer.rs rename to vmm/common/src/trace.rs index baf8671c..329283f7 100644 --- a/vmm/common/src/tracer.rs +++ b/vmm/common/src/trace.rs @@ -33,7 +33,7 @@ lazy_static! { static ref ENABLED: AtomicBool = AtomicBool::new(false); } -pub fn enabled() -> bool { +pub fn is_enabled() -> bool { ENABLED.load(Ordering::Relaxed) } @@ -46,7 +46,7 @@ pub fn setup_tracing(log_level: &str, otlp_service_name: &str) -> anyhow::Result .map_err(|e| anyhow!("failed to init logger filter: {}", e))?; let mut layers = vec![tracing_subscriber::fmt::layer().boxed()]; - if enabled() { + if is_enabled() { let tracer = init_otlp_tracer(otlp_service_name) .map_err(|e| anyhow!("failed to init otlp tracer: {}", e))?; layers.push(tracing_opentelemetry::layer().with_tracer(tracer).boxed()); @@ -54,7 +54,10 @@ pub fn setup_tracing(log_level: &str, otlp_service_name: &str) -> anyhow::Result shutdown_tracing(); } - Registry::default().with(env_filter).with(layers).init(); + Registry::default() + .with(env_filter) + .with(layers) + .try_init()?; Ok(()) } diff --git a/vmm/sandbox/src/bin/cloud_hypervisor/main.rs b/vmm/sandbox/src/bin/cloud_hypervisor/main.rs index daeb7297..0869b3cf 100644 --- a/vmm/sandbox/src/bin/cloud_hypervisor/main.rs +++ b/vmm/sandbox/src/bin/cloud_hypervisor/main.rs @@ -15,7 +15,7 @@ limitations under the License. */ use clap::Parser; -use vmm_common::{signal, tracer}; +use vmm_common::{signal, trace}; use vmm_sandboxer::{ args, cloud_hypervisor::{factory::CloudHypervisorVMFactory, hooks::CloudHypervisorHooks}, @@ -37,8 +37,8 @@ async fn main() { // Update args log level if it not presents args but in config. let log_level = args.log_level.unwrap_or(config.sandbox.log_level()); let service_name = "kuasar-vmm-sandboxer-clh-service"; - tracer::set_enabled(config.sandbox.enable_tracing); - tracer::setup_tracing(&log_level, service_name).unwrap(); + trace::set_enabled(config.sandbox.enable_tracing); + trace::setup_tracing(&log_level, service_name).unwrap(); let mut sandboxer: KuasarSandboxer = KuasarSandboxer::new( diff --git a/vmm/sandbox/src/bin/qemu/main.rs b/vmm/sandbox/src/bin/qemu/main.rs index c3f20be7..3deda83b 100644 --- a/vmm/sandbox/src/bin/qemu/main.rs +++ b/vmm/sandbox/src/bin/qemu/main.rs @@ -15,7 +15,7 @@ limitations under the License. */ use clap::Parser; -use vmm_common::{signal, tracer}; +use vmm_common::{signal, trace}; use vmm_sandboxer::{ args, config::Config, @@ -53,8 +53,8 @@ async fn main() { let log_level = config.sandbox.log_level(); let service_name = "kuasar-vmm-sandboxer-qemu-service"; - tracer::set_enabled(config.sandbox.enable_tracing); - tracer::setup_tracing(&log_level, service_name).unwrap(); + trace::set_enabled(config.sandbox.enable_tracing); + trace::setup_tracing(&log_level, service_name).unwrap(); let sandboxer: KuasarSandboxer = KuasarSandboxer::new( config.sandbox, diff --git a/vmm/sandbox/src/bin/stratovirt/main.rs b/vmm/sandbox/src/bin/stratovirt/main.rs index 158222d5..6e4f155c 100644 --- a/vmm/sandbox/src/bin/stratovirt/main.rs +++ b/vmm/sandbox/src/bin/stratovirt/main.rs @@ -15,7 +15,7 @@ limitations under the License. */ use clap::Parser; -use vmm_common::{signal, tracer}; +use vmm_common::{signal, trace}; use vmm_sandboxer::{ args, config::Config, @@ -39,8 +39,8 @@ async fn main() { // Update args log level if it not presents args but in config. let log_level = config.sandbox.log_level(); let service_name = "kuasar-vmm-sandboxer-stratovirt-service"; - tracer::set_enabled(config.sandbox.enable_tracing); - tracer::setup_tracing(&log_level, service_name).unwrap(); + trace::set_enabled(config.sandbox.enable_tracing); + trace::setup_tracing(&log_level, service_name).unwrap(); let mut sandboxer: KuasarSandboxer = KuasarSandboxer::new( config.sandbox, diff --git a/vmm/task/Cargo.lock b/vmm/task/Cargo.lock index 9a9ea376..9184a301 100644 --- a/vmm/task/Cargo.lock +++ b/vmm/task/Cargo.lock @@ -2348,16 +2348,6 @@ dependencies = [ "tracing-subscriber", ] -[[package]] -name = "tracing-serde" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" -dependencies = [ - "serde", - "tracing-core", -] - [[package]] name = "tracing-subscriber" version = "0.3.18" @@ -2368,15 +2358,12 @@ dependencies = [ "nu-ansi-term", "once_cell", "regex", - "serde", - "serde_json", "sharded-slab", "smallvec", "thread_local", "tracing", "tracing-core", "tracing-log 0.2.0", - "tracing-serde", ] [[package]] diff --git a/vmm/task/Cargo.toml b/vmm/task/Cargo.toml index f4733af3..d1c1c555 100644 --- a/vmm/task/Cargo.toml +++ b/vmm/task/Cargo.toml @@ -28,7 +28,7 @@ protobuf = "3.2" tracing = "0.1.40" tracing-opentelemetry = "0.21.0" -tracing-subscriber = { version = "0.3.18", features = ["json", "env-filter"] } +tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } opentelemetry = { version = "0.20.0", features = ["rt-tokio"] } diff --git a/vmm/task/src/main.rs b/vmm/task/src/main.rs index 2afce356..01dab31a 100644 --- a/vmm/task/src/main.rs +++ b/vmm/task/src/main.rs @@ -45,8 +45,8 @@ use tracing_subscriber::{ use vmm_common::{ api::{sandbox_ttrpc::create_sandbox_service, streaming_ttrpc::create_streaming}, mount::mount, - tracer::{self, init_otlp_tracer}, - ETC_RESOLV, IPC_NAMESPACE, KUASAR_STATE_DIR, PID_NAMESPACE, RESOLV_FILENAME, UTS_NAMESPACE, + trace, ETC_RESOLV, IPC_NAMESPACE, KUASAR_STATE_DIR, PID_NAMESPACE, RESOLV_FILENAME, + UTS_NAMESPACE, }; use crate::{ @@ -149,7 +149,7 @@ async fn initialize() -> anyhow::Result { early_init_call().await?; let config = TaskConfig::new().await?; - tracer::set_enabled(config.enable_tracing); + trace::set_enabled(config.enable_tracing); init_logger(&config.log_level)?; info!("Task server start with config: {:?}", config); @@ -183,15 +183,18 @@ fn init_logger(log_level: &str) -> anyhow::Result<()> { .add_directive(format!("vmm_task={}", log_level).parse()?); let mut layers = vec![tracing_subscriber::fmt::layer().boxed()]; - - if tracer::enabled() { - let tracer = init_otlp_tracer("kuasar-vmm-task-service") + if trace::is_enabled() { + let tracer = trace::init_otlp_tracer("kuasar-vmm-task-service") .map_err(|e| anyhow!("failed to init otlp tracer: {}", e))?; layers.push(tracing_opentelemetry::layer().with_tracer(tracer).boxed()); + } else { + trace::shutdown_tracing(); } - Registry::default().with(env_filter).with(layers).init(); - + Registry::default() + .with(env_filter) + .with(layers) + .try_init()?; Ok(()) } @@ -251,8 +254,8 @@ async fn handle_signals(signals: Signals, log_level: &str) { while let Some(sig) = signals.next().await { match sig { libc::SIGTERM | libc::SIGINT => { - tracer::set_enabled(false); - tracer::shutdown_tracing(); + trace::set_enabled(false); + trace::shutdown_tracing(); debug!("received {}", sig); } libc::SIGCHLD => loop { @@ -320,7 +323,7 @@ async fn handle_signals(signals: Signals, log_level: &str) { } }, libc::SIGUSR1 => { - tracer::set_enabled(!tracer::enabled()); + trace::set_enabled(!trace::is_enabled()); let _ = init_logger(log_level); } _ => {