Skip to content
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

dragonball: add tracing feature for dragonball #7831

Merged
merged 1 commit into from Oct 30, 2023

Conversation

lisongqian
Copy link
Contributor

This PR add tracing feature for dragonball.

Fixes: #7249

Signed-off-by: lisongqian mail@lisongqian.cn

@katacontainersbot katacontainersbot added the size/huge Largest and most complex task (probably needs breaking into small pieces) label Sep 4, 2023
@katacontainersbot
Copy link
Contributor

Can one of the admins verify this patch?

@lisongqian lisongqian force-pushed the feat/dragonball_trace branch 2 times, most recently from 5bb62da to 75501b4 Compare September 5, 2023 07:49
tracing = "0.1.37"
tracing-opentelemetry = "0.18.0"
opentelemetry = { version = "0.18.0", features = [ "trace", "rt-tokio"] }
opentelemetry-jaeger = { version = "0.17.0", features = ["rt-tokio", "hyper_collector_client", "collector_client","rt-tokio-current-thread"] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a space after ','

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

impl std::fmt::Debug for EventManager {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("EventManager")
.field("epoll_mgr", &self.epoll_mgr.type_id())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to get the type_id of epoll mgr?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary, fixed.

pub enum DragonballTraceError {
/// verify jaeger config failed.
#[error("config verify failed: {0}")]
ConfigVerifyFailed(anyhow::Error),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add #source to expand the error stack, and we shouldn't use anyhow in dragonball

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

fn eq(&self, other: &Self) -> bool {
if self.sid == other.sid
&& self.jaeger_endpoint == other.jaeger_endpoint
&& self.jaeger_user == other.jaeger_user
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.sid == other.sid
            && self.jaeger_endpoint == other.jaeger_endpoint
            && self.jaeger_user == other.jaeger_user
            && self.jaeger_password == other.jaeger_password

is enough

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
}

impl Eq for TraceConfigInfo {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use derive

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will encounter a compile error: the trait std::cmp::Eq is not implemented for (dyn tracing::Subscriber + Send + Sync + 'static)

.with_password(config.jaeger_password)
.with_hyper()
.install_batch(opentelemetry::runtime::Tokio)
.expect("Tracer: create jaeger tracer err");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return error instead of expect

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is running in the closure of block_on function, we can't process the error outside the closure. I add a comment here.


/// tracing feature for app.
pub fn setup_tracing(&mut self, config: TraceConfigInfo) -> Result<(), DragonballTraceError> {
if !self.enable_tracing {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if self.enable_tracing {return Ok(())}

xxx

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


#[cfg(test)]
mod tests {
use opentelemetry::global;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clear up use statement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

return v.stop(EXIT_CODE_OK as i32);
let ret = v.stop(EXIT_CODE_OK as i32);
let tracer_mutex = service.tracer();
let mut tracer = tracer_mutex.lock().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tracer_gruad

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -194,6 +203,17 @@ impl Vmm {
}
}

impl std::fmt::Debug for Vmm {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why you need implement debug for vmm?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's needed for macro instrument. The instrument collects the arguments of function and outputs them to tracing info.

@lisongqian lisongqian force-pushed the feat/dragonball_trace branch 2 times, most recently from 2be3729 to 76717af Compare September 19, 2023 05:02
@katacontainersbot katacontainersbot added size/large Task of significant size and removed size/huge Largest and most complex task (probably needs breaking into small pieces) labels Sep 26, 2023
@katacontainersbot katacontainersbot added size/huge Largest and most complex task (probably needs breaking into small pieces) and removed size/large Task of significant size labels Oct 13, 2023
@lisongqian lisongqian force-pushed the feat/dragonball_trace branch 3 times, most recently from 1b2c56a to 72141bb Compare October 17, 2023 15:37
tracer
.setup_tracing(trace_info)
.map(|_| VmmData::Empty)
.map_err(|_| VmmActionError::TracingFailed)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't discard inner errors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

tracer
.end_tracing()
.map(|_| VmmData::Empty)
.map_err(|_| VmmActionError::TracingFailed)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't discard inner errors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -760,6 +817,16 @@ impl VmmService {
}
}

impl std::fmt::Debug for VmmService {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lesson learned. I use it for TraceInfo. But I delete the Debug trait for VmmService since we don't need to output the information of VmmService in tracing.

}
}

impl Eq for TraceInfo {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use derive directly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it with derivative.

}
}

impl PartialEq for TraceInfo {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to implement PartialEq

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TraceInfo is used in VmmAction::SetHypervisorTracing(TraceInfo) and VmmAction implements the PartialEq. This is also the reason why I added the sid field to TraceInfo.

src/dragonball/src/tracer.rs Outdated Show resolved Hide resolved

/// Return whether the tracing is enabled, enabled by [`setup_tracing`]
pub fn enabled(&self) -> bool {
self.tracing_on
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just name this field to enabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

src/dragonball/src/vmm.rs Outdated Show resolved Hide resolved
src/dragonball/src/vmm.rs Outdated Show resolved Hide resolved
@lisongqian lisongqian force-pushed the feat/dragonball_trace branch 4 times, most recently from c9a67fc to 7e5a3a9 Compare October 25, 2023 07:48
Copy link
Contributor

@ZizhengBian ZizhengBian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@studychao
Copy link
Member

/test

Copy link
Member

@studychao studychao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommand that you write a document for how to use the trace functionality under /src/dragonball/docs including how to use and how runtime-rs could use the tracing data from dragonball.
You could choose to do that in another PR.

Copy link
Member

@studychao studychao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, a few comments

src/dragonball/src/api/v1/vmm_action.rs Outdated Show resolved Hide resolved
src/dragonball/src/api/v1/vmm_action.rs Show resolved Hide resolved
src/dragonball/src/tracer.rs Show resolved Hide resolved
}

#[test]
fn test_tracing_in_lib() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that more like a integration test instead of unit test?
Will that be too much to create a JAEGER service every time we run unit test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is more like an example and I have removed it. Actually, opentelemetry_jaeger just creates a request to export the tracing info to JAEGER.

src/dragonball/src/vmm.rs Show resolved Hide resolved
@studychao
Copy link
Member

studychao commented Oct 28, 2023

Besides, did you see how runtime-rs code and have a plan that how could they use your new two actions?

@lisongqian
Copy link
Contributor Author

Besides, did you see how runtime-rs code and have a plan that how could they use your new two actions?↳

Yes, I saw. I will new a PR to support dragonball tracing for runtime-rs after this PR is merged.

@lisongqian
Copy link
Contributor Author

I recommand that you write a document for how to use the trace functionality under /src/dragonball/docs including how to use and how runtime-rs could use the tracing data from dragonball. You could choose to do that in another PR.↳

I will support the dargonball tracing for dbs-cli after this PR is merged. I can write a document and use the implementation of dbs-cli as an example.

This PR adds the tracing capability for dragonball and it depends on the tracing::Subscriber of the upper layer.

Fixes: kata-containers#7249

Signed-off-by: Songqian Li <mail@lisongqian.cn>
@katacontainersbot katacontainersbot added size/large Task of significant size and removed size/huge Largest and most complex task (probably needs breaking into small pieces) labels Oct 28, 2023
Copy link
Member

@studychao studychao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, also I think that jaeger example could put into dbs-cli if that makes sense.

@studychao
Copy link
Member

/test

@studychao studychao merged commit 7d26604 into kata-containers:main Oct 30, 2023
146 of 153 checks passed
@lisongqian lisongqian deleted the feat/dragonball_trace branch November 7, 2023 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dragonball: add tracing feature for dragonball
5 participants