[prometheus-mysql-exporter] Set GOMAXPROCS and GOMEMLIMIT environment variables based on container resources #4547
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What this PR does / why we need it
Set
GOMAXPROCS
andGOMEMLIMIT
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; so64Mi
would result in the environment variable being set to67108864
. 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 wholeenv
block to only make it appear if a value is set, but that will look quite complicated and quite prone to (future) errors.Checklist
[prometheus-couchdb-exporter]
)