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

klog v2.60.1 #108725

Merged
merged 3 commits into from Mar 24, 2022
Merged

klog v2.60.1 #108725

merged 3 commits into from Mar 24, 2022

Conversation

pohly
Copy link
Contributor

@pohly pohly commented Mar 16, 2022

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

The new release supports FlushAndExit and contextual logging.

Does this PR introduce a user-facing change?

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. 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. labels Mar 16, 2022
@k8s-ci-robot
Copy link
Contributor

@pohly: This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added 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. area/apiserver area/cloudprovider area/code-generation area/dependency Issues or PRs related to dependency changes area/kubectl 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/auth Categorizes an issue or PR as relevant to SIG Auth. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. sig/storage Categorizes an issue or PR as relevant to SIG Storage. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Mar 16, 2022
@k8s-ci-robot k8s-ci-robot requested review from ahg-g, andrewsykim and a team March 16, 2022 08:15
@dims
Copy link
Member

dims commented Mar 16, 2022

/retest

@dims
Copy link
Member

dims commented Mar 16, 2022

/assign

@pohly
Copy link
Contributor Author

pohly commented Mar 16, 2022

//
// This must be called during initialization before goroutines are started.
func EnableContextualLogging(enabled bool) {
contextualLoggingEnabled = enabled
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be called during initialization before goroutines are started.

if there any enforcement or protection if someone doesn't follow this rule? the places we'll be calling this will require parsing feature gates from args/config files, which means we can't call this from func init() methods which are easier to reason about goroutines not having started.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will get called in component-base/logs InitLogs which was recently (1.23) moved to the beginning of a program's startup:
https://github.com/kubernetes/component-base/blob/c5dae0cde26ef1c4fc6cfe6384bed8f36148f13f/cli/run.go#L122-L144

// Config and flags parsed, now we can initialize logging.
logs.InitLogs()
logOption := &logs.Options{Config: kubeletConfig.Logging}
if err := logOption.ValidateAndApply(); err != nil {
klog.ErrorS(err, "Failed to initialize logging")
os.Exit(1)
}

There's no enforcement to prevent data races or detect misuse. We could use an atomic Int32 access, but I don't think that this is needed. Even if it gets misused and the race goes wrong, the impact will probably be low.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, the decision to not do locking also applies to SetLogger which has been around for much longer.

Copy link
Contributor Author

@pohly pohly Mar 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a while SetLogger used mutex locking, but the corresponding read accesses don't, which rendered the mutex a bit mute (no pun intended), for example in https://github.com/kubernetes/klog/blob/f8e668dbaa5f6f0e6a5c24ffd7667263840d79ae/klog.go#L1387.

I brought this up when I noticed it and @serathius explained that relying on sequential execution is good enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-threadsafe globally writeable package vars seems like an anti-pattern we wouldn't want to extend.

I'm really not trying to make this a proxy review of changes that have gone into klog, but I'm concerned that the library is becoming harder to use safely within k/k

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO it's as easy (or hard) as before: some functions have to be called early. It's true that this PR adds one more of those, but it doesn't change how klog is used in k/k because EnableContextualLogging will be called at the same time or even earlier than the others (like SetLogger).

@enj enj added this to Needs Triage in SIG Auth Old Mar 21, 2022
The new release supports FlushAndExit and contextual logging.
Not all code knows that it needs to flush through component-base/logs.FlushLogs
when the JSON logger is used. By registering the flush callback together with
the logger, klog.Flush and klog.FlushAndExit are sufficient for flushing all
data.
The advantage is that klog properly handles restarting of the daemon
with a new interval and the daemon can be stopped.

Stopping the daemon solves a data race that the tests had when modifying the
Logger's flush function while goroutines from previous tests were still
running.
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 21, 2022
@pohly
Copy link
Contributor Author

pohly commented Mar 21, 2022

/retest

One unit test flake is getting fixed in #108553

The other is #105589

@ehashman ehashman added this to Triage in SIG Node PR Triage Mar 21, 2022
@fedebongio
Copy link
Contributor

/remove-sig api-machinery

@k8s-ci-robot k8s-ci-robot removed the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Mar 22, 2022
@liggitt
Copy link
Member

liggitt commented Mar 23, 2022

/approve

@liggitt
Copy link
Member

liggitt commented Mar 23, 2022

dependency mechanics lgtm

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dims, liggitt, pohly

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 Mar 23, 2022
@dims
Copy link
Member

dims commented Mar 23, 2022

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 23, 2022
@pohly
Copy link
Contributor Author

pohly commented Mar 24, 2022

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 24, 2022
@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.

@k8s-ci-robot k8s-ci-robot merged commit 56f45c5 into kubernetes:master Mar 24, 2022
SIG Auth Old automation moved this from Needs Triage to Closed / Done Mar 24, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.24 milestone Mar 24, 2022
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/code-generation area/dependency Issues or PRs related to dependency changes area/kubectl area/kubelet 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/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. 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. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. sig/storage Categorizes an issue or PR as relevant to SIG Storage. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. wg/structured-logging Categorizes an issue or PR as relevant to WG Structured Logging.
Projects
Archived in project
SIG Auth Old
Closed / Done
Development

Successfully merging this pull request may close these issues.

None yet

7 participants