etcdserver: add grpc interceptor to log info on incoming request to

etcdserver

To improve debuggability of etcd v3.1. Added a grpc interceptor to log
info on incoming requests to etcd server. The log output includes remote
client info, request content (with value field redacted), request
handling latency, response size, etc.

Dependency on zap logger and grpc_middleware is removed during
backporting.

Added checking in logging interceptor. If debug level is disabled, skip
logUnaryRequestStats() to avoid potential performance degradation. (PR #10021)
This commit is contained in:
Jingyi Hu 2018-08-17 17:06:13 -07:00
parent 4855ca62b5
commit dd2803c4a6

View File

@ -93,7 +93,7 @@ func logUnaryRequestStats(ctx context.Context, info *grpc.UnaryServerInfo, start
reqContent = _req.String()
}
if _resp != nil {
respCount = _resp.GetCount()
respCount = _resp.Count
respSize = _resp.Size()
}
case *pb.PutResponse:
@ -116,13 +116,13 @@ func logUnaryRequestStats(ctx context.Context, info *grpc.UnaryServerInfo, start
reqContent = _req.String()
}
if _resp != nil {
respCount = _resp.GetDeleted()
respCount = _resp.Deleted
respSize = _resp.Size()
}
case *pb.TxnResponse:
_req, ok := req.(*pb.TxnRequest)
if ok && _resp != nil {
if _resp.GetSucceeded() { // determine the 'actual' count and size of request based on success or failure
if _resp.Succeeded { // determine the 'actual' count and size of request based on success or failure
reqCount = int64(len(_req.GetSuccess()))
reqSize = 0
for _, r := range _req.GetSuccess() {