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

Fix cases where KMetadata interface has nil object #226

Merged
merged 1 commit into from
Mar 12, 2021

Conversation

serathius
Copy link

@serathius serathius commented Mar 12, 2021

DO NOT MERGE, this is one of the alternatives considered to fix kubernetes/kubernetes#100155

What this PR does / why we need it:

Fixes passing nil object to klog.KObj

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes kubernetes/kubernetes#100155

Special notes for your reviewer:

Added benchmark run them with go test -bench=BenchmarkKObj -count=100 -benchmem -run=^$ and got results analysed by benchstat:

name    old time/op    new time/op    delta
KObj-8    7.04ns ± 6%    7.50ns ± 8%  +6.57%  (p=0.000 n=89+93)

name    old alloc/op   new alloc/op   delta
KObj-8     0.00B          0.00B         ~     (all equal)

name    old allocs/op  new allocs/op  delta
KObj-8      0.00           0.00         ~     (all equal)

We see around 19% worse performance by introducing reflections, still looks acceptable.

Release note:

NONE

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 12, 2021
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Mar 12, 2021
@serathius serathius force-pushed the fix-nil branch 3 times, most recently from 3d6518b to 045efe9 Compare March 12, 2021 14:26
@serathius
Copy link
Author

Removing WIP as benchmark results look reasonable

@serathius serathius changed the title [WIP] Fix cases where KMetadata interface has nil object Fix cases where KMetadata interface has nil object Mar 12, 2021
@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 Mar 12, 2021
@serathius serathius force-pushed the fix-nil branch 2 times, most recently from 35c387b to b887978 Compare March 12, 2021 14:46
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 12, 2021
@serathius
Copy link
Author

Fixed how benchmark is implemented

@serathius serathius force-pushed the fix-nil branch 2 times, most recently from 648ad63 to 61753a1 Compare March 12, 2021 15:04
@dims
Copy link
Member

dims commented Mar 12, 2021

LGTM, i'd like a second opinion/review from @liggitt or @DirectXMan12

klog.go Outdated Show resolved Hide resolved
klog_test.go Show resolved Hide resolved
@serathius serathius force-pushed the fix-nil branch 2 times, most recently from 4d032b0 to 7d066fe Compare March 12, 2021 16:43
@serathius
Copy link
Author

Updated benchmark results, looks better around 7% difference.

@dims
Copy link
Member

dims commented Mar 12, 2021

/approve

leaving /lgtm for @liggitt or @ehashman

i can cut a release once this is merged

@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 12, 2021
@serathius
Copy link
Author

done, PTAL @liggitt

This was referenced Mar 13, 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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Structured Logging] when klog is passed nil, it causes components to panic while logging
5 participants