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>
This commit is contained in:
Julien Pivotto 2026-02-26 16:59:21 +01:00
parent 3675a5e56c
commit 8edc676cbe
2 changed files with 9 additions and 0 deletions

View file

@ -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 {

View file

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