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): auto set GOMAXPROCS by go.uber.org/automaxprocs #6576

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.

Auto set GOMAXPROCS.
add dependency on go.uber.org/automaxprocs

ref: #6560

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.

auto set GOMAXPROCS by go.uber.org/automaxprocs

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

Amazing @dongjiang1989 🥳

cmd/operator/main.go Outdated Show resolved Hide resolved
@xbglowx
Copy link

xbglowx commented May 9, 2024

Thanks for working on this @dongjiang1989

Signed-off-by: dongjiang1989 <dongjiang1989@126.com>
@@ -183,6 +185,13 @@ func run(fs *flag.FlagSet) int {
stdlog.Fatal(err)
}

l := func(format string, a ...interface{}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should be behind a feature flag, wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

We still don't have feature flags tho 😅

But I agree that this needs to be configurable, e.g. what's the side-effect of having gomaxprocs auto enabled during development? If I run the operator in my machine, will it take over all cores?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Read the CGroup value in the container environment to identify the CPU quota of the container, calculate the actual number of cores, and automatically set the number of GOMAXPROCS threads.

Like: runtime.GOMAXPROCS(maxProcs)

Copy link
Contributor

Choose a reason for hiding this comment

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

Well!
I think it's a fair and simple feature flag implementation.
I'm ok with that, because it's also the same approach we have in Prometheus.
Let's see what the other maintainers think about it.

Copy link
Member

Choose a reason for hiding this comment

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

I have another PR open for a few weeks implementing feature-flags as well, but following Kubernetes feature-flags approach. #6491

Differently from Prometheus' approach, K8s allows us maintainers to graduate feature flags slowly while still letting users disable feature flags that we might enable by default in the future.

In my opinion, this gives us the flexibility to enable features when we feel it has achieved enough maturity, while also providing safe-guards to users if they break something in production

Signed-off-by: dongjiang1989 <dongjiang1989@126.com>
@pull-request-size pull-request-size bot added size/M and removed size/S labels May 10, 2024
@simonpasquier
Copy link
Contributor

I'd be fine using automaxprocs by default without a feature flag. Unlike Prometheus, the operator (almost) always runs on Kubernetes and we should provide the best experience for folks setting CPU limits.

e.g. what's the side-effect of having gomaxprocs auto enabled during development? If I run the operator in my machine, will it take over all cores?

the same as today: the Go runtime will set GOMAXPROCS to the number of cores available from your laptop.

@nicolastakashi
Copy link
Contributor

I'd be fine using automaxprocs by default without a feature flag. Unlike Prometheus, the operator (almost) always runs on Kubernetes and we should provide the best experience for folks setting CPU limits.

e.g. what's the side-effect of having gomaxprocs auto enabled during development? If I run the operator in my machine, will it take over all cores?

the same as today: the Go runtime will set GOMAXPROCS to the number of cores available from your laptop.

Yes, it makes sense.
I was just curious about the almost 👀

@simonpasquier
Copy link
Contributor

"almost" = except when you do local development

@dongjiang1989
Copy link
Contributor Author

dongjiang1989 commented May 14, 2024

I'd be fine using automaxprocs by default without a feature flag. Unlike Prometheus, the operator (almost) always runs on Kubernetes and we should provide the best experience for folks setting CPU limits.

e.g. what's the side-effect of having gomaxprocs auto enabled during development? If I run the operator in my machine, will it take over all cores?

the same as today: the Go runtime will set GOMAXPROCS to the number of cores available from your laptop.

Thanks. Got it. I'll revert this feature flag.

Signed-off-by: dongjiang1989 <dongjiang1989@126.com>
@pull-request-size pull-request-size bot added size/S and removed size/M labels May 14, 2024
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.

LGTM. I've tested on my local env with different limit values (including none) and it works fine from what I can tell.

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.

the same as today: the Go runtime will set GOMAXPROCS to the number of cores available from your laptop.

I had a wrong understanding of this configuration, I don't know how I thought that but I had the impression it was configuring how many CPU cores it would take priority over other processes in my machine 😅

@simonpasquier simonpasquier merged commit bac5d11 into prometheus-operator:main May 16, 2024
17 checks passed
@simonpasquier
Copy link
Contributor

thanks!

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

5 participants