From 08cfdc8d93d33f5e216276cbc74f9dcf89aeb569 Mon Sep 17 00:00:00 2001 From: Ziy1-Tan Date: Sun, 8 Sep 2024 21:34:07 +0800 Subject: [PATCH] instrument skip all Signed-off-by: Ziy1-Tan --- vmm/sandbox/src/bin/qemu/main.rs | 5 +- vmm/sandbox/src/bin/stratovirt/main.rs | 5 +- vmm/sandbox/src/cloud_hypervisor/mod.rs | 22 ++++----- vmm/sandbox/src/sandbox.rs | 62 ++++++++++++------------- vmm/task/src/container.rs | 4 +- 5 files changed, 51 insertions(+), 47 deletions(-) diff --git a/vmm/sandbox/src/bin/qemu/main.rs b/vmm/sandbox/src/bin/qemu/main.rs index 7d6c2299..a9c9bd23 100644 --- a/vmm/sandbox/src/bin/qemu/main.rs +++ b/vmm/sandbox/src/bin/qemu/main.rs @@ -16,7 +16,7 @@ limitations under the License. use clap::Parser; use opentelemetry::global; -use tracing::info_span; +use tracing::{info, info_span}; use tracing_subscriber::Layer; use tracing_subscriber::{layer::SubscriberExt, Registry}; use vmm_common::tracer::{init_logger_filter, init_otlp_tracer}; @@ -77,6 +77,7 @@ async fn main() { QemuHooks::new(config.hypervisor), ); + info!("Kuasar vmm sandboxer clh is started"); // Run the sandboxer containerd_sandbox::run( "kuasar-vmm-sandboxer-qemu", @@ -87,6 +88,8 @@ 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/stratovirt/main.rs b/vmm/sandbox/src/bin/stratovirt/main.rs index e65315c7..395347e1 100644 --- a/vmm/sandbox/src/bin/stratovirt/main.rs +++ b/vmm/sandbox/src/bin/stratovirt/main.rs @@ -16,7 +16,7 @@ limitations under the License. use clap::Parser; use opentelemetry::global; -use tracing::info_span; +use tracing::{info, info_span}; use tracing_subscriber::{layer::SubscriberExt, Registry}; use tracing_subscriber::Layer; use vmm_common::tracer::{init_logger_filter, init_otlp_tracer}; @@ -65,6 +65,7 @@ async fn main() { // Do recovery job sandboxer.recover(&args.dir).await; + info!("Kuasar vmm sandboxer stratovirt is started"); // Run the sandboxer containerd_sandbox::run( "kuasar-vmm-sandboxer-stratovirt", @@ -75,6 +76,8 @@ async fn main() { .await .unwrap(); + info!("Kuasar vmm sandboxer stratovirt is exited"); + root_span.exit(); global::shutdown_tracer_provider(); } diff --git a/vmm/sandbox/src/cloud_hypervisor/mod.rs b/vmm/sandbox/src/cloud_hypervisor/mod.rs index 1eb31be0..39d33cf6 100644 --- a/vmm/sandbox/src/cloud_hypervisor/mod.rs +++ b/vmm/sandbox/src/cloud_hypervisor/mod.rs @@ -157,7 +157,7 @@ impl CloudHypervisorVM { #[async_trait] impl VM for CloudHypervisorVM { - #[instrument(skip(self))] + #[instrument(skip_all)] async fn start(&mut self) -> Result { create_dir_all(&self.base_dir).await?; let virtiofsd_pid = self.start_virtiofsd().await?; @@ -216,7 +216,7 @@ impl VM for CloudHypervisorVM { Ok(pid.unwrap_or_default()) } - #[instrument(skip(self))] + #[instrument(skip_all)] async fn stop(&mut self, force: bool) -> Result<()> { let signal = if force { signal::SIGKILL @@ -248,7 +248,7 @@ impl VM for CloudHypervisorVM { Ok(()) } - #[instrument(skip(self))] + #[instrument(skip_all)] async fn attach(&mut self, device_info: DeviceInfo) -> Result<()> { match device_info { DeviceInfo::Block(blk_info) => { @@ -283,37 +283,37 @@ impl VM for CloudHypervisorVM { Ok(()) } - #[instrument(skip(self))] + #[instrument(skip_all)] async fn hot_attach(&mut self, device_info: DeviceInfo) -> Result<(BusType, String)> { let client = self.get_client()?; let addr = client.hot_attach(device_info)?; Ok((BusType::PCI, addr)) } - #[instrument(skip(self))] + #[instrument(skip_all)] async fn hot_detach(&mut self, id: &str) -> Result<()> { let client = self.get_client()?; client.hot_detach(id)?; Ok(()) } - #[instrument(skip(self))] + #[instrument(skip_all)] async fn ping(&self) -> Result<()> { // TODO Ok(()) } - #[instrument(skip(self))] + #[instrument(skip_all)] fn socket_address(&self) -> String { self.agent_socket.to_string() } - #[instrument(skip(self))] + #[instrument(skip_all)] async fn wait_channel(&self) -> Option> { self.wait_chan.clone() } - #[instrument(skip(self))] + #[instrument(skip_all)] async fn vcpus(&self) -> Result { // Refer to https://github.com/firecracker-microvm/firecracker/issues/718 Ok(VcpuThreads { @@ -335,7 +335,7 @@ impl VM for CloudHypervisorVM { }) } - #[instrument(skip(self))] + #[instrument(skip_all)] fn pids(&self) -> Pids { self.pids.clone() } @@ -343,7 +343,7 @@ impl VM for CloudHypervisorVM { #[async_trait] impl crate::vm::Recoverable for CloudHypervisorVM { - #[instrument(skip(self))] + #[instrument(skip_all)] async fn recover(&mut self) -> Result<()> { self.client = Some(self.create_client().await?); let pid = self.pid()?; diff --git a/vmm/sandbox/src/sandbox.rs b/vmm/sandbox/src/sandbox.rs index 77df75e4..d7be2c91 100644 --- a/vmm/sandbox/src/sandbox.rs +++ b/vmm/sandbox/src/sandbox.rs @@ -34,8 +34,8 @@ use tokio::{ io::{AsyncReadExt, AsyncWriteExt}, sync::{Mutex, RwLock}, }; -use ttrpc::context::with_timeout; use tracing::{debug, error, info, instrument, warn}; +use ttrpc::context::with_timeout; use vmm_common::{ api::{empty::Empty, sandbox::SetupSandboxRequest, sandbox_ttrpc::SandboxServiceClient}, storage::Storage, @@ -84,7 +84,7 @@ where H: Hooks, F::VM: VM + DeserializeOwned + Recoverable + Sync + Send + 'static, { - #[instrument(skip(self))] + #[instrument(skip_all)] pub async fn recover(&mut self, dir: &str) { let mut subs = match tokio::fs::read_dir(dir).await { Ok(subs) => subs, @@ -155,7 +155,7 @@ where { type Sandbox = KuasarSandbox; - #[instrument(skip(self))] + #[instrument(skip_all)] async fn create(&self, id: &str, s: SandboxOption) -> Result<()> { if self.sandboxes.read().await.get(id).is_some() { return Err(Error::AlreadyExist("sandbox".to_string())); @@ -206,7 +206,7 @@ where Ok(()) } - #[instrument(skip(self))] + #[instrument(skip_all)] async fn start(&self, id: &str) -> Result<()> { let sandbox_mutex = self.sandbox(id).await?; let mut sandbox = sandbox_mutex.lock().await; @@ -255,7 +255,7 @@ where Ok(()) } - #[instrument(skip(self))] + #[instrument(skip_all)] async fn update(&self, id: &str, data: SandboxData) -> Result<()> { let sandbox_mutex = self.sandbox(id).await?; let mut sandbox = sandbox_mutex.lock().await; @@ -264,7 +264,7 @@ where Ok(()) } - #[instrument(skip(self))] + #[instrument(skip_all)] async fn sandbox(&self, id: &str) -> Result>> { Ok(self .sandboxes @@ -275,7 +275,7 @@ where .clone()) } - #[instrument(skip(self))] + #[instrument(skip_all)] async fn stop(&self, id: &str, force: bool) -> Result<()> { let sandbox_mutex = self.sandbox(id).await?; let mut sandbox = sandbox_mutex.lock().await; @@ -286,7 +286,7 @@ where Ok(()) } - #[instrument(skip(self))] + #[instrument(skip_all)] async fn delete(&self, id: &str) -> Result<()> { let sb_clone = self.sandboxes.read().await.clone(); if let Some(sb_mutex) = sb_clone.get(id) { @@ -319,17 +319,17 @@ where { type Container = KuasarContainer; - #[instrument(skip(self))] + #[instrument(skip_all)] fn status(&self) -> Result { Ok(self.status.clone()) } - #[instrument(skip(self))] + #[instrument(skip_all)] async fn ping(&self) -> Result<()> { self.vm.ping().await } - #[instrument(skip(self))] + #[instrument(skip_all)] async fn container(&self, id: &str) -> Result<&Self::Container> { let container = self .containers @@ -338,7 +338,7 @@ where Ok(container) } - #[instrument(skip(self))] + #[instrument(skip_all)] async fn append_container(&mut self, id: &str, options: ContainerOption) -> Result<()> { let handler_chain = self.container_append_handlers(id, options)?; handler_chain.handle(self).await?; @@ -346,7 +346,7 @@ where Ok(()) } - #[instrument(skip(self))] + #[instrument(skip_all)] async fn update_container(&mut self, id: &str, options: ContainerOption) -> Result<()> { let handler_chain = self.container_update_handlers(id, options).await?; handler_chain.handle(self).await?; @@ -354,7 +354,7 @@ where Ok(()) } - #[instrument(skip(self))] + #[instrument(skip_all)] async fn remove_container(&mut self, id: &str) -> Result<()> { self.deference_container_storages(id).await?; @@ -378,12 +378,12 @@ where Ok(()) } - #[instrument(skip(self))] + #[instrument(skip_all)] async fn exit_signal(&self) -> Result> { Ok(self.exit_signal.clone()) } - #[instrument(skip(self))] + #[instrument(skip_all)] fn get_data(&self) -> Result { Ok(self.data.clone()) } @@ -393,7 +393,7 @@ impl KuasarSandbox where V: VM + Sync + Send, { - #[instrument(skip(self))] + #[instrument(skip_all)] async fn dump(&self) -> Result<()> { let dump_data = serde_json::to_vec(&self).map_err(|e| anyhow!("failed to serialize sandbox, {}", e))?; @@ -417,7 +417,7 @@ impl KuasarSandbox where V: VM + DeserializeOwned + Recoverable + Sync + Send, { - #[instrument(skip(base_dir))] + #[instrument(skip_all)] async fn recover>(base_dir: P) -> Result { let dump_path = base_dir.as_ref().join("sandbox.json"); let mut dump_file = OpenOptions::new() @@ -463,8 +463,7 @@ impl KuasarSandbox where V: VM + Sync + Send, { - - #[instrument(skip(self))] + #[instrument(skip_all)] async fn start(&mut self) -> Result<()> { let pid = self.vm.start().await?; @@ -490,7 +489,7 @@ where Ok(()) } - #[instrument(skip(self))] + #[instrument(skip_all)] async fn stop(&mut self, force: bool) -> Result<()> { match self.status { // If a sandbox is created: @@ -526,20 +525,20 @@ where Ok(()) } - #[instrument(skip(self))] + #[instrument(skip_all)] pub(crate) fn container_mut(&mut self, id: &str) -> Result<&mut KuasarContainer> { self.containers .get_mut(id) .ok_or_else(|| Error::NotFound(format!("no container with id {}", id))) } - #[instrument(skip(self))] + #[instrument(skip_all)] pub(crate) fn increment_and_get_id(&mut self) -> u32 { self.id_generator += 1; self.id_generator } - #[instrument(skip(self))] + #[instrument(skip_all)] async fn init_client(&mut self) -> Result<()> { let mut client_guard = self.client.lock().await; if client_guard.is_none() { @@ -555,8 +554,7 @@ where Ok(()) } - - #[instrument(skip(self))] + #[instrument(skip_all)] pub(crate) async fn setup_sandbox(&mut self) -> Result<()> { let mut req = SetupSandboxRequest::new(); @@ -591,14 +589,14 @@ where Ok(()) } - #[instrument(skip(self))] + #[instrument(skip_all)] pub(crate) async fn sync_clock(&self) { if let Some(client) = &*self.client.lock().await { client_sync_clock(client, self.id.as_str(), self.exit_signal.clone()); } } - #[instrument(skip(self))] + #[instrument(skip_all)] async fn setup_sandbox_files(&self) -> Result<()> { let shared_path = self.get_sandbox_shared_path(); create_dir_all(&shared_path) @@ -648,12 +646,12 @@ where Ok(()) } - #[instrument(skip(self))] + #[instrument(skip_all)] pub fn get_sandbox_shared_path(&self) -> String { format!("{}/{}", self.base_dir, SHARED_DIR_SUFFIX) } - #[instrument(skip(self))] + #[instrument(skip_all)] pub async fn prepare_network(&mut self) -> Result<()> { // get vcpu for interface queue, at least one vcpu let mut vcpu = 1; @@ -676,7 +674,7 @@ where } // If a sandbox is still running, destroy network may hang with its running - #[instrument(skip(self))] + #[instrument(skip_all)] pub async fn destroy_network(&mut self) { // Network should be destroyed only once, take it out here. if let Some(mut network) = self.network.take() { @@ -684,7 +682,7 @@ where } } - #[instrument(skip(self))] + #[instrument(skip_all)] pub async fn add_to_cgroup(&self) -> Result<()> { // Currently only support cgroup V1, cgroup V2 is not supported now if !cgroups_rs::hierarchies::is_cgroup2_unified_mode() { diff --git a/vmm/task/src/container.rs b/vmm/task/src/container.rs index abdea24d..9c5eedaf 100644 --- a/vmm/task/src/container.rs +++ b/vmm/task/src/container.rs @@ -108,7 +108,7 @@ pub struct Log { #[async_trait] impl ContainerFactory for KuasarFactory { - #[instrument(skip(self))] + #[instrument(skip_all)] async fn create( &self, ns: &str, @@ -181,7 +181,7 @@ impl ContainerFactory for KuasarFactory { Ok(container) } - #[instrument(skip(self, c))] + #[instrument(skip_all)] async fn cleanup(&self, _ns: &str, c: &KuasarContainer) -> containerd_shim::Result<()> { self.sandbox.lock().await.defer_storages(&c.id).await?; Ok(())