-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vmm: imporve observability to vmm-task & vmm-sandboxer #146
Conversation
c7bb961
to
7171a71
Compare
cc @Burning1020 |
5a8ef7b
to
ac3d462
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job! /cc @abel-von @flyflypeng
Could you add a markdown to give more detail usages and results?
Another question, after switching from log to tracing, what changes occurred in the format and amount of log output? Was there a comparison?
let env_filter = init_logger_filter(&args.log_level.unwrap_or(config.sandbox.log_level())) | ||
.expect("failed to init logger filter"); | ||
|
||
let mut layers = vec![tracing_subscriber::fmt::layer().boxed()]; | ||
if config.sandbox.enable_tracing { | ||
let tracer = init_otlp_tracer("kuasar-vmm-sandboxer-clh-tracing-service") | ||
.expect("failed to init otlp tracer"); | ||
layers.push(tracing_opentelemetry::layer().with_tracer(tracer).boxed()); | ||
} | ||
|
||
let subscriber = Registry::default().with(env_filter).with(layers); | ||
tracing::subscriber::set_global_default(subscriber).expect("unable to set global subscriber"); | ||
|
||
let root_span = info_span!("kuasar-vmm-sandboxer-clh-root").entered(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you extra L44-54 in a common function and give sandboxers different service name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Maybe service name could be also configured by toml else use it default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it’s better if the name isn’t configurable.
There are slight differences in the log format (brackets & colons): env_logger::Builder::from_default_env()
.format_timestamp_micros()
.init();
log::error!("hello world from env_logger"); // [2024-09-21T04:02:26.007041Z ERROR log_test] Hello from env_logger
tracing::error!("hello world from tracing"); // 2024-09-21T04:02:05.022320Z ERROR log_test: Hello from tracing |
7466936
to
85664b5
Compare
tracer::setup_tracing( | ||
&args.log_level.unwrap_or(config.sandbox.log_level()), | ||
enable_tracing, | ||
"kuasar-vmm-sandboxer-clh-otlp-service", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use kuasar-vmm-sandboxer-clh
, as "oltp" is not the key info
vmm/sandbox/src/stratovirt/hooks.rs
Outdated
@@ -47,4 +52,11 @@ impl Hooks<StratoVirtVM> for StratoVirtHooks { | |||
sandbox.sync_clock().await; | |||
Ok(()) | |||
} | |||
|
|||
async fn post_stop(&self, _sandbox: &mut KuasarSandbox<StratoVirtVM>) -> Result<()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
post_stop
was called every time before the sandbox stopped, so it's not appropriate call it here.
To make it easy, how about not positive stopping tracing, stopping it with the whole process exits?
vmm/task/src/main.rs
Outdated
if config.enable_tracing { | ||
tracer::shutdown_tracing(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The task process also stopped tracing when it exited.
1014996
to
78276ac
Compare
vmm/common/src/tracer.rs
Outdated
ENABLED.load(Ordering::Relaxed) | ||
} | ||
|
||
// 设置 ENABLED 的值 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please translate it to English
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
vmm/common/src/tracer.rs
Outdated
if enable_tracing { | ||
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 { | ||
layers.push( | ||
tracing_opentelemetry::layer() | ||
.with_tracer(NoopTracer::new()) | ||
.boxed(), | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let tracer = if enable_tracing {
init_otlp_tracer(otlp_service_name)
.map_err(|e| anyhow!("failed to init otlp tracer: {}", e))?
} else {
NoopTracer::new()
};
layers.push(tracing_opentelemetry::layer().with_tracer(tracer).boxed());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tracing_opentelemetry::layer()
will be added only when enable_tracing = true
now.
vmm/common/src/tracer.rs
Outdated
SIGINT | SIGTERM => { | ||
info!("Received signal {}, stopping tracing and exiting...", sig); | ||
shutdown_tracing(); | ||
std::process::exit(0); | ||
} | ||
_ => { | ||
if let Ok(sig) = nix::sys::signal::Signal::try_from(sig) { | ||
debug!("received {}", sig); | ||
} else { | ||
warn!("received invalid signal {}", sig); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think only signal SIGUSR1
should be handled, and the others should be kept same as before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
let log_level = args.log_level.unwrap_or(config.sandbox.log_level()); | ||
let service_name = "kuasar-vmm-sandboxer-clh-service"; | ||
tracer::setup_tracing(&log_level, enable_tracing, service_name).unwrap(); | ||
tracer::set_enabled(enable_tracing); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ENABLED: AtomicBool
static variable is the only one to detiminate, so it's better to:
...
tracer::set_enabled(config.sandbox.enable_tracing);
tracer::setup_tracing(&log_level, service_name).unwrap();
and let setup_tracing()
read ENABLED
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
vmm/common/src/tracer.rs
Outdated
global::shutdown_tracer_provider(); | ||
} | ||
|
||
pub async fn handle_signals(log_level: &str, otlp_service_name: &str) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handle_signal()
is used to handle all signals of the current process, so this function should not in the tracer.rs
file(e.g. signal.rs
), it is a more common funtion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks
Please squash your commits. @Ziy1-Tan |
Signed-off-by: Ziy1-Tan <ajb459684460@gmail.com>
closes #5
kuasar/vmm/sandbox/src/sandbox.rs
Line 342 in 08cfdc8
Main Changes
env_logger
with cratetracing
;#[instrument]
for Sandbox and Container API;Steps
Run the Kuasar: https://github.com/kuasar-io/kuasar#quick-start
Check the result: visit the web page http://localhost:16686/
Instrumentation Scope
The following API will be instrumented: