Skip to content

Commit

Permalink
etcdserver,embed: discard gRPC info logs when debug is off
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
  • Loading branch information
gyuho committed Jan 2, 2018
1 parent 9a50255 commit 9e11ef3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions embed/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
AuthToken: cfg.AuthToken,
InitialCorruptCheck: cfg.ExperimentalInitialCorruptCheck,
CorruptCheckTime: cfg.ExperimentalCorruptCheckTime,
Debug: cfg.Debug,
}

if e.Server, err = etcdserver.NewServer(srvcfg); err != nil {
Expand Down
13 changes: 9 additions & 4 deletions etcdserver/api/v3rpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package v3rpc

import (
"crypto/tls"
"io/ioutil"
"math"
"os"

Expand All @@ -36,10 +37,6 @@ const (
maxSendBytes = math.MaxInt32
)

func init() {
grpclog.SetLoggerV2(grpclog.NewLoggerV2(os.Stderr, os.Stderr, os.Stderr))
}

func Server(s *etcdserver.EtcdServer, tls *tls.Config, gopts ...grpc.ServerOption) *grpc.Server {
var opts []grpc.ServerOption
opts = append(opts, grpc.CustomCodec(&codec{}))
Expand Down Expand Up @@ -70,5 +67,13 @@ func Server(s *etcdserver.EtcdServer, tls *tls.Config, gopts ...grpc.ServerOptio
// set zero values for metrics registered for this grpc server
grpc_prometheus.Register(grpcServer)

if s.Cfg.Debug {
grpc.EnableTracing = true
// enable info, warning, error
grpclog.SetLoggerV2(grpclog.NewLoggerV2(os.Stderr, os.Stderr, os.Stderr))
} else {
// only discard info
grpclog.SetLoggerV2(grpclog.NewLoggerV2(ioutil.Discard, os.Stderr, os.Stderr))
}
return grpcServer
}
2 changes: 2 additions & 0 deletions etcdserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ type ServerConfig struct {
// before serving any peer/client traffic.
InitialCorruptCheck bool
CorruptCheckTime time.Duration

Debug bool
}

// VerifyBootstrap sanity-checks the initial config for bootstrap case
Expand Down

0 comments on commit 9e11ef3

Please sign in to comment.