From 8edc676cbe73b348386ce5db0272dff72ccead76 Mon Sep 17 00:00:00 2001 From: Julien Pivotto <291750+roidelapluie@users.noreply.github.com> Date: Thu, 26 Feb 2026 16:59:21 +0100 Subject: [PATCH] config: inject TSDBConfig defaults in Load for empty config bodies When the config body is empty, UnmarshalYAML is never called, so the TSDBConfig nil injection added there never ran. Replicate the same guard in Load, which is the entry point that already handles this case for other defaults via DefaultConfig. Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com> --- config/config.go | 7 +++++++ config/config_test.go | 2 ++ 2 files changed, 9 insertions(+) diff --git a/config/config.go b/config/config.go index 2ccca31b4f..cb45347e41 100644 --- a/config/config.go +++ b/config/config.go @@ -83,6 +83,13 @@ func Load(s string, logger *slog.Logger) (*Config, error) { return nil, err } + // When the config body is empty, UnmarshalYAML is never called, so + // TSDBConfig may still be nil. + if cfg.StorageConfig.TSDBConfig == nil { + retention := DefaultTSDBRetentionConfig + cfg.StorageConfig.TSDBConfig = &TSDBConfig{Retention: &retention} + } + b := labels.NewScratchBuilder(0) cfg.GlobalConfig.ExternalLabels.Range(func(v labels.Label) { newV := os.Expand(v.Value, func(s string) string { diff --git a/config/config_test.go b/config/config_test.go index dbc221329d..a845fac719 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -2665,6 +2665,8 @@ func TestEmptyConfig(t *testing.T) { require.NoError(t, err) exp := DefaultConfig exp.loaded = true + retention := DefaultTSDBRetentionConfig + exp.StorageConfig.TSDBConfig = &TSDBConfig{Retention: &retention} require.Equal(t, exp, *c) require.Equal(t, 75, c.Runtime.GoGC) }