Skip to content

Commit

Permalink
remove unused features
Browse files Browse the repository at this point in the history
Signed-off-by: Ziy1-Tan <[email protected]>
  • Loading branch information
Ziy1-Tan committed Oct 25, 2024
1 parent 1ce3e44 commit 4f11fb0
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 42 deletions.
2 changes: 1 addition & 1 deletion vmm/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ regex = "1.5.6"

tracing = "0.1.40"
tracing-opentelemetry = "0.21.0"
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "tracing-log"] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }

opentelemetry = { version = "0.20.0", features = ["rt-tokio"] }
opentelemetry-otlp = "0.13.0"
Expand Down
2 changes: 1 addition & 1 deletion vmm/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub mod api;
pub mod mount;
pub mod signal;
pub mod storage;
pub mod tracer;
pub mod trace;

pub const KUASAR_STATE_DIR: &str = "/run/kuasar/state";

Expand Down
6 changes: 3 additions & 3 deletions vmm/common/src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ limitations under the License.
use nix::libc::{SIGINT, SIGTERM, SIGUSR1};
use signal_hook::iterator::Signals;

use crate::tracer::{enabled, set_enabled, setup_tracing};
use crate::trace;

pub async fn handle_signals(log_level: &str, otlp_service_name: &str) {
let mut signals = Signals::new([SIGTERM, SIGINT, SIGUSR1]).expect("new signal failed");

for sig in signals.forever() {
if sig == SIGUSR1 {
set_enabled(!enabled());
let _ = setup_tracing(log_level, otlp_service_name);
trace::set_enabled(!trace::is_enabled());
let _ = trace::setup_tracing(log_level, otlp_service_name);
}
}
}
9 changes: 6 additions & 3 deletions vmm/common/src/tracer.rs → vmm/common/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ lazy_static! {
static ref ENABLED: AtomicBool = AtomicBool::new(false);
}

