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

Add auto-gomaxprocs optional feature #10498

Merged
merged 10 commits into from
Mar 30, 2022
Merged

Conversation

TomasKohout
Copy link
Contributor

Signed-off-by: Tomas Kohout tomas.kohout1995@gmail.com

Hi,

this PR is about adding a new dependency on go.uber.go/automaxprocs.

Why we need that?

As you all know nodes come with different sizes. For example, we use quite huge nodes with up to 104 CPUs and because we use prometheus-operator, we aren't able to set environment variables to set GOMAXPROCS to the value of cpu.limit. automaxprocs package does this automatically without any additional pain. If there are not limits specified, default value (number of cores) will be left in place.

@TomasKohout TomasKohout changed the title add dependency on go.uber.org/automaxprocs Add dependency on go.uber.org/automaxprocs Mar 29, 2022
@roidelapluie
Copy link
Member

Thanks for your contribution. Until the go runtime figures this out, can we have this behind a feature flag rather than having it enabled by default?

@bboreham
Copy link
Member

I think having a side-effect caused by _ is a bit too subtle.
I expect adding a feature flag will fix this too - there will be some description associated with the name.

@peterbourgon
Copy link
Contributor

I agree with @roidelapluie and @bboreham.

because we use prometheus-operator, we aren't able to set environment variables

Is this a limitation of prometheus-operator specifically, or operators in general?

@TomasKohout
Copy link
Contributor Author

Feature flag added. 🙂

@TomasKohout
Copy link
Contributor Author

I agree with @roidelapluie and @bboreham.

because we use prometheus-operator, we aren't able to set environment variables

Is this a limitation of prometheus-operator specifically, or operators in general?

It depends. Maybe there are some operators which expose env field via theirs CRD. Prometheus-operator doesn't do so.

@TomasKohout
Copy link
Contributor Author

I'll add feature description to the documentation tomorrow.

cmd/prometheus/main.go Outdated Show resolved Hide resolved
cmd/prometheus/main.go Outdated Show resolved Hide resolved
cmd/prometheus/main.go Outdated Show resolved Hide resolved
@@ -186,6 +189,9 @@ func (c *flagConfig) setFeatureListOptions(logger log.Logger) error {
case "promql-per-step-stats":
c.enablePerStepStats = true
level.Info(logger).Log("msg", "Experimental per-step statistics reporting")
case "auto-gomaxprocs":
c.enableAutoGOMAXPROCS = true
level.Info(logger).Log("msg", "Automatically set GOMAXPROCS to cpu.limits when running in container.")
Copy link
Contributor

Choose a reason for hiding this comment

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

If this feature flag is enabled, but Prometheus is not running in a container, will the maxprocs.Set call (below) fail and emit a warning?

Copy link
Contributor Author

@TomasKohout TomasKohout Mar 30, 2022

Choose a reason for hiding this comment

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

It'll not fail nor emit warning, it'll leave the default which is equal to number of CPUs.

I'm not sure under which conditions would Set fail. I've added warning for user to know why the GOMAXPROCS is not set when this feature is enabled.

@roidelapluie
Copy link
Member

This LGTM besides my comment. Can you please add a note in the Feature Flags documentation?
Thanks!

@TomasKohout
Copy link
Contributor Author

Note added. I've tried to describe it, but I'm not sure that it's described good enough. 🙂 Could you have an additional look please?

Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Great, thanks! 💪

@bwplotka
Copy link
Member

Do you mind singing commit for DCO bot to work? (Instructions can be found when you click on DCO failure)

@TomasKohout
Copy link
Contributor Author

Yay, sure thing!

TomasKohout and others added 10 commits March 30, 2022 10:30
Signed-off-by: Tomas Kohout <tomas.kohout1995@gmail.com>
Signed-off-by: Tomas Kohout <tomas.kohout1995@gmail.com>
Signed-off-by: Tomas Kohout <tomas.kohout1995@gmail.com>
Signed-off-by: Tomas Kohout <tomas.kohout1995@gmail.com>
Co-authored-by: Peter Bourgon <peterbourgon@users.noreply.github.com>
Signed-off-by: Tomas Kohout <tomas.kohout1995@gmail.com>
Co-authored-by: Peter Bourgon <peterbourgon@users.noreply.github.com>
Signed-off-by: Tomas Kohout <tomas.kohout1995@gmail.com>
Signed-off-by: Tomas Kohout <tomas.kohout1995@gmail.com>
Signed-off-by: Tomas Kohout <tomas.kohout1995@gmail.com>
Co-authored-by: Julien Pivotto <roidelapluie@gmail.com>
Signed-off-by: Tomas Kohout <tomas.kohout1995@gmail.com>
Signed-off-by: Tomas Kohout <tomas.kohout1995@gmail.com>
@roidelapluie
Copy link
Member

Thanks!

@TomasKohout
Copy link
Contributor Author

That was fast! I should thank you for help. 🙂

@roidelapluie roidelapluie mentioned this pull request Apr 6, 2022
@SuperQ
Copy link
Member

SuperQ commented Apr 21, 2022

@TomasKohout I'm not sure where you get the idea that the Prometheus-Operator can't inject env vars.

From the CRD API docs

containers:

Containers allows injecting additional containers or modifying operator generated containers. This can be used to allow adding an authentication proxy to a Prometheus pod or to change the behavior of an operator generated container. Containers described here modify an operator generated container if they share the same name and modifications are done via a strategic merge patch. The current container names are: prometheus, config-reloader, and thanos-sidecar. Overriding containers is entirely outside the scope of what the maintainers will support and by doing so, you accept that this behaviour may break at any time without notice.

You should easily be able to something like this

containers:
- name: prometheus
  env:
  - name: GOMAXPROCS
    value: 16

@TomasKohout
Copy link
Contributor Author

TomasKohout commented Apr 21, 2022

@SuperQ well, that sounds nice, but why should I do something that could break at any time without notice?

Edit: IMHO it's better for prometheus to determine GOMAXPROCS automatically from cpu.limits, sorry for misleading information. ;-)

@bboreham
Copy link
Member

May I suggest editing the PR title and description to match what was merged?
E.g. "Add auto-gomaxprocs optional feature" for the title.

@TomasKohout TomasKohout changed the title Add dependency on go.uber.org/automaxprocs Add auto-gomaxprocs optional feature Apr 21, 2022
@diana-borbe-consensys
Copy link

Can you please make auto-gomaxprocs configurable from the helm chart also?

@bboreham
Copy link
Member

bboreham commented Jul 6, 2022

No helm chart in this repo. Probably best to ask wherever the one you use is maintained.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants