Skip to content

Commit 493063f

Browse files
authored
Merge pull request authzed#1864 from jzelinskie/less-verbose-logging
cmd/server: log dispatching at debug level
2 parents a244ed1 + 2d43e7a commit 493063f

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed

internal/datastore/crdb/crdb_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ func newCRDBWithUser(t *testing.T, pool *dockertest.Pool) (adminConn *pgx.Conn,
303303
require.NoError(t, rootCertFile.Close())
304304

305305
resource, err := pool.RunWithOptions(&dockertest.RunOptions{
306-
Repository: "cockroachdb/cockroach",
306+
Repository: "mirror.gcr.io/cockroachdb/cockroach",
307307
Tag: testdatastore.CRDBTestVersionTag,
308308
Cmd: []string{"start-single-node", "--certs-dir", "/certs", "--accept-sql-without-tls"},
309309
Mounts: []string{certDir + ":/certs"},

internal/testserver/datastore/crdb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func RunCRDBForTesting(t testing.TB, bridgeNetworkName string) RunningEngineForT
4040
name := fmt.Sprintf("crds-%s", uuid.New().String())
4141
resource, err := pool.RunWithOptions(&dockertest.RunOptions{
4242
Name: name,
43-
Repository: "cockroachdb/cockroach",
43+
Repository: "mirror.gcr.io/cockroachdb/cockroach",
4444
Tag: CRDBTestVersionTag,
4545
Cmd: []string{"start-single-node", "--insecure", "--max-offset=50ms"},
4646
NetworkID: bridgeNetworkName,

internal/testserver/datastore/mysql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func RunMySQLForTestingWithOptions(t testing.TB, options MySQLTesterOptions, bri
5858
name := fmt.Sprintf("mysql-%s", uuid.New().String())
5959
resource, err := pool.RunWithOptions(&dockertest.RunOptions{
6060
Name: name,
61-
Repository: "mysql",
61+
Repository: "mirror.gcr.io/library/mysql",
6262
Tag: containerImageTag,
6363
Env: []string{"MYSQL_ROOT_PASSWORD=secret"},
6464
// increase max connections (default 151) to accommodate tests using the same docker container

internal/testserver/datastore/postgres.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func RunPostgresForTestingWithCommitTimestamps(t testing.TB, bridgeNetworkName s
6969

7070
postgres, err := pool.RunWithOptions(&dockertest.RunOptions{
7171
Name: postgresContainerHostname,
72-
Repository: "postgres",
72+
Repository: "mirror.gcr.io/library/postgres",
7373
Tag: pgVersion,
7474
Env: []string{
7575
"POSTGRES_USER=" + POSTGRES_TEST_USER,
@@ -173,7 +173,7 @@ func (b *postgresTester) runPgbouncerForTesting(t testing.TB, pool *dockertest.P
173173

174174
pgbouncer, err := pool.RunWithOptions(&dockertest.RunOptions{
175175
Name: pgbouncerContainerHostname,
176-
Repository: "edoburu/pgbouncer",
176+
Repository: "mirror.gcr.io/edoburu/pgbouncer",
177177
Tag: "latest",
178178
Env: []string{
179179
"DB_USER=" + POSTGRES_TEST_USER,

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)