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

Zap logger prints connection reset by peer but capnslog doesn't #10364

Closed
xxx7xxxx opened this issue Jan 2, 2019 · 15 comments
Closed

Zap logger prints connection reset by peer but capnslog doesn't #10364

xxx7xxxx opened this issue Jan 2, 2019 · 15 comments
Labels

Comments

@xxx7xxxx
Copy link

xxx7xxxx commented Jan 2, 2019

Under the newest master code.

When I execute this command:

make
./bin/etcd --logger zap &
export ETCDCTL_API=3
./bin/etcdctl get hello

The zap logger will print:

{"level":"warn","ts":1546426325.950272,"caller":"grpclog/grpclog.go:60","msg":"transport: http2Server.HandleStreams failed to read frame: read tcp 127.0.0.1:2379->127.0.0.1:50450: read: connection reset by peer"}

But I change the startup command line to ./bin/etcd # which means capnslog logger , there isn't the same warn log.

@xxx7xxxx xxx7xxxx changed the title Print connection reset by peer when launching it with embed Zap logger prints connection reset by peer when launching it with embed Jan 2, 2019
@xxx7xxxx xxx7xxxx changed the title Zap logger prints connection reset by peer when launching it with embed Zap logger prints connection reset by peer Jan 2, 2019
@xxx7xxxx xxx7xxxx changed the title Zap logger prints connection reset by peer Zap logger prints connection reset by peer but capnslog doesn't Jan 2, 2019
@hexfusion
Copy link
Contributor

But I change the startup command line to ./bin/etcd # which means capnslog logger , there isn't the same warn log.

Yeah --logger will be included in 3.4 (unreleased) and we plan to deprecate capnslog in 3.5. I think for this very reason zap is a much better logging solution. I have not dug into this much but feels like it could be a capnslog bug.

@xxx7xxxx
Copy link
Author

xxx7xxxx commented Jan 3, 2019

It is easy to reproduce this weird behavior. Just build repo, then start etcd with different loggers, use v3 etcdctl to get a random key. I think this kind of log should be printed.
Related issues: #8822 #9165

@hexfusion
Copy link
Contributor

It is easy to reproduce this weird behavior. Just build repo, then start etcd with different loggers, use v3 etcdctl to get a random key. I think this kind of log should be printed.

@longdeqidao, I understand we would love your help if you are interested in trying to resolve this.

@WIZARD-CXY
Copy link
Contributor

I came across the same bug here. @hexfusion let me take some time investigate and maybe fix this weird bug

@jingyih
Copy link
Contributor

jingyih commented Dec 11, 2019

Thanks @WIZARD-CXY. I just tried, it is reproducible.

@WIZARD-CXY
Copy link
Contributor

WIZARD-CXY commented Dec 16, 2019

@jingyih @hexfusion @xxx7xxxx I took some time to debug this and find that it is logger verbose settings that make this weird behavior.It makes different dicisions when logging

warningf("transport: http2Server.HandleStreams failed to read frame: %v", err) 

in http2_server.go

The warningf logging really print something when below func V returns true.

// V reports whether verbosity level l is at least the requested verbose level.
func V(l int) bool {
        return logger.V(l)
}

The input value l is defined as const logLevel = 2

when using zap

func (zl *zapGRPCLogger) V(l int) bool {
	// infoLog == 0
	if l <= 0 { // debug level, then we ignore info level in gRPC
		return !zl.lg.Core().Enabled(zapcore.DebugLevel)
	}
	return true
}

The capnslog uses verbose level 0

func NewLoggerV2(infoW, warningW, errorW io.Writer) LoggerV2 {
    return NewLoggerV2WithVerbosity(infoW, warningW, errorW, 0)
}
func (g *loggerT) V(l int) bool {
	return l <= g.v   #g.v is set to 0
}

From above capnslog's V function return false while zap V function returns true.So capnslog never prints the warning msg while zap prints it out.

I hope I make the above logic clear.

@WIZARD-CXY
Copy link
Contributor

I checked the code and it's not easy to ignore this error msg unless we modify the zap code.

@jingyih
Copy link
Contributor

jingyih commented Dec 16, 2019

By default the log level is INFO. So it is consistent that the zap logger prints the grpc warning? Maybe we should trace down what caused the warning in the first place and see if we can fix that? It looks like the client reset the stream while server still tries to read from it.

@WIZARD-CXY
Copy link
Contributor

From the related issue, I think this msg is spam and can be ignored grpc/grpc-go#1062 (comment)

@WIZARD-CXY
Copy link
Contributor

WIZARD-CXY commented Dec 17, 2019

Can the zap logger set the verbose level? I go through the code and doc, but didn't find it...

@jingyih
Copy link
Contributor

jingyih commented Dec 17, 2019

The flag:
https://github.com/etcd-io/etcd/blob/master/Documentation/op-guide/configuration.md#--log-level

The code:

copied.Level = zap.NewAtomicLevelAt(logutil.ConvertToZapLevel(cfg.LogLevel))

@WIZARD-CXY
Copy link
Contributor

ah, but this doesn't affect the verbose level

@jingyih
Copy link
Contributor

jingyih commented Dec 17, 2019

hmmm... Looks like it is by design? Maybe because we want to keep the old behavior?

// NewGRPCLoggerV2 converts "*zap.Logger" to "grpclog.LoggerV2".
// It discards all INFO level logging in gRPC, if debug level
// is not enabled in "*zap.Logger".
func NewGRPCLoggerV2(lcfg zap.Config) (grpclog.LoggerV2, error) {

cc @gyuho

@stale
Copy link

stale bot commented Apr 6, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants