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
logging: add way to configure logging level via cilium-agent option #8607
Conversation
test-me-please |
8ab4bda
to
965fef1
Compare
test-me-please |
965fef1
to
097bd63
Compare
test-me-please |
1 similar comment
test-me-please |
097bd63
to
5c170c8
Compare
test-me-please |
5c170c8
to
430750c
Compare
430750c
to
7b11f62
Compare
test-me-please |
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.
Where is the option flag being set in the cilium-agent?
@aanm it is set as a |
7b11f62
to
fe421fd
Compare
test-me-please |
fe421fd
to
c0e5ca0
Compare
test-me-please |
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.
Looks fine to me. The logic seems like something easy to unit-test (debug overrides other options, invalid options specification is overridden with default, etc).
Also not sure why the options need to be cached in a var, since it seems like they're just validated and configured into the logging library. But this should be inconsequential.
@joestringer will add some unit tests. Re: why options are cached in a var - outside packages consume the configuration (specifically the endpoint log). The value has to be inspected as well when we are changing from user-specified log level --> debug --> user-specified log level as well. |
c0e5ca0
to
76ef141
Compare
test-me-please |
@joestringer added the unit tests - created a type wrapping around the logging options to make unit testing easier. |
// configureLogLevelFromOptions sets the log level of the DefaultLogger based | ||
// off of the value of LevelOpt in logOpts. If LevelOpt is not set in logOpts, | ||
// it defaults to DefaultLogLevelStr. | ||
func setLogLevelFromOptions(logOpts LogOptions) { |
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.
It feels a little odd to have this private function but a global GetLogLevel that is more generic. Creating a SetLogLevel(logrus.Level)
feels more re-usable. It is just shuffling things around, though, since we only use this in one callpath.
// It is thread-safe. | ||
func ToggleDebugLogs(debug bool) { | ||
func ConfigureLogLevel(debug bool) { |
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.
When I saw the name change I was expecting this function to take in both debug
and options
. It feels weird to mix using the global and the debug
parameter. Is there any chance we can pass in the configuration here every time? That will probably mean exposing options
in some way but you might have done all this to avoid 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.
I can't import pkg/option
into here because it will result in a dependency loop. Perhaps I can do it as an interface.
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.
Oh, I meant that we were referring to the global variable options
in this package while also taking the debug
parameter. Both are configuration to be parsed/used. To be clear, I'm fine with the global variable. I would just prefer to pass in both debug
and options
here.
I don't fully see why pkg/options would come up in this case; all calls to ConfigureLogLevel
could pass in the LogOptions
type (SetupLogging already does this
).
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 weird thing about debug
is that it's extracted from other configuration outside of the logging package. What I'd love for us to have (which would be a significant change) is to be able to register objects to be updated when configuration that could be changed after Cilium is started (e.g., cilium config x=y
), and that way we'd not have to pass debug
around as a variable in function calls (not sure how much that makes sense).
Logging level is an option configured at agent bootstrap vs. debug being a configurable option that can change during a single run of a given agent, which is why debug is the only "variable" 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.
Looking at this again, nothing is blocking. I left some clarifications on my comments but we can change things later if you agree, or not if you don't.
// It is thread-safe. | ||
func ToggleDebugLogs(debug bool) { | ||
func ConfigureLogLevel(debug bool) { |
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.
Oh, I meant that we were referring to the global variable options
in this package while also taking the debug
parameter. Both are configuration to be parsed/used. To be clear, I'm fine with the global variable. I would just prefer to pass in both debug
and options
here.
I don't fully see why pkg/options would come up in this case; all calls to ConfigureLogLevel
could pass in the LogOptions
type (SetupLogging already does this
).
76ef141
to
111c71f
Compare
test-me-please |
The new option can be provided as follows to `cilium-agent`: ``` --log-opt level=error ``` If no option is set, or the provided option does not match a level for logrus, use the default logging level (info level). If debug mode is not enabled, endpoint loggers will use the logging level provided via the command-line option, if there was one provided. If not, the endpoitn logger will default to info level as well. If debug mode is enabled, it will override the value passed for the log level. Signed-off by: Ian Vernon <ian@cilium.io>
111c71f
to
ed4fa78
Compare
test-me-please |
The new option can be provided as follows to
cilium-agent
:If no option is set, or the provided option does not match a level for logrus,
use the default logging level (info level). If debug mode is not enabled,
endpoint loggers will use the logging level provided via the command-line
option, if there was one provided. If not, the endpoitn logger will default
to info level as well.
I added this because I thought I would be able to inject the logging level for
unit testing via a
-X
parameter when runninggo test
, but given how weset up our loggers (in their own package), that didn't work very well. But,
I didn't want my work to go to waste, so I posted this PR.
Signed-off by: Ian Vernon ian@cilium.io
This change is