Address review comments a.d. logging.

This commit is contained in:
Piotr Tabor 2021-04-15 17:54:37 +02:00
parent fad6391745
commit b47c5fcc12
3 changed files with 19 additions and 6 deletions

View File

@ -21,12 +21,11 @@ import (
"os"
"go.etcd.io/etcd/client/pkg/v3/logutil"
"go.uber.org/zap/zapgrpc"
"google.golang.org/grpc/grpclog"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zapgrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/grpclog"
)
// GetLogger returns the logger.

View File

@ -509,7 +509,14 @@ func (e *Etcd) servePeers() (err error) {
ErrorLog: defaultLog.New(ioutil.Discard, "", 0), // do not log user error
}
go srv.Serve(m.Match(cmux.Any()))
p.serve = func() error { return m.Serve() }
p.serve = func() error {
e.cfg.logger.Info(
"cmux::serve",
zap.String("address", u),
zap.String("cmuxp", fmt.Sprintf("%p", m)),
)
return m.Serve()
}
p.close = func(ctx context.Context) error {
// gracefully shutdown http.Server
// close open listeners, idle connections
@ -517,12 +524,16 @@ func (e *Etcd) servePeers() (err error) {
e.cfg.logger.Info(
"stopping serving peer traffic",
zap.String("address", u),
zap.String("cmuxp", fmt.Sprintf("%p", m)),
)
stopServers(ctx, &servers{secure: peerTLScfg != nil, grpc: gs, http: srv})
e.cfg.logger.Info(
"stopped serving peer traffic",
zap.String("address", u),
zap.String("cmuxp", fmt.Sprintf("%p", m)),
)
m.Close()
e.cfg.logger.Info("Closed", zap.String("cmuxp", fmt.Sprintf("%p", m)))
return nil
}
}

View File

@ -57,8 +57,9 @@ func startEtcdOrProxyV2(args []string) {
err := cfg.parse(args[1:])
lg := cfg.ec.GetLogger()
cfg.ec.SetupGlobalLoggers()
// If we failed to parse the whole configuration, print the error using
// preferably the resolved logger from the config,
// but if does not exists, create a new temporary logger.
if lg == nil {
var zapError error
// use this logger
@ -78,6 +79,8 @@ func startEtcdOrProxyV2(args []string) {
os.Exit(1)
}
cfg.ec.SetupGlobalLoggers()
defer func() {
logger := cfg.ec.GetLogger()
if logger != nil {