Skip to content

Commit

Permalink
Log: debug user cancellation and log warning for rest
Browse files Browse the repository at this point in the history
The context error with cancel code is typically for user cancellation which
should be at debug level. For other error codes we should display a warning.

Fixes #9085
  • Loading branch information
spzala committed Jan 6, 2018
1 parent ea0a8ff commit 42388cf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
13 changes: 6 additions & 7 deletions etcdserver/api/v3rpc/lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ import (
"github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes"
pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
"github.com/coreos/etcd/lease"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

type LeaseServer struct {
Expand Down Expand Up @@ -110,9 +107,7 @@ func (ls *LeaseServer) leaseKeepAlive(stream pb.Lease_LeaseKeepAliveServer) erro
return nil
}
if err != nil {
ev, _ := status.FromError(err)
code := ev.Code()
if code == codes.Canceled || code == codes.DeadlineExceeded {
if isClientCtxErr(err) {
plog.Debugf("failed to receive lease keepalive request from gRPC stream (%q)", err.Error())
} else {
plog.Warningf("failed to receive lease keepalive request from gRPC stream (%q)", err.Error())
Expand Down Expand Up @@ -142,7 +137,11 @@ func (ls *LeaseServer) leaseKeepAlive(stream pb.Lease_LeaseKeepAliveServer) erro
resp.TTL = ttl
err = stream.Send(resp)
if err != nil {
plog.Debugf("failed to send lease keepalive response to gRPC stream (%q)", err.Error())
if isClientCtxErr(err) {
plog.Debugf("failed to send lease keepalive response to gRPC stream (%q)", err.Error())
} else {
plog.Warningf("failed to send lease keepalive response to gRPC stream (%q)", err.Error())
}
return err
}
}
Expand Down
6 changes: 6 additions & 0 deletions etcdserver/api/v3rpc/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,9 @@ func togRPCError(err error) error {
}
return grpcErr
}

func isClientCtxErr(err error) bool {
ev, _ := status.FromError(err)
code := ev.Code()
return code == codes.Canceled || code == codes.DeadlineExceeded
}
25 changes: 16 additions & 9 deletions etcdserver/api/v3rpc/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ import (
pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
"github.com/coreos/etcd/mvcc"
"github.com/coreos/etcd/mvcc/mvccpb"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

type watchServer struct {
Expand Down Expand Up @@ -143,9 +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 {
ev, _ := status.FromError(rerr)
code := ev.Code()
if code == codes.Canceled || code == codes.DeadlineExceeded {
if isClientCtxErr(rerr) {
plog.Debugf("failed to receive watch request from gRPC stream (%q)", rerr.Error())
} else {
plog.Warningf("failed to receive watch request from gRPC stream (%q)", rerr.Error())
Expand Down Expand Up @@ -348,7 +343,11 @@ func (sws *serverWatchStream) sendLoop() {

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

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

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

Expand All @@ -381,7 +384,11 @@ func (sws *serverWatchStream) sendLoop() {
for _, v := range pending[wid] {
mvcc.ReportEventReceived(len(v.Events))
if err := sws.gRPCStream.Send(v); err != nil {
plog.Debugf("failed to send pending watch response to gRPC stream (%q)", err.Error())
if isClientCtxErr(err) {
plog.Debugf("failed to send pending watch response to gRPC stream (%q)", err.Error())
} else {
plog.Warningf("failed to send pending watch response to gRPC stream (%q)", err.Error())
}
return
}
}
Expand Down

0 comments on commit 42388cf

Please sign in to comment.