mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdserver: print warn log when failed to apply request
This commit is contained in:
@@ -936,11 +936,19 @@ func (as *authStore) isOpPermitted(userName string, revision uint64, key, rangeE
|
||||
}
|
||||
rev := as.Revision()
|
||||
if revision < rev {
|
||||
as.lg.Warn("request auth revision is less than current node auth revision",
|
||||
zap.Uint64("current node auth revision", rev),
|
||||
zap.Uint64("request auth revision", revision),
|
||||
zap.ByteString("request key", key),
|
||||
zap.Error(ErrAuthOldRevision))
|
||||
if as.lg != nil {
|
||||
as.lg.Warn("request auth revision is less than current node auth revision",
|
||||
zap.Uint64("current node auth revision", rev),
|
||||
zap.Uint64("request auth revision", revision),
|
||||
zap.ByteString("request key", key),
|
||||
zap.Error(ErrAuthOldRevision))
|
||||
} else {
|
||||
plog.Warningf("request auth revision is less than current node auth revision,"+
|
||||
"current node auth revision is %d,"+
|
||||
"request auth revision is %d,"+
|
||||
"request key is %s, "+
|
||||
"err is %v", rev, revision, key, ErrAuthOldRevision)
|
||||
}
|
||||
return ErrAuthOldRevision
|
||||
}
|
||||
|
||||
|
||||
@@ -116,6 +116,9 @@ func (a *applierV3backend) Apply(r *pb.InternalRaftRequest) *applyResult {
|
||||
ar := &applyResult{}
|
||||
defer func(start time.Time) {
|
||||
warnOfExpensiveRequest(a.s.getLogger(), start, &pb.InternalRaftStringer{Request: r}, ar.resp, ar.err)
|
||||
if ar.err != nil {
|
||||
warnOfFailedRequest(a.s.getLogger(), start, &pb.InternalRaftStringer{Request: r}, ar.resp, ar.err)
|
||||
}
|
||||
}(time.Now())
|
||||
|
||||
// call into a.s.applyV3.F instead of a.F so upper appliers can check individual calls
|
||||
|
||||
@@ -111,6 +111,25 @@ func warnOfExpensiveRequest(lg *zap.Logger, now time.Time, reqStringer fmt.Strin
|
||||
warnOfExpensiveGenericRequest(lg, now, reqStringer, "", resp, err)
|
||||
}
|
||||
|
||||
func warnOfFailedRequest(lg *zap.Logger, now time.Time, reqStringer fmt.Stringer, respMsg proto.Message, err error) {
|
||||
var resp string
|
||||
if !isNil(respMsg) {
|
||||
resp = fmt.Sprintf("size:%d", proto.Size(respMsg))
|
||||
}
|
||||
d := time.Since(now)
|
||||
if lg != nil {
|
||||
lg.Warn(
|
||||
"failed to apply request",
|
||||
zap.Duration("took", d),
|
||||
zap.String("request", reqStringer.String()),
|
||||
zap.String("response", resp),
|
||||
zap.Error(err),
|
||||
)
|
||||
} else {
|
||||
plog.Warningf("failed to apply request %q with response %q took (%v) to execute, err is %v", reqStringer.String(), resp, d, err)
|
||||
}
|
||||
}
|
||||
|
||||
func warnOfExpensiveReadOnlyTxnRequest(lg *zap.Logger, now time.Time, r *pb.TxnRequest, txnResponse *pb.TxnResponse, err error) {
|
||||
reqStringer := pb.NewLoggableTxnRequest(r)
|
||||
var resp string
|
||||
|
||||
Reference in New Issue
Block a user