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 zap encoding configurable #13339

Merged
merged 4 commits into from
Oct 20, 2021

Conversation

ardaguclu
Copy link
Contributor

@ardaguclu ardaguclu commented Sep 10, 2021

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.

@ardaguclu
Copy link
Contributor Author

/assign @lilic

Could you please take a look?, thanks.

Copy link
Contributor

@lilic lilic left a 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!

@hexfusion @ptabor

@@ -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'")
Copy link
Contributor

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:

Suggested change
log.Printf("Deprecated env ETCD_CLIENT_DEBUG value. Using default level: 'info'")
log.Printf("Unsupported env ETCD_CLIENT_DEBUG value. Using default level: 'info'")

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")
Copy link
Contributor

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

etcd/client/v3/doc.go

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.


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)
Copy link
Contributor

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.

@ardaguclu
Copy link
Contributor Author

Thanks for review @lilic, I applied your comments.

Copy link
Contributor

@lilic lilic left a comment

Choose a reason for hiding this comment

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

Thanks!

CHANGELOG-3.5.md Outdated Show resolved Hide resolved
@ardaguclu ardaguclu force-pushed the support-zap-console-encoding branch from 67a3c5f to 168b868 Compare September 10, 2021 13:12
@codecov-commenter
Copy link

Codecov Report

Merging #13339 (c2937d7) into main (c2937d7) will not change coverage.
The diff coverage is n/a.

❗ Current head c2937d7 differs from pull request most recent head 168b868. Consider uploading reports for the commit 168b868 to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##             main   #13339   +/-   ##
=======================================
  Coverage   39.49%   39.49%           
=======================================
  Files         460      460           
  Lines       39141    39141           
=======================================
  Hits        15459    15459           
  Misses      22009    22009           
  Partials     1673     1673           
Flag Coverage Δ
all 39.49% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c2937d7...168b868. Read the comment docs.

Copy link
Contributor

@lilic lilic left a 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`
Copy link
Contributor

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.

@ardaguclu ardaguclu force-pushed the support-zap-console-encoding branch from 168b868 to 83a43dc Compare September 13, 2021 09:46
Copy link
Contributor

@lilic lilic left a 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!

Copy link
Contributor

@hexfusion hexfusion left a 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

@ardaguclu ardaguclu changed the title Add configuring zap encoding "console" with ETCD_CLIENT_LOG_FORMAT Add --log-format parameter instead ENV var Sep 22, 2021
@ardaguclu ardaguclu changed the title Add --log-format parameter instead ENV var Add zap encoding configurable Sep 22, 2021
@ardaguclu ardaguclu force-pushed the support-zap-console-encoding branch from b25404b to f83eca2 Compare September 22, 2021 08:45
@ardaguclu
Copy link
Contributor Author

Thanks for review @hexfusion. Do you mean something recently pushed?

@hexfusion
Copy link
Contributor

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.

@ardaguclu
Copy link
Contributor Author

@hexfusion, one last thing; do I have to update proto files?

@hexfusion
Copy link
Contributor

@hexfusion, one last thing; do I have to update proto files?

No API changes should be required to my knowledge.

@ardaguclu ardaguclu force-pushed the support-zap-console-encoding branch from f83eca2 to c6ce677 Compare September 22, 2021 12:47
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`.
@ardaguclu ardaguclu force-pushed the support-zap-console-encoding branch from c6ce677 to e647995 Compare September 22, 2021 12:49
var encoder zapcore.Encoder
if logutil.ConvertToZapFormat(cfg.LogFormat) == logutil.ConsoleLogFormat {
encoder = zapcore.NewConsoleEncoder(logutil.DefaultZapLoggerConfig.EncoderConfig)
} else {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@ptabor ptabor requested a review from serathius September 25, 2021 15:36
@ardaguclu
Copy link
Contributor Author

Could we merge this?, what do you think?

Copy link
Contributor

@lilic lilic left a 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.

Copy link
Contributor

@ptabor ptabor left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you.

@hexfusion hexfusion merged commit 691dcd5 into etcd-io:main Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

6 participants