-
Notifications
You must be signed in to change notification settings - Fork 103
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
lib: Add --verbose flag to the CLI for providing a debug output option #1154
base: main
Are you sure you want to change the base?
Conversation
I am checking the failure messages |
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.
Thank you so much for working on this!!
utils/src/tracing_util.rs
Outdated
eprintln!("Failed to update log level: {}", e); | ||
} | ||
} else { | ||
eprintln!("Logging system not initialized yet."); |
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 this should probably be fatal?
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 catch again! How about now?
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 will also add a unit test for it.
#![allow(unsafe_code)] | ||
|
||
use bootc_utils::{initialize_tracing, update_tracing_log_level}; | ||
use nix::unistd::{close, dup, dup2, pipe}; |
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 know we already have nix
in our dependency graph, but I personally prefer rustix
and it's much more widely used in this codebase.
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 don't have a personal preference TBH. Let me check Rustix and implement it instead.
|
||
// Read from the pipe | ||
let mut buffer = String::new(); | ||
// File::from_raw_fd() is considered unsafe in Rust, as it takes ownership of a raw file descriptor. |
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.
And specifically note that rustix's pipe
API is already returning OwnedFd
https://docs.rs/rustix/latest/rustix/pipe/fn.pipe.html which handles this.
lib/src/cli.rs
Outdated
/// Helper function to initialize tracing for tests | ||
fn init_tracing_for_tests() { | ||
INIT.call_once(|| { | ||
std::env::remove_var("RUST_LOG"); |
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.
In 2024 edition this is going to be fully unsafe
, see https://doc.rust-lang.org/edition-guide/rust-2024/newly-unsafe-functions.html#stdenvset_var-remove_var
And yeah...even though we're running this under a mutex, cargo is still going to run other tests in threads and so it is just unsafe.
Actually this comment relates to this whole topic - first, thank you for going to the effort of writing tests for the tracing code! (I honestly might have taken a patch without it with just some manual testing)
But I think to test this correctly we're going to need to fork off a helper process.
That said...there is also https://nexte.st/ and see specifically https://nexte.st/docs/design/why-process-per-test/ - we could investigate setting that up here and using it in CI, but skipping these tests when run directly via cargo test
perhaps?
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.
Got your point. How about this new proposal:
1- Remove the test_update_tracing_respects_rust_log
as it is related to environment setting and cleanup. So that we wont hit the future unsafe issues.
2- Keep the other test functions here as keeping extra tests at unit level wont hurt.
3- Implement similar scenarios and more with the ENV ones at the place where you suggested. BUt I need to look at this first. I don't know much about https://nexte.st yet:) Let me figure it out how to run etc. I am familiar with GH actions.
.gitignore
Outdated
@@ -5,3 +5,6 @@ bootc.tar.zst | |||
|
|||
# Added by cargo | |||
/target | |||
|
|||
# IDEs / Editors | |||
.idea/ |
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.
minor nit: let's add a trailing newline here
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 catch! Done.
pub(crate) struct GlobalArgs { | ||
/// Increase logging verbosity | ||
#[arg(short = 'v', long = "verbose", action = clap::ArgAction::Count, global = true)] | ||
pub(crate) verbose: u8, // Custom verbosity, counts occurrences of -v |
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 this is probably OK as is, but...some bits of code here log quite a bit at debug
level (especially when fetching containers). I wonder if we should also have a --log-level
argument that is just the same as setting the RUST_LOG
env var? Because then it's easier to do e.g. --log-level=bootc=debug
which avoids debug logging from tokio or containers-image-proxy-rs say.
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.
Makes a lot sense. We actually have a log level here but I think you want it to be configurable per component. -v
is common amongst system-wise CLIs but I need to check how a flag like --log-level
is used around. Depending on my research I might propose doing this in another PR, for the sake of separation of concerns:)
f693a14
to
a3cfdf7
Compare
Signed-off-by: mabulgu <[email protected]>
…m in the current scope Signed-off-by: mabulgu <[email protected]>
…hanges the log level Signed-off-by: mabulgu <[email protected]>
Signed-off-by: mabulgu <[email protected]>
Signed-off-by: mabulgu <[email protected]>
Signed-off-by: mabulgu <[email protected]>
Also removed the test case for RUST_LOG as we will cover it via a highler level test Signed-off-by: mabulgu <[email protected]>
Description
This PR adds a
--verbose
flag with the short forms-v
,-vv
,-vvv
.. to increase the logging verbosity as requested in #475.With this PR, the current command structure looks as follows:
The
verbose
flag is matched to different levels of tracing levels fromWARN
toTRACE
:So any user can change the tracing level at runtime by adding the flag and changing its count. In the following
bootc switch
example,-vvv
is used forTRACING
and sub level logs:Users still can use
RUST_LOG
as they used to. Usage ofRUST_LOG
overrides the--verbose
flag if used. So even if you run your command with a-vv
level, if you set your RUST_LOG asinfo
, you will only see theINFO
andWARN
logs, not theDEBUG
ones. This case is provided with a unit test here.Test Results
Unit tests (tracing only is shown here):
Container tests:
Closes: #475