Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#8484](https://github.com/thanos-io/thanos/pull/8484) Query: add `/api/v1/status/tsdb` API endpoint.
- [#8454](https://github.com/thanos-io/thanos/pull/8454) Compact: ensure we don't mark blocks for deletion again after just deleting them
- [#8410](https://github.com/thanos-io/thanos/pull/8410) Compact: ignore blocks with deletion mark in partial deletes
- [#8556](https://github.com/thanos-io/thanos/pull/8556) All Components: add debug logs when enabling GOMEMLIMIT and log the effective memory limit on startup

### Changed

Expand Down
16 changes: 10 additions & 6 deletions cmd/thanos/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,24 +349,28 @@ func (gml *goMemLimitConfig) registerFlag(cmd extkingpin.FlagClause) *goMemLimit
return gml
}

func configureGoAutoMemLimit(common goMemLimitConfig) error {
func configureGoAutoMemLimit(common goMemLimitConfig) (int64, error) {
var err error
limits := int64(-1)

if common.memlimitRatio <= 0.0 || common.memlimitRatio > 1.0 {
return errors.New("--auto-gomemlimit.ratio must be greater than 0 and less than or equal to 1.")
return limits, errors.New("--auto-gomemlimit.ratio must be greater than 0 and less than or equal to 1.")
}

if common.enableAutoGoMemlimit {
if _, err := memlimit.SetGoMemLimitWithOpts(
limits, err = memlimit.SetGoMemLimitWithOpts(
memlimit.WithRatio(common.memlimitRatio),
memlimit.WithProvider(
memlimit.ApplyFallback(
memlimit.FromCgroup,
memlimit.FromSystem,
),
),
); err != nil {
return errors.Wrap(err, "Failed to set GOMEMLIMIT automatically")
)
if err != nil {
return -1, errors.Wrap(err, "Failed to set GOMEMLIMIT automatically")
}
}

return nil
return limits, nil
}
8 changes: 7 additions & 1 deletion cmd/thanos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ func main() {
cmd, setup := app.Parse()
logger := logging.NewLogger(*logLevel, *logFormat, *debugName)

if err := configureGoAutoMemLimit(goMemLimitConf); err != nil {
limits, err := configureGoAutoMemLimit(goMemLimitConf)
if err != nil {
level.Error(logger).Log("msg", "failed to configure Go runtime memory limits", "err", err)
os.Exit(1)
}
Expand All @@ -77,6 +78,11 @@ func main() {
level.Debug(logger).Log("msg", fmt.Sprintf(template, args...))
}))
defer undo()

if goMemLimitConf.enableAutoGoMemlimit {
level.Debug(logger).Log("msg", fmt.Sprintf("GOMEMLIMIT set to %d bytes configured with ratio equals to %.0f%% of detected memory", limits, goMemLimitConf.memlimitRatio*100))
}

if err != nil {
level.Warn(logger).Log("warn", errors.Wrapf(err, "failed to set GOMAXPROCS: %v", err))
}
Expand Down
Loading