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 errors with Canceled or DeadlineExceeded code are typically for user
cancellation which should be at debug level. For other error codes we should
display a warning.

Fixes etcd-io#9085
  • Loading branch information
spzala committed Jan 6, 2018
1 parent 4293f21 commit 96c1c19
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 10 additions & 1 deletion etcdserver/api/v3rpc/lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ 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 @@ -107,7 +110,13 @@ func (ls *LeaseServer) leaseKeepAlive(stream pb.Lease_LeaseKeepAliveServer) erro
return nil
}
if err != nil {
plog.Debugf("failed to receive lease keepalive request from gRPC stream (%q)", err.Error())
ev, _ := status.FromError(err)
code := ev.Code()
if code == codes.Canceled || code == codes.DeadlineExceeded {
plog.Debugf("failed to receive lease 123 keepalive request from gRPC stream (%q)", err.Error())
} else {
plog.Warningf("failed to receive lease keepalive request from gRPC stream (%q)", err.Error())
}
return err
}

Expand Down
9 changes: 7 additions & 2 deletions etcdserver/api/v3rpc/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ 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 @@ -140,8 +143,10 @@ func (ws *watchServer) Watch(stream pb.Watch_WatchServer) (err error) {
// deadlock when calling sws.close().
go func() {
if rerr := sws.recvLoop(); rerr != nil {
if stream.Context().Err() == context.Canceled {
plog.Debugf("failed to receive watch request from gRPC stream 11 (%q)", rerr.Error())
ev, _ := status.FromError(rerr)
code := ev.Code()
if code == codes.Canceled || code == codes.DeadlineExceeded {
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

0 comments on commit 96c1c19

Please sign in to comment.