Skip to content

Commit

Permalink
Address review comments a.d. logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
ptabor committed Apr 15, 2021
1 parent fad6391 commit b47c5fc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
5 changes: 2 additions & 3 deletions server/embed/config_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 12 additions & 1 deletion server/embed/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,20 +509,31 @@ 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
// until context cancel or time-out
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
}
}
Expand Down
7 changes: 5 additions & 2 deletions server/etcdmain/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -78,6 +79,8 @@ func startEtcdOrProxyV2(args []string) {
os.Exit(1)
}

cfg.ec.SetupGlobalLoggers()

defer func() {
logger := cfg.ec.GetLogger()
if logger != nil {
Expand Down

0 comments on commit b47c5fc

Please sign in to comment.