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

runtime log verbosity level changes #114609

Merged
merged 3 commits into from Jan 21, 2023

Conversation

pohly
Copy link
Contributor

@pohly pohly commented Dec 20, 2022

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?

kube-proxy, kube-scheduler and kubelet have HTTP APIs for changing the logging verbosity at runtime. This now also works for JSON output.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Dec 20, 2022
@pohly pohly force-pushed the log-runtime-verbosity-level branch from 9155296 to 0693e89 Compare December 20, 2022 15:13
@k8s-ci-robot k8s-ci-robot added the wg/structured-logging Categorizes an issue or PR as relevant to WG Structured Logging. label Dec 20, 2022
@pohly pohly changed the title WIP: runtime log verbosity level changes runtime log verbosity level changes Dec 20, 2022
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 20, 2022
@pohly pohly force-pushed the log-runtime-verbosity-level branch from 0693e89 to e5cb77c Compare December 20, 2022 18:51
@k8s-ci-robot k8s-ci-robot added area/test sig/testing Categorizes an issue or PR as relevant to SIG Testing. labels Dec 20, 2022
@pohly pohly force-pushed the log-runtime-verbosity-level branch from e5cb77c to 5029d39 Compare December 20, 2022 19:19
// 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)
Copy link
Contributor Author

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.

@pohly pohly force-pushed the log-runtime-verbosity-level branch from 5029d39 to d63e633 Compare December 20, 2022 19:26
@k8s-triage-robot
Copy link

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.

@pohly pohly force-pushed the log-runtime-verbosity-level branch 3 times, most recently from a681fc7 to 679c666 Compare December 21, 2022 07:56
@pohly
Copy link
Contributor Author

pohly commented Dec 21, 2022

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.

@pohly pohly force-pushed the log-runtime-verbosity-level branch from ee7c14e to d148b63 Compare December 21, 2022 16:46
@fedebongio
Copy link
Contributor

/assign @logicalhan @serathius
/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jan 3, 2023
// 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
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 12, 2023
@serathius
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 17, 2023
@k8s-ci-robot
Copy link
Contributor

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.
@pohly pohly force-pushed the log-runtime-verbosity-level branch from 3fe5b39 to a41424d Compare January 17, 2023 09:31
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 17, 2023
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 17, 2023
@serathius
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 17, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 9743d8b20a34e285079ecdf08368ff2df4b527e1

@pohly
Copy link
Contributor Author

pohly commented Jan 17, 2023

/retest

1 similar comment
@pohly
Copy link
Contributor Author

pohly commented Jan 17, 2023

/retest

@thockin
Copy link
Member

thockin commented Jan 20, 2023

/approve

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 20, 2023
@k8s-triage-robot
Copy link

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:

  • The PR does have any do-not-merge/* labels
  • The PR does not have the needs-ok-to-test label
  • The PR is mergeable (does not have a needs-rebase label)
  • The PR is approved (has cncf-cla: yes, lgtm, approved labels)
  • The PR is failing tests required for merge

You can:

/retest

@k8s-ci-robot k8s-ci-robot merged commit 92f0818 into kubernetes:master Jan 21, 2023
@k8s-ci-robot k8s-ci-robot added this to the v1.27 milestone Jan 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver area/cloudprovider area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on. wg/structured-logging Categorizes an issue or PR as relevant to WG Structured Logging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants