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) }