etcdserver: support structured logging
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
This commit is contained in:
@ -18,8 +18,11 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/coreos/etcd/auth"
|
||||
pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
|
||||
"github.com/coreos/etcd/etcdserver/membership"
|
||||
@ -84,7 +87,7 @@ type Authenticator interface {
|
||||
}
|
||||
|
||||
func (s *EtcdServer) Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeResponse, error) {
|
||||
defer warnOfExpensiveReadOnlyRangeRequest(time.Now(), r)
|
||||
defer warnOfExpensiveReadOnlyRangeRequest(s.getLogger(), time.Now(), r)
|
||||
|
||||
if !r.Serializable {
|
||||
err := s.linearizableReadNotify(ctx)
|
||||
@ -135,7 +138,7 @@ func (s *EtcdServer) Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse
|
||||
return checkTxnAuth(s.authStore, ai, r)
|
||||
}
|
||||
|
||||
defer warnOfExpensiveReadOnlyRangeRequest(time.Now(), r)
|
||||
defer warnOfExpensiveReadOnlyRangeRequest(s.getLogger(), time.Now(), r)
|
||||
|
||||
get := func() { resp, err = s.applyV3Base.Txn(r) }
|
||||
if serr := s.doSerialize(ctx, chk, get); serr != nil {
|
||||
@ -358,12 +361,22 @@ func (s *EtcdServer) Authenticate(ctx context.Context, r *pb.AuthenticateRequest
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lg := s.getLogger()
|
||||
|
||||
var resp proto.Message
|
||||
for {
|
||||
checkedRevision, err := s.AuthStore().CheckPassword(r.Name, r.Password)
|
||||
if err != nil {
|
||||
if err != auth.ErrAuthNotEnabled {
|
||||
plog.Errorf("invalid authentication request to user %s was issued", r.Name)
|
||||
if lg != nil {
|
||||
lg.Warn(
|
||||
"invalid authentication was requested",
|
||||
zap.String("user", r.Name),
|
||||
zap.Error(err),
|
||||
)
|
||||
} else {
|
||||
plog.Errorf("invalid authentication request to user %s was issued", r.Name)
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@ -386,7 +399,12 @@ func (s *EtcdServer) Authenticate(ctx context.Context, r *pb.AuthenticateRequest
|
||||
if checkedRevision == s.AuthStore().Revision() {
|
||||
break
|
||||
}
|
||||
plog.Infof("revision when password checked is obsolete, retrying")
|
||||
|
||||
if lg != nil {
|
||||
lg.Info("revision when password checked became stale; retrying")
|
||||
} else {
|
||||
plog.Infof("revision when password checked is obsolete, retrying")
|
||||
}
|
||||
}
|
||||
|
||||
return resp.(*pb.AuthenticateResponse), nil
|
||||
@ -626,13 +644,18 @@ func (s *EtcdServer) linearizableReadLoop() {
|
||||
s.readNotifier = nextnr
|
||||
s.readMu.Unlock()
|
||||
|
||||
lg := s.getLogger()
|
||||
cctx, cancel := context.WithTimeout(context.Background(), s.Cfg.ReqTimeout())
|
||||
if err := s.r.ReadIndex(cctx, ctx); err != nil {
|
||||
cancel()
|
||||
if err == raft.ErrStopped {
|
||||
return
|
||||
}
|
||||
plog.Errorf("failed to get read index from raft: %v", err)
|
||||
if lg != nil {
|
||||
lg.Warn("failed to get read index from Raft", zap.Error(err))
|
||||
} else {
|
||||
plog.Errorf("failed to get read index from raft: %v", err)
|
||||
}
|
||||
nr.notify(err)
|
||||
continue
|
||||
}
|
||||
@ -649,10 +672,22 @@ func (s *EtcdServer) linearizableReadLoop() {
|
||||
if !done {
|
||||
// a previous request might time out. now we should ignore the response of it and
|
||||
// continue waiting for the response of the current requests.
|
||||
plog.Warningf("ignored out-of-date read index response (want %v, got %v)", rs.RequestCtx, ctx)
|
||||
if lg != nil {
|
||||
lg.Warn(
|
||||
"ignored out-of-date read index response",
|
||||
zap.String("ctx-expected", fmt.Sprintf("%+v", string(rs.RequestCtx))),
|
||||
zap.String("ctx-got", fmt.Sprintf("%+v", string(ctx))),
|
||||
)
|
||||
} else {
|
||||
plog.Warningf("ignored out-of-date read index response (want %v, got %v)", rs.RequestCtx, ctx)
|
||||
}
|
||||
}
|
||||
case <-time.After(s.Cfg.ReqTimeout()):
|
||||
plog.Warningf("timed out waiting for read index response")
|
||||
if lg != nil {
|
||||
lg.Warn("timed out waiting for read index response", zap.Duration("timeout", s.Cfg.ReqTimeout()))
|
||||
} else {
|
||||
plog.Warningf("timed out waiting for read index response")
|
||||
}
|
||||
nr.notify(ErrTimeout)
|
||||
timeout = true
|
||||
case <-s.stopping:
|
||||
|
Reference in New Issue
Block a user