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

logging: add way to configure logging level via cilium-agent option #8607

Merged
merged 1 commit into from Aug 12, 2019

Conversation

ianvernon
Copy link
Member

@ianvernon ianvernon commented Jul 17, 2019

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.

I added this because I thought I would be able to inject the logging level for
unit testing via a -X parameter when running go test, but given how we
set 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 Reviewable

@ianvernon ianvernon added kind/enhancement This would improve or streamline existing functionality. wip labels Jul 17, 2019
@ianvernon ianvernon requested review from a team as code owners July 17, 2019 21:53
@ianvernon
Copy link
Member Author

test-me-please

@ianvernon ianvernon force-pushed the pr/ianvernon/log-level-argument branch from 8ab4bda to 965fef1 Compare July 17, 2019 22:08
pkg/endpoint/log.go Outdated Show resolved Hide resolved
@ianvernon
Copy link
Member Author

test-me-please

@ianvernon ianvernon force-pushed the pr/ianvernon/log-level-argument branch from 965fef1 to 097bd63 Compare July 17, 2019 22:52
@ianvernon
Copy link
Member Author

test-me-please

1 similar comment
@ianvernon
Copy link
Member Author

test-me-please

@ianvernon ianvernon force-pushed the pr/ianvernon/log-level-argument branch from 097bd63 to 5c170c8 Compare July 18, 2019 23:31
@ianvernon
Copy link
Member Author

test-me-please

@ianvernon ianvernon force-pushed the pr/ianvernon/log-level-argument branch from 5c170c8 to 430750c Compare July 19, 2019 15:21
@ianvernon ianvernon force-pushed the pr/ianvernon/log-level-argument branch from 430750c to 7b11f62 Compare July 19, 2019 20:11
@ianvernon
Copy link
Member Author

test-me-please

@coveralls
Copy link

coveralls commented Jul 19, 2019

Coverage Status

Coverage increased (+0.06%) to 44.177% when pulling 111c71f on pr/ianvernon/log-level-argument into b6a1790 on master.

aanm
aanm previously requested changes Jul 22, 2019
Copy link
Member

@aanm aanm left a 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?

nebril
nebril previously requested changes Jul 22, 2019
pkg/logging/logging.go Outdated Show resolved Hide resolved
pkg/logging/logging.go Outdated Show resolved Hide resolved
@ianvernon
Copy link
Member Author

Where is the option flag being set in the cilium-agent?

@aanm it is set as a --log-opt, which is a mapping of key-value pairings for configuration related to logging.

@ianvernon ianvernon force-pushed the pr/ianvernon/log-level-argument branch from 7b11f62 to fe421fd Compare July 23, 2019 18:13
@ianvernon ianvernon requested a review from a team July 23, 2019 18:13
@ianvernon ianvernon requested review from aanm and nebril July 23, 2019 18:13
@ianvernon
Copy link
Member Author

test-me-please

@ianvernon ianvernon force-pushed the pr/ianvernon/log-level-argument branch from fe421fd to c0e5ca0 Compare July 23, 2019 18:15
@ianvernon
Copy link
Member Author

test-me-please

Copy link
Member

@joestringer joestringer left a 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.

@ianvernon
Copy link
Member Author

@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.

@ianvernon ianvernon force-pushed the pr/ianvernon/log-level-argument branch from c0e5ca0 to 76ef141 Compare July 24, 2019 18:34
@ianvernon
Copy link
Member Author

test-me-please

@ianvernon
Copy link
Member Author

ianvernon commented Jul 24, 2019

@joestringer added the unit tests - created a type wrapping around the logging options to make unit testing easier.

@ianvernon ianvernon dismissed stale reviews from nebril and aanm July 24, 2019 18:37

Addressed comments.

pkg/logging/logging.go Outdated Show resolved Hide resolved
// 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) {
Copy link
Contributor

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) {
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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).

Copy link
Member Author

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.

Copy link
Contributor

@raybejjani raybejjani left a 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.

pkg/logging/logging.go Outdated Show resolved Hide resolved
// It is thread-safe.
func ToggleDebugLogs(debug bool) {
func ConfigureLogLevel(debug bool) {
Copy link
Contributor

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).

@ianvernon ianvernon force-pushed the pr/ianvernon/log-level-argument branch from 76ef141 to 111c71f Compare August 5, 2019 16:40
@ianvernon
Copy link
Member Author

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>
@ianvernon ianvernon force-pushed the pr/ianvernon/log-level-argument branch from 111c71f to ed4fa78 Compare August 12, 2019 15:55
@ianvernon
Copy link
Member Author

test-me-please

@ianvernon ianvernon merged commit 77583f4 into master Aug 12, 2019
@ianvernon ianvernon deleted the pr/ianvernon/log-level-argument branch August 12, 2019 18:10
@ianvernon ianvernon added this to the 1.7 milestone Aug 12, 2019
@aanm aanm added the release-note/minor This PR changes functionality that users may find relevant to operating Cilium. label Nov 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement This would improve or streamline existing functionality. release-note/minor This PR changes functionality that users may find relevant to operating Cilium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants