[BUGFIX] Top-level: Update GOGC before loading TSDB

We should use the configured value, or Prometheus' default of 75%, while
initializing and loading the WAL.

Since the Go default is 100%, most Prometheus users would experience
higher memory usage before the value is configured.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
Bryan Boreham 2025-04-27 16:49:53 +01:00 committed by machine424
parent a8a4b7ce69
commit 284914c8db
No known key found for this signature in database
GPG Key ID: A4B001A4FDEE017D

View File

@ -617,6 +617,7 @@ func main() {
if cfgFile.StorageConfig.TSDBConfig != nil {
cfg.tsdb.OutOfOrderTimeWindow = cfgFile.StorageConfig.TSDBConfig.OutOfOrderTimeWindow
}
updateGoGC(cfgFile, logger)
// Now that the validity of the config is established, set the config
// success metrics accordingly, although the config isn't really loaded
@ -1472,6 +1473,14 @@ func reloadConfig(filename string, enableExemplarStorage bool, logger *slog.Logg
return fmt.Errorf("one or more errors occurred while applying the new configuration (--config.file=%q)", filename)
}
updateGoGC(conf, logger)
noStepSuqueryInterval.Set(conf.GlobalConfig.EvaluationInterval)
timingsLogger.Info("Completed loading of configuration file", "filename", filename, "totalDuration", time.Since(start))
return nil
}
func updateGoGC(conf *config.Config, logger *slog.Logger) {
oldGoGC := debug.SetGCPercent(conf.Runtime.GoGC)
if oldGoGC != conf.Runtime.GoGC {
logger.Info("updated GOGC", "old", oldGoGC, "new", conf.Runtime.GoGC)
@ -1482,10 +1491,6 @@ func reloadConfig(filename string, enableExemplarStorage bool, logger *slog.Logg
} else {
os.Setenv("GOGC", "off")
}
noStepSuqueryInterval.Set(conf.GlobalConfig.EvaluationInterval)
timingsLogger.Info("Completed loading of configuration file", "filename", filename, "totalDuration", time.Since(start))
return nil
}
func startsOrEndsWithQuote(s string) bool {