-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add details for setting memory limit automatically. #655
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
internal/alloycli/cmd_run.go
Outdated
// Set the memory limit, this will honor GOMEMLIMIT if set | ||
// If there is a cgroup will follow that | ||
if fr.enableAutoMemoryLimit { | ||
memlimit.SetGoMemLimitWithOpts() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to pass in a compatible logger here? If so, some of the logs might be helpful (e.g. if GOMEMLIMIT
is already set it won't honor the cgroups settings, as well as confirmation of the limit)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was thinking something like from the example:
memlimit.SetGoMemLimitWithOpts(
memlimit.WithRatio(0.9),
memlimit.WithProvider(memlimit.FromCgroup),
memlimit.WithLogger(slog.Default()), // Can we pass a logger here?
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can but I have to move it til after our logging is fully initialized, which likely isn't the end of the world its just later in the process to pass down the bool flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the slog.Default, its...a bit different looking but likely works for ease of use.
2024/04/23 17:01:27 INFO memory is not limited, skipping: %v package=github.com/KimMachineGun/automemlimit/memlimit !BADKEY="memory is not limited"
Co-authored-by: Mischa Thompson <mischabear@gmail.com>
Co-authored-by: Mischa Thompson <mischabear@gmail.com>
internal/alloycli/cmd_run.go
Outdated
// Set the memory limit, this will honor GOMEMLIMIT if set | ||
// If there is a cgroup will follow that | ||
if fr.enableAutoMemoryLimit { | ||
memlimit.SetGoMemLimitWithOpts(memlimit.WithLogger(slog.Default())) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than exposing this as a new configuration option, what do you think about having this automatically be enabled for users using experimental/public-preview, and then once we get enough information on it, we can decide whether it should always be on or needs to be configurable?
(The larger our API surface is the more annoying backwards compatibility can be, so avoiding new configuration options when possible is preferable for me)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IE if stability is experimental automatically enable? I can also set the flag as experimental, though unsure if we have a precedent for that with alloy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IE if stability is experimental automatically enable?
Yeah, like we would say that "auto memory limit is an experimental performance improvement" and only applies when --stability.level=experimental
. This is something I expect we'll be doing at some frequency, including for the eventual controller refactor.
I can also set the flag as experimental
We don't have an existing precedent but I expect that most things will support feature gating at some point, including flags.
However in this case I don't think marking the flag as experimental fully addresses my concerns, since presumably we intend for this to GA, and I prefer not adding too many more GA flags because of the increased API surface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marked as public preview and added a helper function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM following some feedback
@@ -164,6 +164,7 @@ original configuration. | |||
Include `--config.extra-args` to pass additional command line flags from the original format to the converter. | |||
Refer to [alloy convert][] for more details on how `extra-args` work. | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO I think we should find a way to document this somewhere just so people know which improvements lower stability levels include. I don't know what page it should be on, but I'll leave that up to you since I'm not too opinionated.
// Set the memory limit, this will honor GOMEMLIMIT if set | ||
// If there is a cgroup will follow that | ||
if fr.minStability.AtLeast(featuregate.StabilityPublicPreview) { | ||
memlimit.SetGoMemLimitWithOpts(memlimit.WithLogger(slog.Default())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should use slog.New(l.Handler())
here instead of slog.Default()
; the controller's logger implements the slog.Handler interface. I think this is important so that log entries are emitted in the proper format if the user requests json vs the default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that. The format isnt set by this point so it errors, its possible we could default to one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could always move it after the logger is resolved but that feels like an odd time to set memory limits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems like a bug in the logging code, it's supposed to buffer logs until the controller evaluates, but it only seems to do that when you're using the go-kit interface and not the slog.Handler interface. I think it might be worth fixing that so we can use the right logger here.
I don't think defaulting to a format is the right move, since when we used to do this, users complained that some of the early log lines weren't in the format they were expecting and parsing the log lines at ingestion time was failing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be worth fixing that so we can use the right logger here.
Since we've fixed issues about this in the past I'd say not using the right logger would be a regression here. IMO I think we need to do something to use the right logger, either fixing the buffering issue with the slog.Handler implementation or moving this later in evaluation at least temporarily (I agree it's weird for setting the memory limit to not happen as early as possible)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to fork this out into its own PR, making the logger work with slog is bigger than this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattdurham Is creating a PR to fix the logger still on your radar? Given this was merged first, there's a known regression in main now, and we're running out of time for 1.1 (RC gets cut this Thursday).
If we can't fix this by Thursday we'll have to discuss this feature skipping 1.1 or putting out the release with a known regression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is, wrapping up testing now, it ended up being slightly more complicated than expected.
* Add details for setting memory limit automatically. * fix typo * Update docs/sources/reference/cli/run.md Co-authored-by: Mischa Thompson <mischabear@gmail.com> * Update internal/alloycli/cmd_run.go Co-authored-by: Mischa Thompson <mischabear@gmail.com> * add logging * Mark as public preview. * Mark as public preview. * pr feedback * use default logger --------- Co-authored-by: Mischa Thompson <mischabear@gmail.com>
PR Description
This will set the automemory limit if cgroups exist and the setting is enabled, the setting defaults to true. If there is a GOMEMLIMIT set already it will not overwrite it. If there are no cgroups then no limit will be applied.
Which issue(s) this PR fixes
Fixes #651
Notes to the Reviewer
PR Checklist