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

pkg/log(dm):support reading fields from Ctx #5518

Merged
merged 2 commits into from
May 24, 2022

Conversation

liuzix
Copy link
Contributor

@liuzix liuzix commented May 23, 2022

What problem does this PR solve?

Issue Number: close #5517

What is changed and how it works?

  • Put zap fields to contexts with context.WithValue.
  • Add WithCtx() method to log package, so that in each function call, the fields can be logged easily.
  • Added relevant benchmarks.

Check List

Tests

  • Unit test

Questions

Will it cause performance regression or break compatibility?
  • No regression for current production code, because no existing execution path is affected.
  • Benchmark results are as follows
goos: linux
goarch: amd64
pkg: github.com/pingcap/tiflow/dm/pkg/log
cpu: AMD Ryzen 9 5900X 12-Core Processor            
BenchmarkBaseline
BenchmarkBaseline-24    	 9693552	       124.1 ns/op
BenchmarkWithCtx
BenchmarkWithCtx-24     	 6640200	       181.1 ns/op
PASS

Process finished with the exit code 0

Using WithCtx increases time cost by 50% compared to traditional, but more complex methods. But given the baseline high performance of zap, it should be fine as long as no logging is used in CPU intensive operations.

Release note

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented May 23, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • amyangfei
  • lance6716

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 23, 2022
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label May 23, 2022
@amyangfei
Copy link
Contributor

goos: linux
goarch: amd64
pkg: github.com/pingcap/tiflow/dm/pkg/log
cpu: AMD Ryzen 9 5900X 12-Core Processor            
BenchmarkBaseline
BenchmarkBaseline-24    	 9693552	       124.1 ns/op
BenchmarkWithCtx
BenchmarkWithCtx-24     	 6640200	       181.1 ns/op
PASS

Process finished with the exit code 0

Really fast CPU 🚀

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels May 24, 2022
@liuzix
Copy link
Contributor Author

liuzix commented May 24, 2022

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 6900b47

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label May 24, 2022
@liuzix
Copy link
Contributor Author

liuzix commented May 24, 2022

/run-dm-integration-test

1 similar comment
@amyangfei
Copy link
Contributor

/run-dm-integration-test

@ti-chi-bot ti-chi-bot merged commit cca66c1 into pingcap:master May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

engine: We need a better mechanism for structured logging
4 participants