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

Allow setting GOMEMLIMIT and GOGC #6080

Closed
TomBillietKlarrio opened this issue Nov 13, 2023 · 5 comments
Closed

Allow setting GOMEMLIMIT and GOGC #6080

TomBillietKlarrio opened this issue Nov 13, 2023 · 5 comments

Comments

@TomBillietKlarrio
Copy link

What is missing?
It seems it's not possible to set the GOMEMLIMIT and GOGC environment variables.
I could not find it anywhere the docs or the api from the prometheus CRD. So I don't think it's possible. If the CRD would allow to inject arbitrary env variables, it could be solved like this, but I could not find that either.

Why do we need it?
Avoid prometheus instances (especially long-running instances that consume a lot of memory) from getting OOMKilled. See also https://weaviate.io/blog/gomemlimit-a-game-changer-for-high-memory-applications for some information.

@slashpai
Copy link
Contributor

You should be able to inject env variable using strategic merge patch https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/user-guides/strategic-merge-patch.md

@slashpai
Copy link
Contributor

Something like:

apiVersion: monitoring.coreos.com/v1
kind: Prometheus
...
spec:
  containers:
  - name: "prometheus"
    env:
    - name: A
      value: B

@TomBillietKlarrio
Copy link
Author

Thanks. It was not clear from the docs I could do those things.
It seems to be working, not let's see if it fixes our OOM kills.

@simonpasquier
Copy link
Contributor

This could be a nice addition to https://prometheus-operator.dev/docs/operator/strategic-merge-patch/

@TomBillietKlarrio
Copy link
Author

TomBillietKlarrio commented Nov 14, 2023

Or even add it as an option to set it automatically. I now do this magic in helm to set it to 80% of the pod limit:

{{ $promMemory := .Values.prometheus.resources.memory }}
    resources:
      requests:
        cpu: {{ .Values.prometheus.resources.cpu }} 
        memory: {{ $promMemory }}
      limits:
        memory: {{ $promMemory }}
    containers:
    - name: "prometheus"
      env:
      - name: GOMEMLIMIT
        # set GOMEMLIMIT: https://weaviate.io/blog/gomemlimit-a-game-changer-for-high-memory-applications
        # this is a complex function to automatically set this to 80% of what the pod limit is.
        value: "{{ floor (mulf (mulf (int (trimSuffix "Gi" $promMemory)) 1024) 0.8) }}MiB"

(caveat: only works if you define memory limit with the unit Gi)

slashpai added a commit to slashpai/prometheus-operator that referenced this issue Nov 14, 2023
Related-to prometheus-operator#6080

Signed-off-by: Jayapriya Pai <slashpai9@gmail.com>
slashpai added a commit to slashpai/prometheus-operator that referenced this issue Nov 14, 2023
Related-to prometheus-operator#6080

Signed-off-by: Jayapriya Pai <slashpai9@gmail.com>
slashpai added a commit to slashpai/prometheus-operator that referenced this issue Nov 15, 2023
Related-to prometheus-operator#6080

Signed-off-by: Jayapriya Pai <slashpai9@gmail.com>
slashpai added a commit to slashpai/prometheus-operator that referenced this issue Nov 15, 2023
Related-to prometheus-operator#6080

Signed-off-by: Jayapriya Pai <slashpai9@gmail.com>
slashpai added a commit to slashpai/prometheus-operator that referenced this issue Nov 16, 2023
Related-to prometheus-operator#6080

Signed-off-by: Jayapriya Pai <slashpai9@gmail.com>
slashpai added a commit to slashpai/prometheus-operator that referenced this issue Nov 16, 2023
Related-to prometheus-operator#6080

Signed-off-by: Jayapriya Pai <slashpai9@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants