diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go index 5bea62e755..28e072363d 100644 --- a/cmd/prometheus/main.go +++ b/cmd/prometheus/main.go @@ -617,7 +617,31 @@ func main() { if cfgFile.StorageConfig.TSDBConfig != nil { cfg.tsdb.OutOfOrderTimeWindow = cfgFile.StorageConfig.TSDBConfig.OutOfOrderTimeWindow } + + // Set Go runtime parameters before we get too far into initialization. updateGoGC(cfgFile, logger) + if cfg.maxprocsEnable { + l := func(format string, a ...interface{}) { + logger.Info(fmt.Sprintf(strings.TrimPrefix(format, "maxprocs: "), a...), "component", "automaxprocs") + } + if _, err := maxprocs.Set(maxprocs.Logger(l)); err != nil { + logger.Warn("Failed to set GOMAXPROCS automatically", "component", "automaxprocs", "err", err) + } + } + + if cfg.memlimitEnable { + if _, err := memlimit.SetGoMemLimitWithOpts( + memlimit.WithRatio(cfg.memlimitRatio), + memlimit.WithProvider( + memlimit.ApplyFallback( + memlimit.FromCgroup, + memlimit.FromSystem, + ), + ), + ); err != nil { + logger.Warn("automemlimit", "msg", "Failed to set GOMEMLIMIT automatically", "err", err) + } + } // Now that the validity of the config is established, set the config // success metrics accordingly, although the config isn't really loaded @@ -765,29 +789,6 @@ func main() { ruleManager *rules.Manager ) - if cfg.maxprocsEnable { - l := func(format string, a ...interface{}) { - logger.Info(fmt.Sprintf(strings.TrimPrefix(format, "maxprocs: "), a...), "component", "automaxprocs") - } - if _, err := maxprocs.Set(maxprocs.Logger(l)); err != nil { - logger.Warn("Failed to set GOMAXPROCS automatically", "component", "automaxprocs", "err", err) - } - } - - if cfg.memlimitEnable { - if _, err := memlimit.SetGoMemLimitWithOpts( - memlimit.WithRatio(cfg.memlimitRatio), - memlimit.WithProvider( - memlimit.ApplyFallback( - memlimit.FromCgroup, - memlimit.FromSystem, - ), - ), - ); err != nil { - logger.Warn("automemlimit", "msg", "Failed to set GOMEMLIMIT automatically", "err", err) - } - } - if !agentMode { opts := promql.EngineOpts{ Logger: logger.With("component", "query engine"),