Skip to content

Commit

Permalink
Merge pull request #9080 from gyuho/log-debug
Browse files Browse the repository at this point in the history
etcdserver: log stream error with debug level, silence gRPC server info level logs
  • Loading branch information
gyuho authored Jan 2, 2018
2 parents e6a46a0 + e567d94 commit 916d9db
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 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
18 changes: 15 additions & 3 deletions etcdserver/api/v3rpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ package v3rpc

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

"github.com/coreos/etcd/etcdserver"
pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
Expand All @@ -36,9 +38,8 @@ const (
maxSendBytes = math.MaxInt32
)

func init() {
grpclog.SetLoggerV2(grpclog.NewLoggerV2(os.Stderr, os.Stderr, os.Stderr))
}
// integration tests call this multiple times, which is racey in gRPC side
var grpclogOnce sync.Once

func Server(s *etcdserver.EtcdServer, tls *tls.Config, gopts ...grpc.ServerOption) *grpc.Server {
var opts []grpc.ServerOption
Expand Down Expand Up @@ -70,5 +71,16 @@ 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)

grpclogOnce.Do(func() {
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
}
4 changes: 2 additions & 2 deletions etcdserver/api/v3rpc/lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (ls *LeaseServer) leaseKeepAlive(stream pb.Lease_LeaseKeepAliveServer) erro
return nil
}
if err != nil {
plog.Warningf("failed to receive lease keepalive request from gRPC stream (%q)", err.Error())
plog.Debugf("failed to receive lease keepalive request from gRPC stream (%q)", err.Error())
return err
}

Expand All @@ -133,7 +133,7 @@ func (ls *LeaseServer) leaseKeepAlive(stream pb.Lease_LeaseKeepAliveServer) erro
resp.TTL = ttl
err = stream.Send(resp)
if err != nil {
plog.Warningf("failed to send lease keepalive response to gRPC stream (%q)", err.Error())
plog.Debugf("failed to send lease keepalive response to gRPC stream (%q)", err.Error())
return err
}
}
Expand Down
8 changes: 4 additions & 4 deletions etcdserver/api/v3rpc/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (ws *watchServer) Watch(stream pb.Watch_WatchServer) (err error) {
// deadlock when calling sws.close().
go func() {
if rerr := sws.recvLoop(); rerr != nil {
plog.Warningf("failed to receive watch request from gRPC stream (%q)", rerr.Error())
plog.Debugf("failed to receive watch request from gRPC stream (%q)", rerr.Error())
errc <- rerr
}
}()
Expand Down Expand Up @@ -339,7 +339,7 @@ func (sws *serverWatchStream) sendLoop() {

mvcc.ReportEventReceived(len(evs))
if err := sws.gRPCStream.Send(wr); err != nil {
plog.Warningf("failed to send watch response to gRPC stream (%q)", err.Error())
plog.Debugf("failed to send watch response to gRPC stream (%q)", err.Error())
return
}

Expand All @@ -356,7 +356,7 @@ func (sws *serverWatchStream) sendLoop() {
}

if err := sws.gRPCStream.Send(c); err != nil {
plog.Warningf("failed to send watch control response to gRPC stream (%q)", err.Error())
plog.Debugf("failed to send watch control response to gRPC stream (%q)", err.Error())
return
}

Expand All @@ -372,7 +372,7 @@ func (sws *serverWatchStream) sendLoop() {
for _, v := range pending[wid] {
mvcc.ReportEventReceived(len(v.Events))
if err := sws.gRPCStream.Send(v); err != nil {
plog.Warningf("failed to send pending watch response to gRPC stream (%q)", err.Error())
plog.Debugf("failed to send pending watch response to gRPC stream (%q)", err.Error())
return
}
}
Expand Down
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
4 changes: 0 additions & 4 deletions tools/functional-tester/etcd-tester/stresser.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@ package main

import (
"fmt"
"os"
"strings"
"sync"
"time"

"golang.org/x/time/rate"
"google.golang.org/grpc/grpclog"
)

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

type Stresser interface {
// Stress starts to stress the etcd cluster
Stress() error
Expand Down

0 comments on commit 916d9db

Please sign in to comment.