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

[prometheus-mysql-exporter] Set GOMAXPROCS and GOMEMLIMIT environment variables based on container resources #4547

Conversation

jnoordsij
Copy link
Contributor

What this PR does / why we need it

Set GOMAXPROCS and GOMEMLIMIT environment variables based on container resources. This should reduce potential CPU throttling and OOMKills on containers.

The resourceFieldRef is a very specific Kubernetes directive that is created specifically for passing resource-related values, which rounds up the CPU value to the nearest whole number (e.g. 250m to 1) and passes the memory as a numeric value; so 64Mi would result in the environment variable being set to 67108864. This by design makes it completely compatible with Go's API.

An example is documented within Kubernetes documentation itself: https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#use-container-fields-as-values-for-environment-variables.

Inspired by traefik/traefik-helm-chart#1029.

Which issue this PR fixes

N/A

Special notes for your reviewer

This creates an empty env key for those not setting resource values (and not using existing config secret). This is only a little ugly, but should not be harmful. Alternatively, the could be some combined conditional wrapper around the whole env block to only make it appear if a value is set, but that will look quite complicated and quite prone to (future) errors.

Checklist

  • DCO signed
  • Chart Version bumped
  • Title of the PR starts with chart name (e.g. [prometheus-couchdb-exporter])

Copy link
Member

@monotek monotek left a comment

Choose a reason for hiding this comment

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

Pleas fix linting error

@jkroepke
Copy link
Member

Looking at prometheus-operator/prometheus-operator#501 - GOMAXPROCS should not set by that way.

Copy link
Member

@monotek monotek left a comment

Choose a reason for hiding this comment

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

I would also say adding some more generice itteration over an "extraEnv" value would be the way to go.

@desaintmartin
Copy link
Member

Is there a case where we do not want this to be applied?

… variables based on container resources

Signed-off-by: Jesper Noordsij <jesper@sslleiden.nl>
@jnoordsij jnoordsij force-pushed the mysql-exporter-set-gomemlimit-gomaxprocs branch from ae03735 to 9714ddf Compare July 16, 2024 08:53
@monotek monotek merged commit 62734a5 into prometheus-community:main Jul 16, 2024
4 checks passed
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

4 participants