'PrometheusOperator Helm Chart: adding labels to default rules

I need to add a label to all default rules that come with the Helm chart. I tried setting the label under commonLabels in the values file, to no avail. I also tried putting it as external_labels within the defaultRules stanza, again didn't do the trick. When I add the label to rules I define myself under AdditionalAlerts, it works fine. But I need it for all alerts.

I also added it under the "labels for default rules". The label got added to the metadata of each of the default rules, but I need it inside the spec of the rule, under the already existing label for "severity".

The end goal is to put the environment inside that label, e.g. TEST, STAGING and PRODUCTION. So if anyone has another way to accomplish this, by all means....



Solution 1:[1]

You can upgrade your values.yaml file for Prometheus with the necessary labels in the additionalRuleLabels section for defaultRules.

Below is an example based on the values.yaml file from the Prometheus Monitoring Community:

defaultRules:
  ## Additional labels for PrometheusRule alerts
  additionalRuleLabels:
    additionalRuleLabel1: additinalRuleValue1

Result: enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1