Skip to content
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

feat(env): Add automatic memory limit handling #6591

Merged

Conversation

dongjiang1989
Copy link
Contributor

Description

Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request.
If it fixes a bug or resolves a feature request, be sure to link to that issue.

add auto GOMEMLIMIT setting

Type of change

What type of changes does your code introduce to the Prometheus operator? Put an x in the box that apply.

  • CHANGE (fix or feature that would cause existing functionality to not work as expected)
  • FEATURE (non-breaking change which adds functionality)
  • BUGFIX (non-breaking change which fixes an issue)
  • ENHANCEMENT (non-breaking change which improves existing functionality)
  • NONE (if none of the other choices apply. Example, tooling, build system, CI, docs, etc.)

Verification

Please check the Prometheus-Operator testing guidelines for recommendations about automated tests.

Changelog entry

Please put a one-line changelog entry below. This will be copied to the changelog file during the release process.

add auto  GOMEMLIMIT setting

Signed-off-by: dongjiang1989 <dongjiang1989@126.com>
@dongjiang1989 dongjiang1989 requested a review from a team as a code owner May 15, 2024 12:08
@nicolastakashi
Copy link
Contributor

LGTM 🥳
Just a simple question, on the PR about MAXPROC I think you also added to config reloader, should we do the same?

Signed-off-by: dongjiang1989 <dongjiang1989@126.com>
@dongjiang1989
Copy link
Contributor Author

LGTM 🥳 Just a simple question, on the PR about MAXPROC I think you also added to config reloader, should we do the same?

Thanks. Done added.

Copy link
Contributor

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike the gomaxprocs change, I wonder if it shouldn't be an opt-in feature? My rationale is that GOMAXPROCS is always set to "some" value while GOMEMLIMIT is unset by default (e.g. math.MaxInt64).

Also should we really consider the system memory if no k8s limits are set? More food for thoughts from https://www.ardanlabs.com/blog/2024/02/kubernetes-memory-limits-go.html:

If you’re not going to use K8s memory limits, then don’t do anything with GOMEMLIMIT. The Go runtime is really good at finding the sweet spot for your memory requirements.

cmd/operator/main.go Outdated Show resolved Hide resolved
cmd/operator/main.go Outdated Show resolved Hide resolved
cmd/operator/main.go Outdated Show resolved Hide resolved
dongjiang1989 and others added 2 commits May 16, 2024 18:56
Co-authored-by: Simon Pasquier <spasquie@redhat.com>
@simonpasquier
Copy link
Contributor

To follow-up with my last comment, I'd suggest that we treat <= 0 values as "don't set GOMEMLIMIT" and > 1 values as 1.
We can set the default to 0, thus making it an opt-in feature for now (we can still change it later). Also I'd only take into account the cgroup memory limit in the calculation and I would highlight in the arg description that you have to set memory limits to benefit from the functionality. What do you think?

Signed-off-by: dongjiang1989 <dongjiang1989@126.com>
@dongjiang1989
Copy link
Contributor Author

To follow-up with my last comment, I'd suggest that we treat <= 0 values as "don't set GOMEMLIMIT" and > 1 values as 1. We can set the default to 0, thus making it an opt-in feature for now (we can still change it later). Also I'd only take into account the cgroup memory limit in the calculation and I would highlight in the arg description that you have to set memory limits to benefit from the functionality. What do you think?

Thank. Got it. @simonpasquier , PTAL

Signed-off-by: dongjiang1989 <dongjiang1989@126.com>
cmd/operator/main.go Outdated Show resolved Hide resolved
cmd/operator/main.go Outdated Show resolved Hide resolved
pkg/operator/feature_gates.go Outdated Show resolved Hide resolved
cmd/operator/main.go Outdated Show resolved Hide resolved
cmd/operator/main.go Outdated Show resolved Hide resolved
Signed-off-by: dongjiang1989 <dongjiang1989@126.com>
@pull-request-size pull-request-size bot added size/L and removed size/M labels May 26, 2024
Signed-off-by: dongjiang1989 <dongjiang1989@126.com>
cmd/prometheus-config-reloader/main.go Outdated Show resolved Hide resolved
pkg/operator/feature_gates.go Outdated Show resolved Hide resolved
pkg/operator/feature_gates_test.go Outdated Show resolved Hide resolved
cmd/operator/main.go Outdated Show resolved Hide resolved
cmd/prometheus-config-reloader/main.go Show resolved Hide resolved
Copy link
Contributor

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Can you make the same change for the admission webhook too? I'd also advise to factorize the argument parsing in internal/goruntime to avoid duplication.

cmd/prometheus-config-reloader/main.go Show resolved Hide resolved
Signed-off-by: dongjiang1989 <dongjiang1989@126.com>
Signed-off-by: dongjiang1989 <dongjiang1989@126.com>
@dongjiang1989
Copy link
Contributor Author

Apply the same modification to the admission webhook as was done. Setting auto-gomemlimit-ratio to 0.

Copy link
Contributor

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pkg/operator/feature_gates*.go aren't need anymore, right? Also the default isn't 0 for all binaries.

internal/goruntime/memory.go Outdated Show resolved Hide resolved
Copy link
Member

@ArthurSens ArthurSens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for all the bumps here @dongjiang1989! After all the discussions on the PR, I think we're aligned on not using a feature-gate at all, but just disable the feature if -auto-gomemlimit-ratio is not set.

This means that we'd need to revert all changes made that are related to feature-gates. Thanks for the patience 🙂

cmd/operator/main.go Outdated Show resolved Hide resolved
pkg/operator/feature_gates.go Outdated Show resolved Hide resolved
dongjiang1989 and others added 2 commits May 29, 2024 22:16
Co-authored-by: Simon Pasquier <spasquie@redhat.com>
@dongjiang1989
Copy link
Contributor Author

dongjiang1989 commented May 30, 2024

Sorry for all the bumps here @dongjiang1989! After all the discussions on the PR, I think we're aligned on not using a feature-gate at all, but just disable the feature if -auto-gomemlimit-ratio is not set.

This means that we'd need to revert all changes made that are related to feature-gates. Thanks for the patience 🙂

Thanks. Got it. Please re-check. @ArthurSens

Signed-off-by: dongjiang1989 <dongjiang1989@126.com>
Signed-off-by: dongjiang1989 <dongjiang1989@126.com>
Copy link
Contributor

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@simonpasquier simonpasquier merged commit d5d08c5 into prometheus-operator:main May 30, 2024
17 checks passed
@dongjiang1989 dongjiang1989 deleted the support-gomemlimit branch May 30, 2024 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants