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 2.20.0, logr v1.1.0, zapr v1.1.0 #104103

Merged
merged 1 commit into from Sep 9, 2021
Merged

Conversation

pohly
Copy link
Contributor

@pohly pohly commented Aug 3, 2021

What type of PR is this?

/kind cleanup
/kind api-change

What this PR does / why we need it:

This replaces the experimental logr v0.4 with the stable v1.1.0
release. This is a breaking API change for some users because:

  • Comparing logr.Logger against nil is not possible anymore:
    it's now a struct instead of an interface. Code which
    allows a nil logger must switch to *logr.Logger as type.
  • Logger implementations must be updated in lockstep.

Instead of updating the forked zapr code in json.go, directly using
the original go-logr/zapr is simpler and avoids duplication of effort.

Which issue(s) this PR fixes:

Fixes #104097

Special notes for your reviewer:

The updated zapr supports logging of numeric verbosity. Error messages
don't have a verbosity (= always get logged), so "v" is not getting
added to them anymore.

Source code logging for panic messages got fixed so that it references
the code with the invalid log call, not the json.go implementation.

Finally, zapr includes additional information in its panic
messages ("zap field", "ignored key", "invalid key").

Does this PR introduce a user-facing change?

Users of LogFormatRegistry in component-base must update their code to use the logr v1.0.0 API. The JSON log output now uses the format from go-logr/zapr (no `v` field for error messages, additional information for invalid calls) and has some fixes (correct source code location for warnings about invalid log calls).

@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. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API 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. area/apiserver area/cloudprovider needs-priority Indicates a PR lacks a `priority/foo` label and requires one. 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/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. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Aug 3, 2021
@k8s-ci-robot k8s-ci-robot added 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. wg/structured-logging Categorizes an issue or PR as relevant to WG Structured Logging. labels Aug 3, 2021
@pohly
Copy link
Contributor Author

pohly commented Aug 3, 2021

This is WIP because klog doesn't have a formal release yet and because there are known test failures in staging/src/k8s.io/component-base/logs/json.

@pohly
Copy link
Contributor Author

pohly commented Aug 3, 2021

This is failing because it uses Logger{} to denote an uninitialized logger instead of the former nil, but that then cause nil pointer access because klog does not (and cannot!) detect that such a struct is unusable.

@thockin
Copy link
Member

thockin commented Aug 3, 2021 via email

@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 Sep 2, 2021
@pohly
Copy link
Contributor Author

pohly commented Sep 2, 2021

@kubernetes/dep-approvers: @serathius finished the technical review, now we need approval for the modified dependencies (external zapr instead of internal fork, updated dependencies).

@pohly
Copy link
Contributor Author

pohly commented Sep 9, 2021

Just noticed some left-over comment and a formatting issue, force-pushed.

This replaces the experimental logr v0.4 with the stable v1.1.0
release. This is a breaking API change for some users because:
- Comparing logr.Logger against nil is not possible anymore:
  it's now a struct instead of an interface. Code which
  allows a nil logger should switch to *logr.Logger as type.
- Logger implementations must be updated in lockstep.

Instead of updating the forked zapr code in json.go, directly using
the original go-logr/zapr is simpler and avoids duplication of effort.

The updated zapr supports logging of numeric verbosity. Error messages
don't have a verbosity (= always get logged), so "v" is not getting
added to them anymore.

Source code logging for panic messages got fixed so that it references
the code with the invalid log call, not the json.go implementation.

Finally, zapr includes additional information in its panic
messages ("zap field", "ignored key", "invalid key").
@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Sep 9, 2021
@dims
Copy link
Member

dims commented Sep 9, 2021

/retest

@dims
Copy link
Member

dims commented Sep 9, 2021

/approve
/lgtm
/assign @liggitt

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 9, 2021
@logicalhan
Copy link
Member

/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 Sep 9, 2021
@@ -149,57 +163,63 @@ func TestKlogIntegration(t *testing.T) {
fun: func() {
klog.Error("test ", 1)
},
format: `{"ts":%f,"caller":"json/klog_test.go:%d","msg":"test 1\n","v":0}`,
Copy link
Member

Choose a reason for hiding this comment

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

is it expected that these no longer output "v":0?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, verbosity for error didn't have any semantic meaning. It was always supposed to be equal zero, but we decided to drop it in zapr.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Only info messages have a verbosity level and are subjected to filtering by verbosity. Error messages are always printed and therefore conceptually don't have verbosity. In other words, V(3).Error is the same as V(0).Error.

@liggitt
Copy link
Member

liggitt commented Sep 9, 2021

are there any benchmarks/performance tests on the structured logging to demonstrate this replumbing didn't noticeably affect resource usage?

@liggitt
Copy link
Member

liggitt commented Sep 9, 2021

dependency mechanics lgtm, just a couple questions

@pohly
Copy link
Contributor Author

pohly commented Sep 9, 2021

are there any benchmarks/performance tests on the structured logging to demonstrate this replumbing didn't noticeably affect resource usage?

I ran the staging/src/k8s.io/component-base/logs/json benchmarks without and with these changes and got:

$ benchstat /tmp/logr04 /tmp/logr10
name               old time/op    new time/op    delta
InfoLoggerInfo-36    1.84µs ± 8%    1.93µs ± 8%     ~     (p=0.246 n=5+5)
ZapLoggerError-36    2.89µs ± 2%    2.87µs ± 4%     ~     (p=0.841 n=5+5)
ZapLoggerV-36        2.23µs ± 2%    2.14µs ± 3%   -3.80%  (p=0.016 n=5+5)

name               old alloc/op   new alloc/op   delta
InfoLoggerInfo-36    1.43kB ± 0%    1.43kB ± 0%     ~     (p=0.111 n=5+5)
ZapLoggerError-36    1.62kB ± 0%    1.56kB ± 0%   -3.93%  (p=0.008 n=5+5)
ZapLoggerV-36        1.45kB ± 0%    1.43kB ± 0%   -1.21%  (p=0.000 n=5+4)

name               old allocs/op  new allocs/op  delta
InfoLoggerInfo-36      7.00 ± 0%      7.00 ± 0%     ~     (all equal)
ZapLoggerError-36      10.0 ± 0%      10.0 ± 0%     ~     (all equal)
ZapLoggerV-36          8.00 ± 0%      7.00 ± 0%  -12.50%  (p=0.008 n=5+5)

So performance gets slightly better.

@liggitt
Copy link
Member

liggitt commented Sep 9, 2021

/lgtm
/approve

@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 Sep 9, 2021
@serathius
Copy link
Contributor

serathius commented Sep 9, 2021

are there any benchmarks/performance tests on the structured logging to demonstrate this replumbing didn't noticeably affect resource usage?

I ran the staging/src/k8s.io/component-base/logs/json benchmarks without and with these changes and got:

$ benchstat /tmp/logr04 /tmp/logr10
name               old time/op    new time/op    delta
InfoLoggerInfo-36    1.84µs ± 8%    1.93µs ± 8%     ~     (p=0.246 n=5+5)
ZapLoggerError-36    2.89µs ± 2%    2.87µs ± 4%     ~     (p=0.841 n=5+5)
ZapLoggerV-36        2.23µs ± 2%    2.14µs ± 3%   -3.80%  (p=0.016 n=5+5)

name               old alloc/op   new alloc/op   delta
InfoLoggerInfo-36    1.43kB ± 0%    1.43kB ± 0%     ~     (p=0.111 n=5+5)
ZapLoggerError-36    1.62kB ± 0%    1.56kB ± 0%   -3.93%  (p=0.008 n=5+5)
ZapLoggerV-36        1.45kB ± 0%    1.43kB ± 0%   -1.21%  (p=0.000 n=5+4)

name               old allocs/op  new allocs/op  delta
InfoLoggerInfo-36      7.00 ± 0%      7.00 ± 0%     ~     (all equal)
ZapLoggerError-36      10.0 ± 0%      10.0 ± 0%     ~     (all equal)
ZapLoggerV-36          8.00 ± 0%      7.00 ± 0%  -12.50%  (p=0.008 n=5+5)

So performance gets slightly better.

Just a note about using benchstat. You should look at value of p. It represents statistical significance. Lower the better. Result of 0.841 for ZapLoggerError-36 means that number of runs (5 in this example) were not enough to determine if there is improvement (variance is bigger than difference). In this case this doesn't make much differece, but it's usually good to increase number of test runs to make sure p is kept low (<0.1).

For example looks like there is a small regression for InfoLoggerInfo-36, but with p=0.246, benchstat doesn't show delta as there is not enough runs to be sure. I would recommend increasing number of runs to 10.

@pohly
Copy link
Contributor Author

pohly commented Sep 9, 2021

/retest

Unit test flake (k8s.io/kubernetes/vendor/k8s.io/apiserver/pkg/util/flowcontrol/fairqueuing/queueset: TestDifferentWidths)

@pohly
Copy link
Contributor Author

pohly commented Sep 9, 2021

/retest

gce test flake (Kubernetes e2e suite: [sig-storage] Downward API volume should update labels on modification)

@k8s-ci-robot k8s-ci-robot merged commit 5b49d12 into kubernetes:master Sep 9, 2021
SIG Auth Old automation moved this from Needs Triage to Closed / Done Sep 9, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.23 milestone Sep 9, 2021
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 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. 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/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. 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
Archived in project
SIG Auth Old
Closed / Done
Development

Successfully merging this pull request may close these issues.

Migrate Json logging format to use zapr