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

*: add pingcap/log encoder as the default encoder #62

Merged
merged 3 commits into from
Aug 31, 2022

Conversation

xhebox
Copy link
Collaborator

@xhebox xhebox commented Aug 30, 2022

Signed-off-by: xhe xw897002528@gmail.com

What problem does this PR solve?

Issue Number: close None

Problem Summary: To reduce the risk of GA, the old encoder is brought back as the default.

What is changed and how it works: StackTrace by zap is multiline, this is not compatible with tidb format.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Notable changes

  • Has configuration change
  • Has HTTP API interfaces change (Don't forget to add the declarative for API)
  • Has weirctl change
  • Other user behavior changes

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

Signed-off-by: xhe <xw897002528@gmail.com>
@xhebox xhebox requested a review from djshow832 August 30, 2022 11:02
@@ -33,7 +33,7 @@ func main() {
}

configFile := rootCmd.PersistentFlags().String("config", "conf/weirproxy.yaml", "weir proxy config file path")
logEncoder := rootCmd.PersistentFlags().String("log_encoder", "", "log in format of tidb, console, or json")
logEncoder := rootCmd.PersistentFlags().String("log_encoder", "", "log in format of tidb, newtidb, console, or json")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is shown for users, don't show this. It just confuses users.
Why don't you trust log.NewTextEncoder? Did you fix any bugs on your version?

Copy link
Collaborator Author

@xhebox xhebox Aug 30, 2022

Choose a reason for hiding this comment

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

This is shown for users, don't show this. It just confuses users.

Removed from the description.

Why don't you trust log.NewTextEncoder?

I've trust log.NewTextEncoder much that I just modified the encoder instead of writing a new one from the scratch.

The modification of encoder is seen as a minor improvement that should not have problems. And it is indeed a minor change. Even if it has problems, like now, I can fix it easily.

Did you fix any bugs on your version?

I don't, neither the old encoder.

Most bugs of pingcap/log is not in the encoder, but comes from its buggy API. I did not even include one line of other components. The old encoder code have not been modified since Mar 2019.

But there was a bug in the function log.NewTextEncoder. I would say that the encoder itself is indeed stable(or more like unmaintained, should have special processors for key encodings or errors), but not other parts.

Signed-off-by: xhe <xw897002528@gmail.com>
@@ -32,6 +33,9 @@ var registerEncoders sync.Once
func RunRootCommand(rootCmd *cobra.Command) {
registerEncoders.Do(func() {
zap.RegisterEncoder("tidb", func(cfg zapcore.EncoderConfig) (zapcore.Encoder, error) {
return log.NewTextEncoder(&log.Config{})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Have a manual test to verify that the log configurations in the configuration file can work.

Copy link
Collaborator Author

@xhebox xhebox Aug 30, 2022

Choose a reason for hiding this comment

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

LogLevel has no relation with Encoder. zapcore will handle loglevel and logfile. That said, there is no options in our yaml files, or options from EncoderConfig can be applied to log.NewTextEncoder. If we want to apply all zap config, either we need to modify pingcap/log, or we need to copy the whole file.

LogFile support is not added. If I rememered it correct, it is not added in the original weir, too. I can add it to my TODO list. This should be a trivial change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

LogLevel tested, LogFile not working expectedly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

File an issue to support LogFile.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

File an issue to support LogFile.

It is recorded in the list already.

Signed-off-by: xhe <xw897002528@gmail.com>
@@ -57,6 +57,7 @@ func main() {

zapcfg := zap.NewDevelopmentConfig()
zapcfg.Encoding = cfg.Log.Encoder
zapcfg.DisableStacktrace = true
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

While Encoder can ensure there is no multiline string, the stacktrace from zap iteself may escape.

@djshow832 djshow832 merged commit b49db9a into pingcap:main Aug 31, 2022
@xhebox xhebox deleted the log_1 branch August 31, 2022 03:32
@xhebox xhebox mentioned this pull request Aug 31, 2022
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants