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 the log duplication issue for --log-file #78

Merged
merged 1 commit into from
Aug 7, 2019

Conversation

dims
Copy link
Member

@dims dims commented Jul 30, 2019

What this PR does / why we need it:

when we use a log-file, all the items in l.file array point to the
same file. we are currently using a switch statement with fallthrough
which ends up logging the same line multiple times. So check if we are
using a log-file and just write the data once.

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 #

Special notes for your reviewer:

Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.

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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 30, 2019
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 30, 2019
@dims
Copy link
Member Author

dims commented Jul 30, 2019

benchmark with "fix"

dims@bigbox:~/go/src/k8s.io/klog$ go test -benchmem -run=^$ k8s.io/klog -bench "^(BenchmarkLogs)$" -v -count=10
goos: linux
goarch: amd64
pkg: k8s.io/klog
BenchmarkLogs-20    	  200000	      8123 ns/op	     556 B/op	       6 allocs/op
BenchmarkLogs-20    	  200000	      7999 ns/op	     556 B/op	       6 allocs/op
BenchmarkLogs-20    	  200000	      7580 ns/op	     556 B/op	       6 allocs/op
BenchmarkLogs-20    	  200000	      8165 ns/op	     556 B/op	       6 allocs/op
BenchmarkLogs-20    	  200000	      7790 ns/op	     556 B/op	       6 allocs/op
BenchmarkLogs-20    	  200000	      8584 ns/op	     556 B/op	       6 allocs/op
BenchmarkLogs-20    	  200000	      7789 ns/op	     556 B/op	       6 allocs/op
BenchmarkLogs-20    	  200000	      7952 ns/op	     556 B/op	       6 allocs/op
BenchmarkLogs-20    	  200000	      7665 ns/op	     556 B/op	       6 allocs/op
BenchmarkLogs-20    	  200000	      8583 ns/op	     556 B/op	       6 allocs/op
PASS
ok  	k8s.io/klog	25.716s

benchmark without the "fix"

dims@bigbox:~/go/src/k8s.io/klog$ go test -benchmem -run=^$ k8s.io/klog -bench "^(BenchmarkLogs)$" -v -count=10
goos: linux
goarch: amd64
pkg: k8s.io/klog
BenchmarkLogs-20    	  100000	     10248 ns/op	     560 B/op	       6 allocs/op
BenchmarkLogs-20    	  100000	     10330 ns/op	     560 B/op	       6 allocs/op
BenchmarkLogs-20    	  100000	     10996 ns/op	     560 B/op	       6 allocs/op
BenchmarkLogs-20    	  100000	     10331 ns/op	     560 B/op	       6 allocs/op
BenchmarkLogs-20    	  200000	     10166 ns/op	     556 B/op	       6 allocs/op
BenchmarkLogs-20    	  200000	     10168 ns/op	     556 B/op	       6 allocs/op
BenchmarkLogs-20    	  100000	     10920 ns/op	     560 B/op	       6 allocs/op
BenchmarkLogs-20    	  100000	     10079 ns/op	     560 B/op	       6 allocs/op
BenchmarkLogs-20    	  100000	     10913 ns/op	     560 B/op	       6 allocs/op
BenchmarkLogs-20    	  100000	     10162 ns/op	     560 B/op	       6 allocs/op
PASS
ok  	k8s.io/klog	24.772s

@dims
Copy link
Member Author

dims commented Jul 30, 2019

/assign @vincepri @yuwenma

@dims
Copy link
Member Author

dims commented Jul 30, 2019

/approve cancel

@k8s-ci-robot k8s-ci-robot removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 30, 2019
klog.go Outdated

if logging.logFile != "" {
if l.file[infoLog] == nil {
if err := l.createFiles(s); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

should this be l.createFiles(infoLog)?
i don't know the details of the duplication issue, but does logging.logFile imply infoLog severity only?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed @neolit123. added some comments to clarify what we are doing

@dims dims changed the title [WIP] Attempt #2 - Fix the log duplication issue for --log-file Fix the log duplication issue for --log-file Aug 2, 2019
@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 Aug 2, 2019
@dims
Copy link
Member Author

dims commented Aug 2, 2019

/assign @tallclair

@yuwenma @tallclair can you please review since both of you worked on the previous attempt? (in kubernetes/kubernetes#78466)

when we use a `log-file`, all the items in l.file array point to the
same file. we are currently using a switch statement with fallthrough
which ends up logging the same line multiple times. So check if we are
using a `log-file` and just write the data once.

Change-Id: I3396558f487daf9db2c5e21e29a7a6bee618d64a
@yuwenma
Copy link

yuwenma commented Aug 7, 2019

@dims The PR lgtm. The only concern I have is that: Even if user provides --log-file flag, they should still be able to use --alsologtostderr flag to require standard output. This requires storing logs individually by severity level. Also, in such case users should be able to use --stderrthreshold to change the severity level of the standard output (e.g. if stderrthreshold is warning, all logs in warning and above warning will be printed in the stdout).

The above feature is no longer available after this PR goes in. Is this what we want? If so, can you add a docstring for alsologtostderr and stderrthreshold flags to explain this behavior?
 

Copy link
Member

@tallclair tallclair left a comment

Choose a reason for hiding this comment

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

/lgtm

I could have sworn I reviewed a very similar change before, but don't know what happened to it...

if logging.logFile != "" {
// Since we are using a single log file, all of the items in l.file array
// will point to the same file, so just use one of them to write data.
if l.file[infoLog] == nil {
Copy link
Member

Choose a reason for hiding this comment

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

nit: can we declare a constant to make this more explicit?

const singleFileLog = infoLog

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 7, 2019
@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: tallclair

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 Aug 7, 2019
@k8s-ci-robot k8s-ci-robot merged commit 3ca30a5 into kubernetes:master Aug 7, 2019
@tallclair
Copy link
Member

@yuwenma I don't understand your comment - it looks like the stderr output happens before these changes? Or were you commenting on an older version of this PR?

@yuwenma
Copy link

yuwenma commented Aug 7, 2019

@yuwenma I don't understand your comment - it looks like the stderr output happens before these changes? Or were you commenting on an older version of this PR?

yeah, i was referring to a old change.

/lgtm

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.

6 participants