Skip to content

Commit

Permalink
feat(otel): Only keep the Instance and Task server functions on 'Info'
Browse files Browse the repository at this point in the history
Signed-off-by: Jiaxiao (mossaka) Zhou <duibao55328@gmail.com>
  • Loading branch information
Mossaka committed Jan 30, 2025
1 parent 7f58e33 commit b47ec16
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 45 deletions.
26 changes: 13 additions & 13 deletions crates/containerd-shim-wasm/src/sandbox/containerd/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path>,
namespace: impl Into<String>,
Expand All @@ -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<Vec<u8>> {
let req = ReadContentRequest {
digest: digest.to_string(),
Expand All @@ -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(),
Expand All @@ -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<LeaseGuard> {
let mut lease_labels = HashMap::new();
// Unwrap is safe here since 24 hours is a valid time
Expand Down Expand Up @@ -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<u8>,
Expand Down Expand Up @@ -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<Info> {
let req = InfoRequest {
digest: content_digest.to_string(),
Expand All @@ -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<Info> {
let mut req = UpdateRequest {
info: Some(info.clone()),
Expand All @@ -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<Image> {
let name = image_name.to_string();
let req = GetImageRequest { name };
Expand All @@ -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<String> {
let digest = image
.target
Expand All @@ -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<Container> {
let id = container_name.to_string();
let req = GetContainerRequest { id };
Expand All @@ -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,
Expand All @@ -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<T: Engine>(
&self,
containerd_id: impl ToString,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/containerd-shim-wasm/src/sandbox/instance_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct Options {
root: Option<PathBuf>,
}

#[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<Path>,
namespace: &str,
Expand Down
16 changes: 8 additions & 8 deletions crates/containerd-shim-wasm/src/sandbox/shim/instance_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub(super) struct InstanceData<T: Instance> {
}

impl<T: Instance> InstanceData<T> {
#[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<str>, cfg: InstanceConfig) -> Result<Self> {
let id = id.as_ref().to_string();
let instance = T::new(id, &cfg)?;
Expand All @@ -26,17 +26,17 @@ impl<T: Instance> InstanceData<T> {
})
}

#[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<u32> {
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<u32> {
let mut s = self.state.write().unwrap();
s.start()?;
Expand All @@ -56,15 +56,15 @@ impl<T: Instance> InstanceData<T> {
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()?;

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()?;
Expand All @@ -79,15 +79,15 @@ impl<T: Instance> InstanceData<T> {
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<Utc>) {
let res = self.instance.wait();
let mut s = self.state.write().unwrap();
*s = TaskState::Exited;
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<Duration>>) -> Option<(u32, DateTime<Utc>)> {
let res = self.instance.wait_timeout(t);
if res.is_some() {
Expand Down
24 changes: 12 additions & 12 deletions crates/containerd-shim-wasm/src/sandbox/shim/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub struct Local<T: Instance + Send + Sync, E: EventSender = RemoteEventSender>

impl<T: Instance + Send + Sync, E: EventSender> Local<T, E> {
/// 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,
Expand All @@ -68,31 +68,31 @@ impl<T: Instance + Send + Sync, E: EventSender> Local<T, E> {
}
}

#[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<Arc<InstanceData<T>>> {
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)
}
}

// These are the same functions as in Task, but without the TtrcpContext, which is useful for testing
impl<T: Instance + Send + Sync, E: EventSender> Local<T, E> {
#[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<CreateTaskResponse> {
if !req.checkpoint().is_empty() || !req.parent_checkpoint().is_empty() {
return Err(ShimError::Unimplemented("checkpoint is not supported".to_string()).into());
Expand Down Expand Up @@ -178,7 +178,7 @@ impl<T: Instance + Send + Sync, E: EventSender> Local<T, E> {
})
}

#[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<StartResponse> {
if req.exec_id().is_empty().not() {
return Err(ShimError::Unimplemented("exec is not supported".to_string()).into());
Expand Down Expand Up @@ -221,7 +221,7 @@ impl<T: Instance + Send + Sync, E: EventSender> Local<T, E> {
})
}

#[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<Empty> {
if !req.exec_id().is_empty() {
return Err(Error::InvalidArgument("exec is not supported".to_string()));
Expand All @@ -230,7 +230,7 @@ impl<T: Instance + Send + Sync, E: EventSender> Local<T, E> {
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<DeleteResponse> {
if !req.exec_id().is_empty() {
return Err(Error::InvalidArgument("exec is not supported".to_string()));
Expand Down Expand Up @@ -262,7 +262,7 @@ impl<T: Instance + Send + Sync, E: EventSender> Local<T, E> {
})
}

#[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<WaitResponse> {
if !req.exec_id().is_empty() {
return Err(Error::InvalidArgument("exec is not supported".to_string()));
Expand All @@ -279,7 +279,7 @@ impl<T: Instance + Send + Sync, E: EventSender> Local<T, E> {
})
}

#[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<StateResponse> {
if !req.exec_id().is_empty() {
return Err(Error::InvalidArgument("exec is not supported".to_string()));
Expand Down Expand Up @@ -311,7 +311,7 @@ impl<T: Instance + Send + Sync, E: EventSender> Local<T, E> {
})
}

#[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<StatsResponse> {
let i = self.get_instance(req.id())?;
let pid = i
Expand Down
10 changes: 5 additions & 5 deletions crates/containerd-shim-wasm/src/sandbox/shim/task_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub(crate) struct Executor<E: Engine> {
}

impl<E: Engine> LibcontainerExecutor for Executor<E> {
#[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) {
Expand All @@ -42,7 +42,7 @@ impl<E: Engine> LibcontainerExecutor for Executor<E> {
}
}

#[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
Expand Down
2 changes: 1 addition & 1 deletion crates/containerd-shim-wasm/src/sys/unix/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Any> {
let metrics = collect_metrics(pid)?;

Expand Down
Loading

0 comments on commit b47ec16

Please sign in to comment.