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
log message verbosity #106978
log message verbosity #106978
Conversation
} | ||
klog.InfoS("Found related ReplicaSets", "replicaSet", klog.KObj(rs), "relatedReplicaSets", relatedNames) | ||
} | ||
klog.V(2).InfoS("Found related ReplicaSets", "replicaSet", klog.KObj(rs), "relatedReplicaSets", klog.KObjs(relatedRSs)) |
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.
klog.KObjs
does not produce exactly the same output but that should be fine because it works better with JSON.
I am worried that it might cause overhead when the log message is not actually emitted (see #106945).
Therefore here the prior "enabled" check might make sense even when using klog.KObjs
.
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.
Seems definitely a valid concern, should we try to prioritize the optimization before we push this out? It definitely could have a large impact in terms of resource consumption
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.
In other places klog.KObjs
was used without outer if check. But I myself also lean towards keeping the check until klog.KObj
can be shown to not have a performance overhead when called unconditionally.
We need @liggitt for approval. https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/legacy-cloud-providers/OWNERS has a very narrow set of approvers and @thockin's approval wasn't enough. |
/skip |
570fae7
to
24ba370
Compare
Rebased because of a conflict in pkg/kubelet/pleg/generic.go. |
24ba370
to
ac455f3
Compare
/remove-sig api-machinery |
In the following code pattern, the log message will get logged with v=0 in JSON output although conceptually it has a higher verbosity: if klog.V(5).Enabled() { klog.Info("hello world") } Having the actual verbosity in the JSON output is relevant, for example for filtering out only the important info messages. The solution is to use klog.V(5).Info or something similar. Whether the outer if is necessary at all depends on how complex the parameters are. The return value of klog.V can be captured in a variable and be used multiple times to avoid the overhead for that function call and to avoid repeating the verbosity level.
ac455f3
to
9eaa2dc
Compare
@pohly: The following tests failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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. I understand the commands that are listed here. |
/skip |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dims, pohly, 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 |
looks like the |
/lgtm |
/hold cancel |
What type of PR is this?
/kind bug
What this PR does / why we need it:
In the following code pattern, the log message will get logged with v=0 in JSON
output although conceptually it has a higher verbosity:
Having the actual verbosity in the JSON output is relevant, for example for
filtering out only the important info messages. The solution is to use
klog.V(5).Info
or something similar.Whether the outer if is necessary at all depends on how complex the parameters
are. The return value of
klog.V
can be captured in a variable and be used multipletimes to avoid the overhead for that function call and to avoid repeating
the verbosity level.
Which issue(s) this PR fixes:
Related-to: #102430
Special notes for your reviewer:
git grep 'klog.V([0-9]*).Enabled' cmd/ pkg/ staging
can be used to find code locations that may have to be modified.Does this PR introduce a user-facing change?