
{{- $Values := (.helm).Values | default .Values }}
{{- $runbookUrl := ($Values.defaultRules).runbookUrl | default "https://runbooks.prometheus-operator.dev/runbooks" }}
{{- $clusterLabel := ($Values.global).clusterLabel | default "cluster" }}
{{- $additionalGroupByLabels := append $Values.defaultRules.additionalGroupByLabels $clusterLabel }}
{{- $groupLabels := join "," (uniq $additionalGroupByLabels) }}
{{- $grafanaAddr := include "vm-k8s-stack.grafana.addr" . }}
name: general.rules
rules:
- alert: TargetDown
  expr: {{ printf "(100 * (count(up == 0) by(%s,job,namespace,service) / count(up) by(%s,job,namespace,service))) > 10" $groupLabels $groupLabels }}
  annotations:
    description: '{{`{{`}} printf "%.4g" $value {{`}}`}}% of the {{`{{`}} $labels.job {{`}}`}}/{{`{{`}} $labels.service {{`}}`}} targets in {{`{{`}} $labels.namespace {{`}}`}} namespace are down.'
    runbook_url: {{ $runbookUrl }}/general/targetdown
    summary: One or more targets are unreachable.
  condition: true
  for: 10m
  labels:
    severity: warning
- alert: Watchdog
  expr: vector(1)
  annotations:
    description: |
      This is an alert meant to ensure that the entire alerting pipeline is functional.
      This alert is always firing, therefore it should always be firing in Alertmanager
      and always fire against a receiver. There are integrations with various notification
      mechanisms that send a notification when this alert is not firing. For example the
      "DeadMansSnitch" integration in PagerDuty.
    runbook_url: {{ $runbookUrl }}/general/watchdog
    summary: An alert that should always be firing to certify that Alertmanager is working properly.
  condition: true
  labels:
    severity: none
- alert: InfoInhibitor
  expr: {{ printf "group(ALERTS{severity=\"info\"} == 1) by(namespace,%s) unless on(namespace,%s) group(ALERTS{alertname!=\"InfoInhibitor\",alertstate=\"firing\",severity=~\"warning|critical\"} == 1) by(namespace,%s)" $groupLabels $groupLabels $groupLabels }}
  annotations:
    description: |
      This is an alert that is used to inhibit info alerts.
      By themselves, the info-level alerts are sometimes very noisy, but they are relevant when combined with
      other alerts.
      This alert fires whenever there's a severity="info" alert, and stops firing when another alert with a
      severity of 'warning' or 'critical' starts firing on the same namespace.
      This alert should be routed to a null receiver and configured to inhibit alerts with severity="info".
    runbook_url: {{ $runbookUrl }}/general/infoinhibitor
    summary: Info-level alert inhibition.
  condition: true
  labels:
    severity: none
condition: true