pub fn enabled() -> bool {
pub fn is_enabled() -> bool {
ENABLED.load(Ordering::Relaxed)
}

Expand All @@ -46,15 +46,18 @@ pub fn setup_tracing(log_level: &str, otlp_service_name: &str) -> anyhow::Result
.map_err(|e| anyhow!("failed to init logger filter: {}", e))?;

let mut layers = vec![tracing_subscriber::fmt::layer().boxed()];
if enabled() {
if is_enabled() {
let tracer = init_otlp_tracer(otlp_service_name)
.map_err(|e| anyhow!("failed to init otlp tracer: {}", e))?;
layers.push(tracing_opentelemetry::layer().with_tracer(tracer).boxed());
} else {
shutdown_tracing();
}

Registry::default().with(env_filter).with(layers).init();
Registry::default()
.with(env_filter)
.with(layers)
.try_init()?;
Ok(())
}

Expand Down
6 changes: 3 additions & 3 deletions vmm/sandbox/src/bin/cloud_hypervisor/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
*/

use clap::Parser;
use vmm_common::{signal, tracer};
use vmm_common::{signal, trace};
use vmm_sandboxer::{
args,
cloud_hypervisor::{factory::CloudHypervisorVMFactory, hooks::CloudHypervisorHooks},
Expand All @@ -37,8 +37,8 @@ async fn main() {
// Update args log level if it not presents args but in config.
let log_level = args.log_level.unwrap_or(config.sandbox.log_level());
let service_name = "kuasar-vmm-sandboxer-clh-service";
tracer::set_enabled(config.sandbox.enable_tracing);
tracer::setup_tracing(&log_level, service_name).unwrap();
trace::set_enabled(config.sandbox.enable_tracing);
trace::setup_tracing(&log_level, service_name).unwrap();

let mut sandboxer: KuasarSandboxer<CloudHypervisorVMFactory, CloudHypervisorHooks> =
KuasarSandboxer::new(
Expand Down
6 changes: 3 additions & 3 deletions vmm/sandbox/src/bin/qemu/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
*/

use clap::Parser;
use vmm_common::{signal, tracer};
use vmm_common::{signal, trace};
use vmm_sandboxer::{
args,
config::Config,
Expand Down Expand Up @@ -53,8 +53,8 @@ async fn main() {

let log_level = config.sandbox.log_level();
let service_name = "kuasar-vmm-sandboxer-qemu-service";
tracer::set_enabled(config.sandbox.enable_tracing);
tracer::setup_tracing(&log_level, service_name).unwrap();
trace::set_enabled(config.sandbox.enable_tracing);
trace::setup_tracing(&log_level, service_name).unwrap();

let sandboxer: KuasarSandboxer<QemuVMFactory, QemuHooks> = KuasarSandboxer::new(
config.sandbox,
Expand Down
6 changes: 3 additions & 3 deletions vmm/sandbox/src/bin/stratovirt/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
*/

use clap::Parser;
use vmm_common::{signal, tracer};
use vmm_common::{signal, trace};
use vmm_sandboxer::{
args,
config::Config,
Expand All @@ -39,8 +39,8 @@ async fn main() {
// Update args log level if it not presents args but in config.
let log_level = config.sandbox.log_level();
let service_name = "kuasar-vmm-sandboxer-stratovirt-service";
tracer::set_enabled(config.sandbox.enable_tracing);
tracer::setup_tracing(&log_level, service_name).unwrap();
trace::set_enabled(config.sandbox.enable_tracing);
trace::setup_tracing(&log_level, service_name).unwrap();

let mut sandboxer: KuasarSandboxer<StratoVirtVMFactory, StratoVirtHooks> = KuasarSandboxer::new(
config.sandbox,
Expand Down
13 changes: 0 additions & 13 deletions vmm/task/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vmm/task/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protobuf = "3.2"

tracing = "0.1.40"
tracing-opentelemetry = "0.21.0"
tracing-subscriber = { version = "0.3.18", features = ["json", "env-filter"] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }

opentelemetry = { version = "0.20.0", features = ["rt-tokio"] }

Expand Down
25 changes: 14 additions & 11 deletions vmm/task/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ use tracing_subscriber::{
use vmm_common::{
api::{sandbox_ttrpc::create_sandbox_service, streaming_ttrpc::create_streaming},
mount::mount,
tracer::{self, init_otlp_tracer},
ETC_RESOLV, IPC_NAMESPACE, KUASAR_STATE_DIR, PID_NAMESPACE, RESOLV_FILENAME, UTS_NAMESPACE,
trace, ETC_RESOLV, IPC_NAMESPACE, KUASAR_STATE_DIR, PID_NAMESPACE, RESOLV_FILENAME,
UTS_NAMESPACE,
};

use crate::{
Expand Down Expand Up @@ -149,7 +149,7 @@ async fn initialize() -> anyhow::Result<TaskConfig> {
early_init_call().await?;

let config = TaskConfig::new().await?;
tracer::set_enabled(config.enable_tracing);
trace::set_enabled(config.enable_tracing);
init_logger(&config.log_level)?;

info!("Task server start with config: {:?}", config);
Expand Down Expand Up @@ -183,15 +183,18 @@ fn init_logger(log_level: &str) -> anyhow::Result<()> {
.add_directive(format!("vmm_task={}", log_level).parse()?);

let mut layers = vec![tracing_subscriber::fmt::layer().boxed()];

if tracer::enabled() {
let tracer = init_otlp_tracer("kuasar-vmm-task-service")
if trace::is_enabled() {
let tracer = trace::init_otlp_tracer("kuasar-vmm-task-service")
.map_err(|e| anyhow!("failed to init otlp tracer: {}", e))?;
layers.push(tracing_opentelemetry::layer().with_tracer(tracer).boxed());
} else {
trace::shutdown_tracing();
}

Registry::default().with(env_filter).with(layers).init();

Registry::default()
.with(env_filter)
.with(layers)
.try_init()?;
Ok(())
}

Expand Down Expand Up @@ -251,8 +254,8 @@ async fn handle_signals(signals: Signals, log_level: &str) {
while let Some(sig) = signals.next().await {
match sig {
libc::SIGTERM | libc::SIGINT => {
tracer::set_enabled(false);
tracer::shutdown_tracing();
trace::set_enabled(false);
trace::shutdown_tracing();
debug!("received {}", sig);
}
libc::SIGCHLD => loop {
Expand Down Expand Up @@ -320,7 +323,7 @@ async fn handle_signals(signals: Signals, log_level: &str) {
}
},
libc::SIGUSR1 => {
tracer::set_enabled(!tracer::enabled());
trace::set_enabled(!trace::is_enabled());
let _ = init_logger(log_level);
}
_ => {
Expand Down

0 comments on commit 4f11fb0

Please sign in to comment.