Home > Software engineering >  Using variables in PrometheusRule expr field instead of contant values
Using variables in PrometheusRule expr field instead of contant values

Time:01-06

I am trying to create a 'PrometheusRule' inside my cluster with some alert rules using promql expressions. However, I want these resources to be used and configurable for different services inside my same cluster. All I want to do is have Variable values inside my "expr" field, something like this:

expr: sum( nginx_ingress_controller_requests{status=~"5. "} ) > VARIABLE_VALUE

Instead of:

expr: sum( nginx_ingress_controller_requests{status=~"5. "} ) > 50

This is the PromethuesRule I am trying to make:

apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
  name: blablaname
  namespace: blablans
spec:
  groups:
  - name: {{ include "blabla.fullname" . }}-cache
    rules:
    - alert: TOOMANY5XXX
      annotations:
        description: too many 5XXs
        summary: blablabla
      expr: sum( nginx_ingress_controller_requests{status=~"5. "} ) > VARIABLE_VALUE
      for: 5m
      labels:
        severity: critical

PS: I am using Helm charts as my package manager and would like the Variable to be present in my Values.yaml file

CodePudding user response:

If you are using helm then use simple variable assignment:

expr: sum( nginx_ingress_controller_requests{status=~"5. "} ) > {{ .Values.VariableValue }}
  • Related