Skip to content

Commit

Permalink
instrument skip all
Browse files Browse the repository at this point in the history
Signed-off-by: Ziy1-Tan <[email protected]>
  • Loading branch information
Ziy1-Tan committed Sep 8, 2024
1 parent 91da3f9 commit 08cfdc8
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 47 deletions.
5 changes: 4 additions & 1 deletion vmm/sandbox/src/bin/qemu/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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",
Expand All @@ -87,6 +88,8 @@ async fn main() {
.await
.unwrap();

info!("Kuasar vmm sandboxer clh is exited");

root_span.exit();
global::shutdown_tracer_provider();
}
5 changes: 4 additions & 1 deletion vmm/sandbox/src/bin/stratovirt/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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",
Expand All @@ -75,6 +76,8 @@ async fn main() {
.await
.unwrap();

info!("Kuasar vmm sandboxer stratovirt is exited");

root_span.exit();
global::shutdown_tracer_provider();
}
22 changes: 11 additions & 11 deletions vmm/sandbox/src/cloud_hypervisor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl CloudHypervisorVM {

#[async_trait]
impl VM for CloudHypervisorVM {
#[instrument(skip(self))]
#[instrument(skip_all)]
async fn start(&mut self) -> Result<u32> {
create_dir_all(&self.base_dir).await?;
let virtiofsd_pid = self.start_virtiofsd().await?;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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<Receiver<(u32, i128)>> {
self.wait_chan.clone()
}

#[instrument(skip(self))]
#[instrument(skip_all)]
async fn vcpus(&self) -> Result<VcpuThreads> {
// Refer to https://github.com/firecracker-microvm/firecracker/issues/718
Ok(VcpuThreads {
Expand All @@ -335,15 +335,15 @@ impl VM for CloudHypervisorVM {
})
}

#[instrument(skip(self))]
#[instrument(skip_all)]
fn pids(&self) -> Pids {
self.pids.clone()
}
}

#[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()?;
Expand Down
62 changes: 30 additions & 32 deletions vmm/sandbox/src/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -84,7 +84,7 @@ where
H: Hooks<F::VM>,
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,
Expand Down Expand Up @@ -155,7 +155,7 @@ where
{
type Sandbox = KuasarSandbox<F::VM>;

#[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()));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -264,7 +264,7 @@ where
Ok(())
}

#[instrument(skip(self))]
#[instrument(skip_all)]
async fn sandbox(&self, id: &str) -> Result<Arc<Mutex<Self::Sandbox>>> {
Ok(self
.sandboxes
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -319,17 +319,17 @@ where
{
type Container = KuasarContainer;

#[instrument(skip(self))]
#[instrument(skip_all)]
fn status(&self) -> Result<SandboxStatus> {
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
Expand All @@ -338,23 +338,23 @@ 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?;
self.dump().await?;
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?;
self.dump().await?;
Ok(())
}

#[instrument(skip(self))]
#[instrument(skip_all)]
async fn remove_container(&mut self, id: &str) -> Result<()> {
self.deference_container_storages(id).await?;

Expand All @@ -378,12 +378,12 @@ where
Ok(())
}

#[instrument(skip(self))]
#[instrument(skip_all)]
async fn exit_signal(&self) -> Result<Arc<ExitSignal>> {
Ok(self.exit_signal.clone())
}

#[instrument(skip(self))]
#[instrument(skip_all)]
fn get_data(&self) -> Result<SandboxData> {
Ok(self.data.clone())
}
Expand All @@ -393,7 +393,7 @@ impl<V> KuasarSandbox<V>
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))?;
Expand All @@ -417,7 +417,7 @@ impl<V> KuasarSandbox<V>
where
V: VM + DeserializeOwned + Recoverable + Sync + Send,
{
#[instrument(skip(base_dir))]
#[instrument(skip_all)]
async fn recover<P: AsRef<Path>>(base_dir: P) -> Result<Self> {
let dump_path = base_dir.as_ref().join("sandbox.json");
let mut dump_file = OpenOptions::new()
Expand Down Expand Up @@ -463,8 +463,7 @@ impl<V> KuasarSandbox<V>
where
V: VM + Sync + Send,
{

#[instrument(skip(self))]
#[instrument(skip_all)]
async fn start(&mut self) -> Result<()> {
let pid = self.vm.start().await?;

Expand All @@ -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:
Expand Down Expand Up @@ -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() {
Expand All @@ -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();

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -676,15 +674,15 @@ 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() {
network.destroy().await;
}
}

#[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() {
Expand Down
Loading

0 comments on commit 08cfdc8

Please sign in to comment.