Skip to content

Commit f30c5cb

Browse files
committed
cmd/server: log dispatching at debug level
Prior to this change, dispatch logs can become VERY noisy and most use cases don't necessitate them.
1 parent 095ffd3 commit f30c5cb

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

pkg/cmd/server/defaults.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,26 @@ func MetricsHandler(telemetryRegistry *prometheus.Registry, c *Config) http.Hand
118118
return mux
119119
}
120120

121-
// the server has a deadline set, so we consider it a normal condition
122-
// this makes sure we don't log them as errors
123121
var defaultCodeToLevel = grpclog.WithLevels(func(code codes.Code) grpclog.Level {
124122
if code == codes.DeadlineExceeded {
123+
// The server has a deadline set, so we consider it a normal condition.
124+
// This ensures that we don't log them as errors.
125125
return grpclog.LevelInfo
126126
}
127127
return grpclog.DefaultServerCodeToLevel(code)
128128
})
129129

130+
var dispatchDefaultCodeToLevel = grpclog.WithLevels(func(code codes.Code) grpclog.Level {
131+
switch code {
132+
case codes.OK, codes.Canceled:
133+
return grpclog.LevelDebug
134+
case codes.NotFound, codes.AlreadyExists, codes.InvalidArgument, codes.Unauthenticated:
135+
return grpclog.LevelWarn
136+
default:
137+
return grpclog.DefaultServerCodeToLevel(code)
138+
}
139+
})
140+
130141
var durationFieldOption = grpclog.WithDurationField(func(duration time.Duration) grpclog.Fields {
131142
return grpclog.Fields{"grpc.time_ms", duration.Milliseconds()}
132143
})
@@ -376,15 +387,15 @@ func DefaultDispatchMiddleware(logger zerolog.Logger, authFunc grpcauth.AuthFunc
376387
return []grpc.UnaryServerInterceptor{
377388
requestid.UnaryServerInterceptor(requestid.GenerateIfMissing(true)),
378389
logmw.UnaryServerInterceptor(logmw.ExtractMetadataField(string(requestmeta.RequestIDKey), "requestID")),
379-
grpclog.UnaryServerInterceptor(InterceptorLogger(logger), defaultCodeToLevel, durationFieldOption, traceIDFieldOption),
390+
grpclog.UnaryServerInterceptor(InterceptorLogger(logger), dispatchDefaultCodeToLevel, durationFieldOption, traceIDFieldOption),
380391
grpcMetricsUnaryInterceptor,
381392
grpcauth.UnaryServerInterceptor(authFunc),
382393
datastoremw.UnaryServerInterceptor(ds),
383394
servicespecific.UnaryServerInterceptor,
384395
}, []grpc.StreamServerInterceptor{
385396
requestid.StreamServerInterceptor(requestid.GenerateIfMissing(true)),
386397
logmw.StreamServerInterceptor(logmw.ExtractMetadataField(string(requestmeta.RequestIDKey), "requestID")),
387-
grpclog.StreamServerInterceptor(InterceptorLogger(logger), defaultCodeToLevel, durationFieldOption, traceIDFieldOption),
398+
grpclog.StreamServerInterceptor(InterceptorLogger(logger), dispatchDefaultCodeToLevel, durationFieldOption, traceIDFieldOption),
388399
grpcMetricsStreamingInterceptor,
389400
grpcauth.StreamServerInterceptor(authFunc),
390401
datastoremw.StreamServerInterceptor(ds),

0 commit comments

Comments
 (0)