-
Notifications
You must be signed in to change notification settings - Fork 72
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
Use RUST_LOG env to configure logging if present #247
Conversation
Signed-off-by: James Sturtevant <jstur@microsoft.com>
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.
Love to see this!
fn configure_logging_level(debug: bool, default_log_level: &str) { | ||
let debug_level = std::env::var(LOG_ENV).unwrap_or(default_log_level.to_string()); | ||
let debug_level = log::LevelFilter::from_str(&debug_level).unwrap_or(log::LevelFilter::Info); | ||
let level = if debug && log::LevelFilter::Debug > debug_level { |
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.
Why do you still need this special handling of debug
logic?
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 kept it there so that it was backwards compatible. If a user turns that value on they would expect logs and I didn't want to break that.
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.
Some context about defaults is above, but we may simplify this a bit to:
level = DEFAULT_LOG_LEVEL
if there is an env - parse & set level from env
if debug { level = debug }
(may be output a warning that containerd forced debug mode)
?
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 wasn't sure that we could push out a warning as the logger wasn't fully set up at this point but I can try it
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 reason for if debug && log::LevelFilter::Debug > debug_level
was I wanted to ensure that if the ENV variable was more verbose than debug
that we honor it.
@@ -34,6 +34,8 @@ use crate::error::Error; | |||
#[cfg(windows)] | |||
use crate::sys::windows::NamedPipeLogger; | |||
|
|||
pub const LOG_ENV: &str = "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.
I wonder if we should name the env var to be SHIM_LOG
because this is probably not specific to rust, no?
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.
RUST_LOG
is used by another popular (128m downloads) logging crate - env_logger
to customize log output. We could integrate env_logger with pipes to offer same level of functionality or use other name here to avoid confusion - users might expect same level of customization, which we don't offer.
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 did consider trying to integrate env_logger
initially and can take closer look if we want to add that level of customization or can change the name
pub struct Config { | ||
/// Disables automatic configuration of logrus to use the shim FIFO | ||
pub no_setup_logger: bool, | ||
// Sets the the default log level. Default is info | ||
pub default_log_level: String, |
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.
nit: Is this case sensitive?
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.
from my testing it was not
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.
default_log_level
is a bit confusing to me. We have a default one and env variable to customize it if default doesn't work. Customizing both default value and env log is a bit excessive?
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 was thinking that some shims owners would want to set it different from info
with requiring customization through an Environment variable
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.
but they can use environment variable to customize it, if they don't like default value, right?
Would be curious to learn more about costs of logging to pipe/fifo. |
@radu-matei @lann could you share some of your findings? |
I suspect that the performance issues have more to do with mutex contention in |
I wonder if going this route would be more viable instead of introducing a custom env var? parking_lot's mutex or maintaining a message queue. |
I think it should be both. There is an expectation from users that since they are using |
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
Let's have this one in. We can follow up with further improvements. |
We identified a perf impact when writing logs. In this case it would be helpful to only run with logs set at a "warning" or "error" level. We attempted to turn most logs off via containerd with
containerd -l fatal
but it still dumped logs.After some investigation it appears containerd only sets a flag not a level (https://github.com/containerd/containerd/blob/7467d81987e1a54dd2a89e052ae9429a4c921e9e/core/runtime/v2/binary.go#L66-L68) and our code will default to info
rust-extensions/crates/shim/src/logger.rs
Lines 135 to 139 in cc445f5
changes
This reads the environment variable
RUST_LOG
and will use value from there if set. It can be set to any values in the log crate. Otherwise the behavior is the same. If the-debug
flag is passed it will choose the highest of the two values.This also introduces ability to configure the default setting through the shim
Config
object:If all the configuration fails it will fallback to logging to to
info
level.