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
runtime log verbosity level changes #114609
runtime log verbosity level changes #114609
Conversation
9155296
to
0693e89
Compare
0693e89
to
e5cb77c
Compare
e5cb77c
to
5029d39
Compare
// If provided, the caller must ensure that it is called | ||
// periodically (if desired) and at program exit. | ||
Create(c LoggingConfiguration) (log logr.Logger, flush func()) | ||
Create(c LoggingConfiguration) (logr.Logger, RuntimeControl) |
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's unfortunate that Go API changes inside k8s.io/component-base/logs are needed, but the effect is limited to code which provides its own logging format, which might be none at all outside of k/k.
The "v1" refers to the user-facing API (configuration file, command line flags) and that doesn't change.
I looked (again) at whether some of this code could be moved out of the "v1" package, but that quickly fails due to circular dependencies.
5029d39
to
d63e633
Compare
This PR may require API review. If so, when the changes are ready, complete the pre-review checklist and request an API review. Status of requested reviews is tracked in the API Review project. |
a681fc7
to
679c666
Compare
As this PR will need an API review due to the changes in api/v1, let me add another commit with a change in that directory: its an enabler for writing tests which need to redirect output instead of using os.Stdout and os.Stderr. |
ee7c14e
to
d148b63
Compare
/assign @logicalhan @serathius |
// k8s.io/component-base/logs (uses the callbacks) to | ||
// k8s.io/component-base/logs/api/v1 (adds them). Not all users of the logs | ||
// package also use the API. | ||
package setverbositylevel |
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.
Interface of this package is a little too open and doesn't follow golang naming scheme (https://go.dev/doc/effective_go#package-names).
Could we expose AddCallback
and SetVerbosity
functions instead of Mutex
and Callbacks
to avoid misuse?
Instead naming package setverbositylevel
could we rename it to just verbosity
? This would allow external packages to call function verbosity.Set
.
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.
doesn't follow golang naming scheme (https://go.dev/doc/effective_go#package-names).
setverbositylevel.Mutex
and setverbositylevel.Callbacks
sounds okay to me.
to avoid misuse?
This is an internal package - nothing outside of k8s.io/component-base/logs has access to it. Therefore I wasn't worried about preventing misuse and instead went for simplicity. Does that make sense?
Instead naming package setverbositylevel could we rename it to just verbosity?
I can, but is verbosity.Callbacks
really a better name?
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 think it's worth blocking, however I still think verbosity
is a better package name.
I can, but is verbosity.Callbacks really a better name?
Maybe verbosity.ChangeCallbacks
. Usually you would prefer verbosity.RegisterCallback
.
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.
Let's continue with the simpler approach of not adding functions to the package. The package only exists to avoid circular package dependencies, not to protect variables against undesired access.
/lgtm |
LGTM label has been added. Git tree hash: ee3a14e58afc72d99f80a7f36923cac8fbf1e6ff
|
Having the sub-package using the same name as the parent package makes no sense. This seems to be a cut-and-paste error.
The GlogSetter method is used by three components to change verbosity at runtime through HTTP APIs. This used to work only for text output with klog calls, but not for text output through the klog logger or for JSON output. Now loggers can also provide a callback for changing their verbosity at runtime. Implementing that implies that the Create factory method has to be extended, which is an API break for the Go package, but not an API break for the configuration file and command line flags, which is what matters for the "api/v1" component API.
This is useful for tests which need to discard or capture the output.
3fe5b39
to
a41424d
Compare
/lgtm |
LGTM label has been added. Git tree hash: 9743d8b20a34e285079ecdf08368ff2df4b527e1
|
/retest |
1 similar comment
/retest |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: pohly, serathius, thockin The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass. This bot retests PRs for certain kubernetes repos according to the following rules:
You can:
/retest |
What type of PR is this?
/kind feature
What this PR does / why we need it:
This enables changing the verbosity level of JSON output at runtime.
Does this PR introduce a user-facing change?