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

Embedded server should not mess global loggers (by default) #12861

Merged
merged 4 commits into from
Apr 15, 2021

Conversation

ptabor
Copy link
Contributor

@ptabor ptabor commented Apr 14, 2021

Give control to Embedded servers whether they override global loggers

So far each instance of embed server was overriding the grpc loggers and zap.global loggers.
It's counter intutitive that last created Embedded server was 'wining' and more-over it was breaking grpc expectation to change it "only" before the grpc stack is being used.

This PR introduces explicit call: embed.Config::SetupGlobalLoggers(), that changes the loggers where requested. The call is used by etcd main binary.

The immediate benefit from this change is lower test flakiness, as there were flakes due to not-proper logger usage across tests.

So far each instance of embed server was overriding the grpc loggers and zap.global loggers.
It's counter intutitive that last created Embedded server was 'wining' and more-over it was breaking grpc expectation to change it "only" before the grpc stack is being used.

This PR introduces explicit call: `embed.Config::SetupGlobalLoggers()`, that changes the loggers where requested. The call is used by etcd main binary.

The immediate benefit from this change is reduction of  test flakiness, as there were flakes due to not a proper logger being used across tests.
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.

Nice! 🎉

Few nits and questions mainly :)

"go.etcd.io/etcd/client/pkg/v3/logutil"
"go.uber.org/zap/zapgrpc"
"google.golang.org/grpc/grpclog"

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Any reason for a new line here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// The method is not executed by embed server by default (since 3.5) to
// enable setups where grpc/zap.Global logging is configured independently
// or spans separate lifecycle (like in tests).
func (cfg *Config) SetupGlobalLoggers() {
Copy link
Contributor

Choose a reason for hiding this comment

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

A small future refactor suggestion: Since this is no longer called by embed by default should we move it to be closer to the etcdmain package instead? Or is there maybe a reason we want to keep it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All direct users of Embed servers might want to call that API in similar way to how etcd does.
I decided to change existing behavior, but I think we should make the costs of getting previous behavior as low as possible.
To some degree Embed server is (the only) part of public API of go.etcd.io/etcd/server module.

@@ -57,6 +57,8 @@ func startEtcdOrProxyV2(args []string) {

err := cfg.parse(args[1:])
lg := cfg.ec.GetLogger()
cfg.ec.SetupGlobalLoggers()
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: What do you think, should this maybe be moved before getting the logger, so to line 59:

	cfg.ec.SetupGlobalLoggers()
	lg := cfg.ec.GetLogger()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved it to the later place of the file, so make it just after error handling (see the other comment)

@@ -57,6 +57,8 @@ func startEtcdOrProxyV2(args []string) {

err := cfg.parse(args[1:])
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder why this error is only checked on line 70.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If think the whole logic says:

If we failed to parse the whole configuration, print the error using preferable the resolved logger from the config, but if does not exists, create a new temporary logger.

Copy link
Contributor

@lilic lilic Apr 15, 2021

Choose a reason for hiding this comment

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

Thank you for the explanation!

)
m.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

+1.

@ptabor
Copy link
Contributor Author

ptabor commented Apr 15, 2021

Thank you for review !

@ptabor ptabor merged commit f3c5180 into etcd-io:master Apr 15, 2021
@ptabor ptabor deleted the 20210413-test-logging-fixes branch April 15, 2021 22:07
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.

3 participants