From b47ec16f1698b6eaec538614703e32489b1e62b9 Mon Sep 17 00:00:00 2001 From: "Jiaxiao (mossaka) Zhou" Date: Thu, 30 Jan 2025 07:37:19 +0000 Subject: [PATCH] feat(otel): Only keep the Instance and Task server functions on 'Info' Signed-off-by: Jiaxiao (mossaka) Zhou --- .../src/sandbox/containerd/client.rs | 26 +++++++++---------- .../src/sandbox/instance_utils.rs | 2 +- .../src/sandbox/shim/instance_data.rs | 16 ++++++------ .../src/sandbox/shim/local.rs | 24 ++++++++--------- .../src/sandbox/shim/task_state.rs | 10 +++---- .../src/sys/unix/container/executor.rs | 4 +-- .../src/sys/unix/metrics.rs | 2 +- .../containerd-shim-wasmtime/src/instance.rs | 6 ++--- 8 files changed, 45 insertions(+), 45 deletions(-) diff --git a/crates/containerd-shim-wasm/src/sandbox/containerd/client.rs b/crates/containerd-shim-wasm/src/sandbox/containerd/client.rs index 2f7772b64..af0242f15 100644 --- a/crates/containerd-shim-wasm/src/sandbox/containerd/client.rs +++ b/crates/containerd-shim-wasm/src/sandbox/containerd/client.rs @@ -57,7 +57,7 @@ impl WriteContent { // sync wrapper implementation from https://tokio.rs/tokio/topics/bridging impl Client { // wrapper around connection that will establish a connection and create a client - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] pub async fn connect( address: impl AsRef, namespace: impl Into, @@ -73,7 +73,7 @@ impl Client { } // wrapper around read that will read the entire content file - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] async fn read_content(&self, digest: impl ToString) -> Result> { let req = ReadContentRequest { digest: digest.to_string(), @@ -93,7 +93,7 @@ impl Client { // used in tests to clean up content #[allow(dead_code)] - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] async fn delete_content(&self, digest: impl ToString) -> Result<()> { let req = DeleteContentRequest { digest: digest.to_string(), @@ -107,7 +107,7 @@ impl Client { } // wrapper around lease that will create a lease and return a guard that will delete the lease when dropped - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] async fn lease(&self, reference: String) -> Result { let mut lease_labels = HashMap::new(); // Unwrap is safe here since 24 hours is a valid time @@ -136,7 +136,7 @@ impl Client { )) } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] async fn save_content( &self, data: Vec, @@ -258,7 +258,7 @@ impl Client { Ok(WriteContent { lease, digest }) } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] async fn get_info(&self, content_digest: &Digest) -> Result { let req = InfoRequest { digest: content_digest.to_string(), @@ -276,7 +276,7 @@ impl Client { Ok(info) } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] async fn update_info(&self, info: Info) -> Result { let mut req = UpdateRequest { info: Some(info.clone()), @@ -299,7 +299,7 @@ impl Client { Ok(info) } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] async fn get_image(&self, image_name: impl ToString) -> Result { let name = image_name.to_string(); let req = GetImageRequest { name }; @@ -319,7 +319,7 @@ impl Client { Ok(image) } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] fn extract_image_content_sha(&self, image: &Image) -> Result { let digest = image .target @@ -335,7 +335,7 @@ impl Client { Ok(digest) } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] async fn get_container(&self, container_name: impl ToString) -> Result { let id = container_name.to_string(); let req = GetContainerRequest { id }; @@ -355,7 +355,7 @@ impl Client { Ok(container) } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] async fn get_image_manifest_and_digest( &self, image_name: &str, @@ -370,7 +370,7 @@ impl Client { // load module will query the containerd store to find an image that has an OS of type 'wasm' // If found it continues to parse the manifest and return the layers that contains the WASM modules // and possibly other configuration layers. - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] pub async fn load_modules( &self, containerd_id: impl ToString, @@ -508,7 +508,7 @@ impl Client { Ok((layers, platform)) } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] async fn read_wasm_layer( &self, original_config: &oci_spec::image::Descriptor, diff --git a/crates/containerd-shim-wasm/src/sandbox/instance_utils.rs b/crates/containerd-shim-wasm/src/sandbox/instance_utils.rs index 824272c40..12fa2cae3 100644 --- a/crates/containerd-shim-wasm/src/sandbox/instance_utils.rs +++ b/crates/containerd-shim-wasm/src/sandbox/instance_utils.rs @@ -12,7 +12,7 @@ struct Options { root: Option, } -#[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] +#[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] pub fn determine_rootdir( bundle: impl AsRef, namespace: &str, diff --git a/crates/containerd-shim-wasm/src/sandbox/shim/instance_data.rs b/crates/containerd-shim-wasm/src/sandbox/shim/instance_data.rs index 8b19cda6e..338424491 100644 --- a/crates/containerd-shim-wasm/src/sandbox/shim/instance_data.rs +++ b/crates/containerd-shim-wasm/src/sandbox/shim/instance_data.rs @@ -14,7 +14,7 @@ pub(super) struct InstanceData { } impl InstanceData { - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] pub fn new(id: impl AsRef, cfg: InstanceConfig) -> Result { let id = id.as_ref().to_string(); let instance = T::new(id, &cfg)?; @@ -26,17 +26,17 @@ impl InstanceData { }) } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] pub fn pid(&self) -> Option { self.pid.get().copied() } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] pub fn config(&self) -> &InstanceConfig { &self.cfg } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] pub fn start(&self) -> Result { let mut s = self.state.write().unwrap(); s.start()?; @@ -56,7 +56,7 @@ impl InstanceData { res } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] pub fn kill(&self, signal: u32) -> Result<()> { let mut s = self.state.write().unwrap(); s.kill()?; @@ -64,7 +64,7 @@ impl InstanceData { self.instance.kill(signal) } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] pub fn delete(&self) -> Result<()> { let mut s = self.state.write().unwrap(); s.delete()?; @@ -79,7 +79,7 @@ impl InstanceData { res } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] pub fn wait(&self) -> (u32, DateTime) { let res = self.instance.wait(); let mut s = self.state.write().unwrap(); @@ -87,7 +87,7 @@ impl InstanceData { res } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] pub fn wait_timeout(&self, t: impl Into>) -> Option<(u32, DateTime)> { let res = self.instance.wait_timeout(t); if res.is_some() { diff --git a/crates/containerd-shim-wasm/src/sandbox/shim/local.rs b/crates/containerd-shim-wasm/src/sandbox/shim/local.rs index 75b5599ca..5b6043c08 100644 --- a/crates/containerd-shim-wasm/src/sandbox/shim/local.rs +++ b/crates/containerd-shim-wasm/src/sandbox/shim/local.rs @@ -47,7 +47,7 @@ pub struct Local impl Local { /// Creates a new local task service. - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] pub fn new( engine: T::Engine, events: E, @@ -68,23 +68,23 @@ impl Local { } } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] pub(super) fn get_instance(&self, id: &str) -> Result>> { let instance = self.instances.read().unwrap().get(id).cloned(); instance.ok_or_else(|| Error::NotFound(id.to_string())) } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] fn has_instance(&self, id: &str) -> bool { self.instances.read().unwrap().contains_key(id) } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] fn is_empty(&self) -> bool { self.instances.read().unwrap().is_empty() } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] fn instance_config(&self) -> InstanceConfig { InstanceConfig::new(&self.namespace, &self.containerd_address) } @@ -92,7 +92,7 @@ impl Local { // These are the same functions as in Task, but without the TtrcpContext, which is useful for testing impl Local { - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] fn task_create(&self, req: CreateTaskRequest) -> Result { if !req.checkpoint().is_empty() || !req.parent_checkpoint().is_empty() { return Err(ShimError::Unimplemented("checkpoint is not supported".to_string()).into()); @@ -178,7 +178,7 @@ impl Local { }) } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] fn task_start(&self, req: StartRequest) -> Result { if req.exec_id().is_empty().not() { return Err(ShimError::Unimplemented("exec is not supported".to_string()).into()); @@ -221,7 +221,7 @@ impl Local { }) } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] fn task_kill(&self, req: KillRequest) -> Result { if !req.exec_id().is_empty() { return Err(Error::InvalidArgument("exec is not supported".to_string())); @@ -230,7 +230,7 @@ impl Local { Ok(Empty::new()) } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] fn task_delete(&self, req: DeleteRequest) -> Result { if !req.exec_id().is_empty() { return Err(Error::InvalidArgument("exec is not supported".to_string())); @@ -262,7 +262,7 @@ impl Local { }) } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] fn task_wait(&self, req: WaitRequest) -> Result { if !req.exec_id().is_empty() { return Err(Error::InvalidArgument("exec is not supported".to_string())); @@ -279,7 +279,7 @@ impl Local { }) } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] fn task_state(&self, req: StateRequest) -> Result { if !req.exec_id().is_empty() { return Err(Error::InvalidArgument("exec is not supported".to_string())); @@ -311,7 +311,7 @@ impl Local { }) } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] fn task_stats(&self, req: StatsRequest) -> Result { let i = self.get_instance(req.id())?; let pid = i diff --git a/crates/containerd-shim-wasm/src/sandbox/shim/task_state.rs b/crates/containerd-shim-wasm/src/sandbox/shim/task_state.rs index 03e6bbf9f..2da979b76 100644 --- a/crates/containerd-shim-wasm/src/sandbox/shim/task_state.rs +++ b/crates/containerd-shim-wasm/src/sandbox/shim/task_state.rs @@ -11,7 +11,7 @@ pub(super) enum TaskState { } impl TaskState { - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] pub fn start(&mut self) -> Result<()> { *self = match self { Self::Created => Ok(Self::Starting), @@ -20,7 +20,7 @@ impl TaskState { Ok(()) } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] pub fn kill(&mut self) -> Result<()> { *self = match self { Self::Started => Ok(Self::Started), @@ -29,7 +29,7 @@ impl TaskState { Ok(()) } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] pub fn delete(&mut self) -> Result<()> { *self = match self { Self::Created | Self::Exited => Ok(Self::Deleting), @@ -38,7 +38,7 @@ impl TaskState { Ok(()) } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] pub fn started(&mut self) -> Result<()> { *self = match self { Self::Starting => Ok(Self::Started), @@ -47,7 +47,7 @@ impl TaskState { Ok(()) } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] pub fn stop(&mut self) -> Result<()> { *self = match self { Self::Started | Self::Starting => Ok(Self::Exited), diff --git a/crates/containerd-shim-wasm/src/sys/unix/container/executor.rs b/crates/containerd-shim-wasm/src/sys/unix/container/executor.rs index 23326f78f..8e323e78f 100644 --- a/crates/containerd-shim-wasm/src/sys/unix/container/executor.rs +++ b/crates/containerd-shim-wasm/src/sys/unix/container/executor.rs @@ -33,7 +33,7 @@ pub(crate) struct Executor { } impl LibcontainerExecutor for Executor { - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] fn validate(&self, spec: &Spec) -> Result<(), ExecutorValidationError> { // We can handle linux container. We delegate wasm container to the engine. match self.inner(spec) { @@ -42,7 +42,7 @@ impl LibcontainerExecutor for Executor { } } - #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] + #[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] fn exec(&self, spec: &Spec) -> Result<(), LibcontainerExecutorError> { // If it looks like a linux container, run it as a linux container. // Otherwise, run it as a wasm container diff --git a/crates/containerd-shim-wasm/src/sys/unix/metrics.rs b/crates/containerd-shim-wasm/src/sys/unix/metrics.rs index 08a182042..712c7e2d9 100644 --- a/crates/containerd-shim-wasm/src/sys/unix/metrics.rs +++ b/crates/containerd-shim-wasm/src/sys/unix/metrics.rs @@ -3,7 +3,7 @@ use containerd_shim::cgroup::collect_metrics; use containerd_shim::util::convert_to_any; use protobuf::well_known_types::any::Any; -#[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Info"))] +#[cfg_attr(feature = "tracing", tracing::instrument(parent = tracing::Span::current(), skip_all, level = "Debug"))] pub fn get_metrics(pid: u32) -> Result { let metrics = collect_metrics(pid)?; diff --git a/crates/containerd-shim-wasmtime/src/instance.rs b/crates/containerd-shim-wasmtime/src/instance.rs index b81ed8c4f..e5059c844 100644 --- a/crates/containerd-shim-wasmtime/src/instance.rs +++ b/crates/containerd-shim-wasmtime/src/instance.rs @@ -171,7 +171,7 @@ impl Engine for WasmtimeEngine { Some(Module) => PRECOMPILER.precompile_module(&layer.layer)?, Some(Component) => PRECOMPILER.precompile_component(&layer.layer)?, None => { - log::warn!("Unknow WASM binary type"); + log::warn!("Unknown WASM binary type"); continue; } }; @@ -218,12 +218,12 @@ impl WasmtimeEngineImpl { let instance: wasmtime::Instance = module_linker.instantiate_async(&mut store, &module).await?; - log::info!("getting start function"); + log::debug!("getting start function"); let start_func = instance .get_func(&mut store, func) .context("module does not have a WASI start function")?; - log::debug!("running start function {func:?}"); + log::info!("running start function {func:?}"); start_func .call_async(&mut store, &[], &mut [])