-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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 zap encoding configurable #13339
Add zap encoding configurable #13339
Conversation
/assign @lilic Could you please take a look?, thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of comments, thanks for the PR!
client/v3/logger.go
Outdated
@@ -51,18 +51,28 @@ func etcdClientDebugLevel() zapcore.Level { | |||
return zapcore.InfoLevel | |||
} | |||
var l zapcore.Level | |||
if err := l.Set(envLevel); err == nil { | |||
if err := l.Set(envLevel); err != nil { | |||
log.Printf("Deprecated env ETCD_CLIENT_DEBUG value. Using default level: 'info'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be something like, as its not necessarily deprecated:
log.Printf("Deprecated env ETCD_CLIENT_DEBUG value. Using default level: 'info'") | |
log.Printf("Unsupported env ETCD_CLIENT_DEBUG value. Using default level: 'info'") |
client/v3/logger.go
Outdated
log.Printf("Deprecated env ETCD_CLIENT_DEBUG value. Using default level: 'info'") | ||
return zapcore.InfoLevel | ||
} | ||
return l | ||
} | ||
|
||
func etcdClientLogFormat() string { | ||
envFormat := os.Getenv("ETCD_CLIENT_LOG_FORMAT") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's document this in the
Lines 102 to 104 in e2d67f2
// The grpc load balancer is registered statically and is shared across etcd clients. | |
// To enable detailed load balancer logging, set the ETCD_CLIENT_DEBUG environment | |
// variable. E.g. "ETCD_CLIENT_DEBUG=1". |
as well add a changelog entry similar to how the ETCD_CLIENT_DEBUG was added.
client/v3/logger.go
Outdated
|
||
return "json" | ||
} | ||
|
||
// CreateDefaultZapLoggerConfig creates a logger config that is configurable using env variable: | ||
// ETCD_CLIENT_DEBUG= debug|info|warn|error|dpanic|panic|fatal|true (true=info) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also same as above, please add what options ETCD_CLIENT_LOG_FORMAT has.
Thanks for review @lilic, I applied your comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
67a3c5f
to
168b868
Compare
Codecov Report
@@ Coverage Diff @@
## main #13339 +/- ##
=======================================
Coverage 39.49% 39.49%
=======================================
Files 460 460
Lines 39141 39141
=======================================
Hits 15459 15459
Misses 22009 22009
Partials 1673 1673
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small comment, otherwise lgtm.
CHANGELOG-3.6.md
Outdated
@@ -28,3 +28,6 @@ See [code changes](https://github.com/etcd-io/etcd/compare/v3.5.0...v3.6.0). | |||
- Package `mvcc/buckets` was moved to `storage/schema` | |||
- Package `wal` was moved to `storage/wal` | |||
- Package `datadir` was moved to `storage/datadir` | |||
|
|||
### Package `clientv3` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit, new line missing after this.
168b868
to
83a43dc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
@ptabor @hexfusion please take a look, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My feelings here are that we should not introduce a new orphaned ENV configuration and ensure a similar UX to the existing logging configs. IE
--log-format=console
b25404b
to
f83eca2
Compare
Thanks for review @hexfusion. Do you mean something recently pushed? |
Yes :) #13295 (comment) was to change server log format. So let's start here, thank you. |
@hexfusion, one last thing; do I have to update proto files? |
No API changes should be required to my knowledge. |
f83eca2
to
c6ce677
Compare
Json encoding is the default zap encoding value and can not be changeable. This PR enables configuring zap encoding to console via new flag `log-format`.
c6ce677
to
e647995
Compare
var encoder zapcore.Encoder | ||
if logutil.ConvertToZapFormat(cfg.LogFormat) == logutil.ConsoleLogFormat { | ||
encoder = zapcore.NewConsoleEncoder(logutil.DefaultZapLoggerConfig.EncoderConfig) | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might have missed this but do we validate the logFormat? IE --log-format=konsole
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, because ConvertToZapFormat
handles this https://github.com/etcd-io/etcd/pull/13339/files#diff-47d0d38c1df3e69bbdfb072164f8ee599204de9b3871d41d0c11b7ffed1b619cR25
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It returns json
other than anything console
including the empty string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should consider returning a clear error to admin that the config was not valid vs defaulting silently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, you are right. I'll add validation and warning user if log-format value is incorrect.
Could we merge this?, what do you think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hexfusion @ptabor please take a look again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you.
Json encoding is the default zap encoding value and can not be changeable.
This PR enables configuring zap encoding to console via new flag
log-format
.