From c7bb9610abdbb07bbf9c8ce7e005420f4aeb5730 Mon Sep 17 00:00:00 2001 From: Ziy1-Tan Date: Sun, 8 Sep 2024 23:28:11 +0800 Subject: [PATCH] fix style Signed-off-by: Ziy1-Tan --- vmm/common/Cargo.toml | 2 +- vmm/common/src/tracer.rs | 3 +-- vmm/sandbox/config_clh.toml | 2 +- vmm/sandbox/src/bin/cloud_hypervisor/main.rs | 8 +------- vmm/sandbox/src/bin/qemu/main.rs | 3 +-- vmm/sandbox/src/bin/stratovirt/main.rs | 3 +-- vmm/sandbox/src/client.rs | 2 +- vmm/task/src/main.rs | 17 +++++++++++------ vmm/task/src/sandbox.rs | 1 - 9 files changed, 18 insertions(+), 23 deletions(-) diff --git a/vmm/common/Cargo.toml b/vmm/common/Cargo.toml index 78ad289e..1cc31193 100644 --- a/vmm/common/Cargo.toml +++ b/vmm/common/Cargo.toml @@ -28,4 +28,4 @@ opentelemetry-otlp = "0.13.0" [build-dependencies] ttrpc-codegen = { git = "https://github.com/kuasar-io/ttrpc-rust.git", branch = "v0.7.1-kuasar" } -tonic-build = "0.7.2" \ No newline at end of file +tonic-build = "0.7.2" diff --git a/vmm/common/src/tracer.rs b/vmm/common/src/tracer.rs index c76fb634..e18c2973 100644 --- a/vmm/common/src/tracer.rs +++ b/vmm/common/src/tracer.rs @@ -14,8 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -use opentelemetry::sdk::trace::Tracer; -use opentelemetry::sdk::{trace, Resource}; +use opentelemetry::sdk::{trace, trace::Tracer, Resource}; use tracing_subscriber::EnvFilter; pub fn init_otlp_tracer(otlp_service_name: &str) -> anyhow::Result { diff --git a/vmm/sandbox/config_clh.toml b/vmm/sandbox/config_clh.toml index dd9b0207..9622e8bb 100644 --- a/vmm/sandbox/config_clh.toml +++ b/vmm/sandbox/config_clh.toml @@ -23,4 +23,4 @@ path = "/usr/local/bin/virtiofsd" log_level = "info" cache = "never" thread_pool_size = 4 -syslog = true \ No newline at end of file +syslog = true diff --git a/vmm/sandbox/src/bin/cloud_hypervisor/main.rs b/vmm/sandbox/src/bin/cloud_hypervisor/main.rs index 193ba21e..fa8d5386 100644 --- a/vmm/sandbox/src/bin/cloud_hypervisor/main.rs +++ b/vmm/sandbox/src/bin/cloud_hypervisor/main.rs @@ -17,8 +17,7 @@ limitations under the License. use clap::Parser; use opentelemetry::global; use tracing::{info, info_span}; -use tracing_subscriber::Layer; -use tracing_subscriber::{layer::SubscriberExt, Registry}; +use tracing_subscriber::{layer::SubscriberExt, Layer, Registry}; use vmm_common::tracer::{init_logger_filter, init_otlp_tracer}; use vmm_sandboxer::{ args, @@ -46,7 +45,6 @@ async fn main() { if config.sandbox.enable_tracing { let tracer = init_otlp_tracer("kuasar-vmm-sandboxer-clh-tracing-service") .expect("failed to init otlp tracer"); - layers.push(tracing_opentelemetry::layer().with_tracer(tracer).boxed()); } @@ -65,8 +63,6 @@ async fn main() { // Do recovery job sandboxer.recover(&args.dir).await; - info!("Kuasar vmm sandboxer clh is started"); - // Run the sandboxer containerd_sandbox::run( "kuasar-vmm-sandboxer-clh", @@ -77,8 +73,6 @@ async fn main() { .await .unwrap(); - info!("Kuasar vmm sandboxer clh is exited"); - root_span.exit(); global::shutdown_tracer_provider(); } diff --git a/vmm/sandbox/src/bin/qemu/main.rs b/vmm/sandbox/src/bin/qemu/main.rs index a9c9bd23..ec217567 100644 --- a/vmm/sandbox/src/bin/qemu/main.rs +++ b/vmm/sandbox/src/bin/qemu/main.rs @@ -17,8 +17,7 @@ limitations under the License. use clap::Parser; use opentelemetry::global; use tracing::{info, info_span}; -use tracing_subscriber::Layer; -use tracing_subscriber::{layer::SubscriberExt, Registry}; +use tracing_subscriber::{layer::SubscriberExt, Layer, Registry}; use vmm_common::tracer::{init_logger_filter, init_otlp_tracer}; use vmm_sandboxer::{ args, diff --git a/vmm/sandbox/src/bin/stratovirt/main.rs b/vmm/sandbox/src/bin/stratovirt/main.rs index 395347e1..3ba6b627 100644 --- a/vmm/sandbox/src/bin/stratovirt/main.rs +++ b/vmm/sandbox/src/bin/stratovirt/main.rs @@ -17,8 +17,7 @@ limitations under the License. use clap::Parser; use opentelemetry::global; use tracing::{info, info_span}; -use tracing_subscriber::{layer::SubscriberExt, Registry}; -use tracing_subscriber::Layer; +use tracing_subscriber::{layer::SubscriberExt, Layer, Registry}; use vmm_common::tracer::{init_logger_filter, init_otlp_tracer}; use vmm_sandboxer::{ args, diff --git a/vmm/sandbox/src/client.rs b/vmm/sandbox/src/client.rs index 47f7e08d..20e1583c 100644 --- a/vmm/sandbox/src/client.rs +++ b/vmm/sandbox/src/client.rs @@ -42,11 +42,11 @@ use tokio::{ net::UnixStream, time::timeout, }; +use tracing::{debug, error}; use ttrpc::{ context::with_timeout, r#async::{Client, TtrpcContext}, }; -use tracing::{debug, error}; use vmm_common::api::{ sandbox::{CheckRequest, SetupSandboxRequest, SyncClockPacket}, sandbox_ttrpc::SandboxServiceClient, diff --git a/vmm/task/src/main.rs b/vmm/task/src/main.rs index ce71cb24..b1bd9ab5 100644 --- a/vmm/task/src/main.rs +++ b/vmm/task/src/main.rs @@ -18,6 +18,7 @@ limitations under the License. use std::{collections::HashMap, convert::TryFrom, path::Path, process::exit, sync::Arc}; +use anyhow::anyhow; use containerd_shim::{ asynchronous::{monitor::monitor_notify_by_pid, util::asyncify}, error::Error, @@ -177,18 +178,22 @@ async fn initialize() -> anyhow::Result<()> { fn init_logger(log_level: &str, enable_tracing: bool) -> anyhow::Result<()> { let env_filter = EnvFilter::from_default_env() - .add_directive(format!("containerd_shim={:?}", log_level).parse()?) - .add_directive(format!("vmm_task={:?}", log_level).parse()?); + .add_directive(format!("containerd_shim={}", log_level).parse()?) + .add_directive(format!("vmm_task={}", log_level).parse()?); let mut layers = vec![tracing_subscriber::fmt::layer().boxed()]; if enable_tracing { - let tracer = init_otlp_tracer("kuasar-vmm-task-otlp-service")?; + let tracer = init_otlp_tracer("kuasar-vmm-task-tracing-service")?; layers.push(tracing_opentelemetry::layer().with_tracer(tracer).boxed()); } let subscriber = Registry::default().with(env_filter).with(layers); - tracing::subscriber::set_global_default(subscriber).expect("unable to set global subscriber"); - + match tracing::subscriber::set_global_default(subscriber) { + Ok(_) => {} + Err(e) => { + return Err(anyhow!("failed to set global default subscriber: {}", e)); + } + } Ok(()) } @@ -198,6 +203,7 @@ async fn main() { error!("failed to do init call: {:?}", e); exit(-1); } + let root_span = info_span!("kuasar-vmm-task-root").entered(); // Keep server alive in main function let mut server = match create_ttrpc_server().await { @@ -212,7 +218,6 @@ async fn main() { exit(-1); } - let root_span = info_span!("kuasar-vmm-task-root").entered(); let signals = match Signals::new([libc::SIGTERM, libc::SIGINT, libc::SIGPIPE, libc::SIGCHLD]) { Ok(s) => s, diff --git a/vmm/task/src/sandbox.rs b/vmm/task/src/sandbox.rs index f3c12a3d..2cdc9900 100644 --- a/vmm/task/src/sandbox.rs +++ b/vmm/task/src/sandbox.rs @@ -29,7 +29,6 @@ use nix::{ }; use tokio::fs::File; use tracing::{debug, warn}; - use vmm_common::{ mount::{mount, unmount}, storage::{Storage, DRIVERBLKTYPE, DRIVEREPHEMERALTYPE, DRIVERSCSITYPE},