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

Move pkg/jsonlog to be a subpackage of the single consumer #34946

Merged
merged 6 commits into from
Sep 26, 2017

Conversation

dnephin
Copy link
Member

@dnephin dnephin commented Sep 22, 2017

Remove some unused code
Un-export some code that shouldn't be exported
Cleanup test cases
Move a constant to a more appropriate module
Move the pkg/jsonlog to a subpackage of jsonfilelog

Copy link
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

LGTM

@cpuguy83
Copy link
Member

It would be nice to reconcile this with ffjson.

@dnephin
Copy link
Member Author

dnephin commented Sep 23, 2017

It would be nice to reconcile this with ffjson.

I agree, but I think we need to get it setup with a go generate, and a check in hack/validate to make sure generation is done correctly, and a benchmark to compare against encoding/json.

@unclejack
Copy link
Contributor

@dnephin: Can you provide benchmark numbers for memory allocations done before and after these changes, please?

Created string `json:"time"`
Log []byte `json:"log,omitempty"`
Stream string `json:"stream,omitempty"`
Created time.Time `json:"time"`
Copy link
Member

Choose a reason for hiding this comment

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

We are using that one on the client side right ? This might break a bunch of user of this pkg right ?

Copy link
Member Author

Choose a reason for hiding this comment

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

This struct is not used by the cli. The cli is only using a constant, and is made forward compatible here: docker/cli#551

It might break users of this pkg, but that is unfortunately necessary. These packages were not maintained properly and developed really bad interfaces which need to be fixed. We're going to be breaking everyone with #32989 anyway, and I think this can be seen as cleanup work necessary for #32989.

The godoc (https://godoc.org/github.com/moby/moby/pkg/jsonlog) doesn't show any consumers of this package. I'm not sure how reliable that is, but it seems to work for other packages.

@dnephin
Copy link
Member Author

dnephin commented Sep 25, 2017

Looking at this again, I don't think JSONLog.MarshalJSON() is actually used anywhere. It seems that object is only ever used to unmarshal JSON.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Signed-off-by: Daniel Nephin <dnephin@docker.com>
@dnephin
Copy link
Member Author

dnephin commented Sep 25, 2017

Can you provide benchmark numbers for memory allocations done before and after these changes

I found some benchmarks in daemon/logger/jsonfilelog and fixed them up to work, then backported them to master. Here's the output.

# Branch
go test -v -bench=. -run TestNothing -benchmem ./daemon/logger/jsonfilelog/
BenchmarkJSONFileLoggerLog-8             1000000              1007 ns/op    172.65 MB/s         121 B/op          1 allocs/op
BenchmarkJSONFileLoggerReadLogs-8        1000000              1243 ns/op    139.98 MB/s         356 B/op          6 allocs/op
PASS
ok      github.com/docker/docker/daemon/logger/jsonfilelog      2.284s

# Master
BenchmarkJSONFileLoggerLog-8             2000000               990 ns/op    175.61 MB/s         122 B/op          1 allocs/op
BenchmarkJSONFileLoggerReadLogs-8        1000000              1137 ns/op    153.01 MB/s         260 B/op          6 allocs/op
PASS
ok      github.com/docker/docker/daemon/logger/jsonfilelog      4.102s

This is the first go benchmark I've written, so let me know if you see anything that looks off. There were some logical errors in what exited before (wrong number of bytes because 1) it was using a different struct to calculate bytes, and 2) it was doing extra iterations not accounted for by b.N)

@dnephin dnephin changed the title Cleanup pkg/jsonlog Move pkg/jsonlog to be a subpackage of the single consumer Sep 25, 2017
@dnephin
Copy link
Member Author

dnephin commented Sep 25, 2017

I removed some more unused code JSONLog.MarshalJSON() was completely unused, which allowed me to remove the duplcate ffjson function. I moved the whole package to under jsonfilelog since this is really just an implementation detail of that logger.

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

LGTM 🐸

@vdemeester vdemeester merged commit 7d47823 into moby:master Sep 26, 2017
@dnephin dnephin deleted the fix-jsonlog branch September 26, 2017 13:59
bonczj added a commit to bonczj/moby-json-file-logger that referenced this pull request Sep 26, 2017
Fixes moby#19803
Updated the json-logger to utilize the common log option
'tag' that can define container/image information to include
as part of logging.

When the 'tag' log option is not included, there is no change
to the log content via the json-logger. When the 'tag' log option
is included, the tag will be parsed as a template and the result
will be stored within each log entry as the attribute 'tag'.

Update: Removing test added to integration_cli as those have been deprecated.
Update: Using proper test calls (require and assert) in jsonfilelog_test.go based on review.
Update: Added new unit test configs for logs with tag. Updated unit test error checking.
Update: Cleanup check in jsonlogbytes_test.go to match pending changes in PR moby#34946.
Update: Merging to correct conflicts from PR moby#34946.

Signed-off-by: bonczj <josh.bonczkowski@gmail.com>
@unclejack
Copy link
Contributor

@dnephin: Thank you. I'm worried about regressions related to memory allocations in this code. We've had some unpleasant issues related to this in the past. It's good to see allocations remain pretty much the same.

yongtang pushed a commit to yongtang/docker that referenced this pull request Jan 19, 2018
Fixes moby#19803
Updated the json-logger to utilize the common log option
'tag' that can define container/image information to include
as part of logging.

When the 'tag' log option is not included, there is no change
to the log content via the json-logger. When the 'tag' log option
is included, the tag will be parsed as a template and the result
will be stored within each log entry as the attribute 'tag'.

Update: Removing test added to integration_cli as those have been deprecated.
Update: Using proper test calls (require and assert) in jsonfilelog_test.go based on review.
Update: Added new unit test configs for logs with tag. Updated unit test error checking.
Update: Cleanup check in jsonlogbytes_test.go to match pending changes in PR moby#34946.
Update: Merging to correct conflicts from PR moby#34946.

Signed-off-by: bonczj <josh.bonczkowski@gmail.com>
@thaJeztah thaJeztah mentioned this pull request Jan 9, 2025
74 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants