in pkg/utils/grpc.go [28:43]
func LogInterceptor() grpc.UnaryServerInterceptor {
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
start := time.Now()
reporter := metrics.NewStatsReporter()
ctxDeadline, _ := ctx.Deadline()
klog.V(5).InfoS("request", "method", info.FullMethod, "deadline", time.Until(ctxDeadline).String())
resp, err := handler(ctx, req)
s, _ := status.FromError(err)
klog.V(5).InfoS("response", "method", info.FullMethod, "duration", time.Since(start).String(), "code", s.Code().String(), "message", s.Message())
reporter.ReportGRPCRequest(ctx, time.Since(start).Seconds(), info.FullMethod, s.Code().String(), s.Message())
return resp, err
}
}