Skip to content

Tracing filter #3971

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 84 additions & 12 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions src/api_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ mmds = { path = "../mmds" }
seccompiler = { path = "../seccompiler" }
utils = { path = "../utils" }
vmm = { path = "../vmm" }
tracing = { version = "0.1.37", default-features = false }

[dev-dependencies]
libc = "0.2.117"
log = "0.4.19"
4 changes: 2 additions & 2 deletions src/api_server/src/parsed_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use std::fmt::Debug;

use logger::{error, info, log_enabled, Level};
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to hide tracing::{error,info,...} behind logging::{error,info,...}. What I am thinking is that, if we do that, we will not be hardly dependant on tracing crate everywhere. That way, if we ever decide that we want to use something else, other than tracing we won't have to make changes everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

logging::error used to re-export log::error (e.g. pub use log::error;). We could also re-export tracing::error but I don't like this, I find re-exports add complexity and reduce readability.

I understand your point if we wanted to change away from tracing but I don't think it's valuable for this PR to be designed considering it may be reverted.

I think using tracing::error (etc.) is the simplest and best approach (I think if we avoid this with wrapping here, the same point could be argued in many cases and not be useful).

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have a super strong opinion here, but I do not understand how re-exporting adds complexity or reduces readability. Re-exporting just renames something. Also, it removes the need to "polute" Cargo.toml with both logger and tracing.

I think it's worth getting more opinions here

Copy link
Contributor

Choose a reason for hiding this comment

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

Mh, I can see a few (weak) arguments for re-exporting

  • It would prevent us from having to add tracing as a dependency to a bunch of Cargo.toml files (however we're in the process of merging all crates, so this will resolve itself either way)
  • The diff for this commit wouldn't include changes of the type log::error! -> tracing::error (however we dont tend to fully qualify our logging calls, instead mostly opting for importing the macros at the top of the file).

Overall I think reexporting would be nicer (diff would be a bit smaller, and we avoid having to specify the dependency a ton of times), but I also don't have a strong opinion.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am in favor of reexporting. Makes simpler imports + less dependency declarations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated it to maintain the same re-exporting pattern.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I didn't get it. Do you mean you don't want to use re-export? (The first commit is not re-exporting, just replacing use log::* with use tracing::* everywhere

use logger::{error, info, Level};
use micro_http::{Body, Method, Request, Response, StatusCode, Version};
use serde::ser::Serialize;
use serde_json::Value;
Expand Down Expand Up @@ -232,7 +232,7 @@ fn describe(method: Method, path: &str, body: Option<&Body>) -> String {
("/cpu-config", Some(payload_value)) => {
// If the log level is at Debug or higher, include the CPU template in
// the log line.
if log_enabled!(Level::Debug) {
if tracing::enabled!(Level::DEBUG) {
describe_with_body(method, path, payload_value)
} else {
format!(
Expand Down
20 changes: 11 additions & 9 deletions src/api_server/src/request/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(crate) fn parse_put_logger(body: &Body) -> Result<ParsedRequest, Error> {
mod tests {
use std::path::PathBuf;

use vmm::vmm_config::logger::LoggerLevel;
use vmm::vmm_config::logger::LevelFilter;

use super::*;
use crate::parsed_request::tests::vmm_action_from_request;
Expand All @@ -37,10 +37,11 @@ mod tests {
}"#;

let mut expected_cfg = LoggerConfig {
log_path: PathBuf::from("log"),
level: LoggerLevel::Warning,
show_level: false,
show_log_origin: false,
log_path: Some(PathBuf::from("log")),
level: Some(LevelFilter::Warn),
show_level: Some(false),
show_log_origin: Some(false),
filter: None,
};
match vmm_action_from_request(parse_put_logger(&Body::new(body)).unwrap()) {
VmmAction::ConfigureLogger(cfg) => assert_eq!(cfg, expected_cfg),
Expand All @@ -55,10 +56,11 @@ mod tests {
}"#;

expected_cfg = LoggerConfig {
log_path: PathBuf::from("log"),
level: LoggerLevel::Debug,
show_level: false,
show_log_origin: false,
log_path: Some(PathBuf::from("log")),
level: Some(LevelFilter::Debug),
show_level: Some(false),
show_log_origin: Some(false),
filter: None,
};
match vmm_action_from_request(parse_put_logger(&Body::new(body)).unwrap()) {
VmmAction::ConfigureLogger(cfg) => assert_eq!(cfg, expected_cfg),
Expand Down
1 change: 1 addition & 0 deletions src/cpu-template-helper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ libc = "0.2.147"
serde = { version = "1.0.183", features = ["derive"] }
serde_json = "1.0.104"
thiserror = "1.0.44"
tracing = { version = "0.1.37", default-features = false }

vmm = { path = "../vmm" }

Expand Down
1 change: 1 addition & 0 deletions src/dumbo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ bench = false
[dependencies]
bitflags = "1.3.2"
derive_more = { version = "0.99.17", default-features = false, features = ["from"] }
tracing = { version = "0.1.37", default-features = false }

logger = { path = "../logger" }
micro_http = { git = "https://github.com/firecracker-microvm/micro-http", rev = "4b18a04" }
Expand Down
3 changes: 3 additions & 0 deletions src/firecracker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ bench = false
[dependencies]
event-manager = "0.3.0"
libc = "0.2.147"
log = "0.4.19"
serde_json = "1.0.104"
thiserror = "1.0.44"
timerfd = "1.5.0"
tracing = { version = "0.1.37", default-features = false }
tracing-subscriber = { version = "0.3.17", default-features = false, features = ["fmt"] }

api_server = { path = "../api_server" }
logger = { path = "../logger" }
Expand Down
Loading