From 3cae346b44f035a0a2207c3c2bbdf0a5597da5fc Mon Sep 17 00:00:00 2001 From: Renato Costa Date: Fri, 21 Oct 2022 19:48:17 +0000 Subject: [PATCH] server: write pebble log messages to storage channel Previously, when setting up the server, the pebble engine would be initialized with Pebble's default logger. The reason for this is that the pebble initialization code calls `EnsureDefaults` on the configuration options _before_ checking if the `options.Logger` is nil/unset. At that point, it will never be unset, as `EnsureDefaults` will set the logger to `pebble.DefaultLogger` if it was not previously set. This change overwrites the pebble logger if its found to be the `DefaultLogger`. We never want to use pebble's `DefaultLogger` in CRDB as that would mean pebble would use the standard library `log` package, making every message emitted by Pebble to be treated as `INFO` level messages, regardless of severity (including `log.Fatal` calls). Related to #83079. Fixes #72683. Fixes #90483. Release note: None. --- pkg/storage/pebble.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/storage/pebble.go b/pkg/storage/pebble.go index 67244a99e23c..52d7e318a4fb 100644 --- a/pkg/storage/pebble.go +++ b/pkg/storage/pebble.go @@ -853,7 +853,11 @@ func NewPebble(ctx context.Context, cfg PebbleConfig) (p *Pebble, err error) { storeIDContainer := &base.StoreIDContainer{} logCtx = logtags.AddTag(logCtx, "s", storeIDContainer) - if cfg.Opts.Logger == nil { + // If no logger was passed, the previous call to `EnsureDefaults` on + // `cfg.Opts` will set the logger to pebble's `DefaultLogger`. In + // crdb, we want pebble-related logs to go to the storage channel, + // so we update the logger here accordingly. + if cfg.Opts.Logger == nil || cfg.Opts.Logger == pebble.DefaultLogger { cfg.Opts.Logger = pebbleLogger{ ctx: logCtx, depth: 1,