Skip to content

Commit 5082b06

Browse files
authored
feat: promote auto-gomemlimit to a regular flag (#5464)
change feature flag `auto-gomemlimit` to a regular flag `--auto-gomemlimit` and add a new flag `--auto-gomemlimit.refresh-interval`. The flag layout is identical to the one used in prometheus, except that this feature is enabled by default in prometheus and disabled by default in alertmanager. Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
1 parent a7577f8 commit 5082b06

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

cmd/alertmanager/main.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,12 @@ func run() int {
6666
getConcurrency = kingpin.Flag("web.get-concurrency", "Maximum number of GET requests processed concurrently. If negative or zero, the limit is GOMAXPROC or 8, whichever is larger.").Default("0").Int()
6767
httpTimeout = kingpin.Flag("web.timeout", "Timeout for HTTP requests. If negative or zero, no timeout is set.").Default("0").Duration()
6868

69-
memlimitRatio = kingpin.Flag("auto-gomemlimit.ratio", "The ratio of reserved GOMEMLIMIT memory to the detected maximum container or system memory. The value must be greater than 0 and less than or equal to 1.").
69+
memlimitEnable = kingpin.Flag("auto-gomemlimit", "Automatically set GOMEMLIMIT to match Linux container or system memory limit").
70+
Default("false").Bool()
71+
memlimitRatio = kingpin.Flag("auto-gomemlimit.ratio", "The ratio of reserved GOMEMLIMIT memory to the detected maximum container or system memory.").
7072
Default("0.9").Float64()
73+
memlimitRefreshInterval = kingpin.Flag("auto-gomemlimit.refresh-interval", "Interval at which to re-detect the container or system memory limit and update GOMEMLIMIT accordingly. Useful when the limit can change at runtime, e.g. with a Vertical Pod Autoscaler. Set to 0 to detect the limit only once at startup. Note that a downward change in the limit can cause a temporary increase in garbage collection activity. Only used when --auto-gomemlimit is set.").
74+
Default("0s").Duration()
7175

7276
clusterBindAddr = kingpin.Flag("cluster.listen-address", "Listen address for cluster. Set to empty string to disable HA mode.").
7377
Default(app.DefaultClusterAddr).String()
@@ -108,19 +112,26 @@ func run() int {
108112
}
109113
compat.InitFromFlags(logger, ff)
110114

111-
if ff.EnableAutoGOMEMLIMIT() {
115+
if *memlimitEnable || ff.EnableAutoGOMEMLIMIT() {
112116
if *memlimitRatio <= 0.0 || *memlimitRatio > 1.0 {
113117
logger.Error("--auto-gomemlimit.ratio must be greater than 0 and less than or equal to 1.")
114118
return 1
115119
}
120+
if *memlimitRefreshInterval < 0 {
121+
logger.Error("--auto-gomemlimit.refresh-interval must not be negative.")
122+
return 1
123+
}
124+
116125
if _, err := memlimit.SetGoMemLimitWithOpts(
117126
memlimit.WithRatio(*memlimitRatio),
127+
memlimit.WithRefreshInterval(*memlimitRefreshInterval),
118128
memlimit.WithProvider(
119129
memlimit.ApplyFallback(
120130
memlimit.FromCgroup,
121131
memlimit.FromSystem,
122132
),
123133
),
134+
memlimit.WithLogger(logger.With("component", "automemlimit")),
124135
); err != nil {
125136
logger.Warn("automemlimit", "msg", "Failed to set GOMEMLIMIT automatically", "err", err)
126137
}

featurecontrol/featurecontrol.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func NewFlags(logger *slog.Logger, features string) (Flagger, error) {
160160
logger.Warn("UTF-8 strict mode enabled")
161161
case FeatureAutoGOMEMLIMIT:
162162
opts = append(opts, enableAutoGOMEMLIMIT())
163-
logger.Warn("Automatically set GOMEMLIMIT to match the Linux container or system memory limit.")
163+
logger.Error("Deprecated: auto-gomemlimit will be removed in v0.35. Please use the new command line flag --auto-gomemlimit instead.")
164164
case FeatureEventRecorder:
165165
opts = append(opts, enableEventRecorder())
166166
logger.Warn("Experimental event recorder enabled")

0 commit comments

Comments
 (0)