This guide explains how to add a new PrometheusRule to the platform. All alerting and recording rules are evaluated by Thanos Ruler against Thanos Query, which has access to metrics from both the Regional Cluster and all Management Clusters in the region.
All platform rules live in the alerting-rules Helm chart:
argocd/config/regional-cluster/alerting-rules/
├── Chart.yaml
├── values.yaml
└── templates/
├── hcp-sla.yaml # example: HCP availability SLA rules
└── zoa.yaml # ZOA Lambda/EMF alerts (YACE gauges, not rate())
Each template renders a PrometheusRule CR (monitoring.coreos.com/v1). You can group related rules in a single file or create separate files — one file per logical concern is the convention.
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: my-rules
namespace: thanos
labels:
app.kubernetes.io/name: alerting-rules # required — ThanosRuler ruleConfigSelector
app.kubernetes.io/managed-by: Helm
operator.thanos.io/prometheus-rule: "true" # required — thanos-operator default label
spec:
groups:
- name: my-recording-rules
interval: 1m # optional, defaults to global evaluation interval
rules:
- record: my:metric_name
expr: |
some_promql_expression
labels:
extra_label: value
- name: my-alerts
rules:
- alert: MyAlertName
expr: |
some_promql_expression > threshold
for: 5m
labels:
severity: critical # or warning
annotations:
summary: Short description
description: >-
Longer description with template variables like
{{ "{{" }} $labels.name {{ "}}" }}.Key points:
- namespace: Always
thanos— Thanos Ruler discovers rules in this namespace. - labels: Two labels are required for Thanos Ruler to discover the PrometheusRule:
app.kubernetes.io/name: alerting-rules— matched by the ThanosRulerruleConfigSelectoroperator.thanos.io/prometheus-rule: "true"— the thanos-operator's default label, always merged into the selector viaBuildLabelSelectorFrom()- Both must be present. Missing either one causes the operator to skip the rule (
found prometheus rule-based configmaps count=0). - Also include
app.kubernetes.io/managed-by: Helmfor consistency.
- Helm escaping: Prometheus template expressions (
{{ $labels.name }}) conflict with Helm's{{ }}syntax. Escape them as{{ "{{" }} $labels.name {{ "}}" }}.
Parameterize thresholds and targets via values.yaml so they can be overridden per environment:
# values.yaml
sla:
target: 0.9995# templates/my-rules.yaml
- alert: MyBurnRateAlert
expr: |
error_rate > (6 * (1 - {{ .Values.sla.target }}))For SLA-based alerts, use multi-window, multi-burn-rate alerting as described in the Google SRE Workbook — Alerting on SLOs. See templates/hcp-sla.yaml for a working example with the HCP availability SLA.
Create a test file in ci/promtool-test/ following the promtool unit testing format:
evaluation_interval: 1m
rule_files:
- rules.yaml # populated by ci/promtool-test.sh from Helm output
tests:
- interval: 1m
input_series:
- series: 'my_metric{name="test", namespace="test-ns"}'
values: "1 1 1 0 0 0" # available, then unavailable
alert_rule_test:
- eval_time: 5m
alertname: MyAlertName
exp_alerts: []./ci/promtool-test.shThis script:
- Renders the
alerting-ruleschart viahelm template - Extracts the PrometheusRule
.specinto a standalone rules file usingyq - Runs
promtool check rulesto validate syntax - Runs
promtool test rulesagainst test files inci/promtool-test/
Tests also run in CI as part of the unit test suite.
After deploying to an ephemeral environment:
- Confirm ThanosRuler pods are running:
kubectl get pods -n thanos -l app.kubernetes.io/name=thanos-ruler - Query the recording rule via Thanos Query to verify it produces data
- Check alert state via Thanos Query UI — new alerts should be in
inactivestate for healthy clusters - Verify
helm lint argocd/config/regional-cluster/alerting-rules/passes
- Recording rules: Use colons as namespace separators —
<domain>:<metric_name>(e.g.,hcp:hostedcluster_available) - Alerts: PascalCase, descriptive —
HCPAvailabilityErrorBudgetFastBurn - Template files: kebab-case matching the logical concern —
hcp-sla.yaml - Rule groups: kebab-case —
hcp-availability-recording,hcp-availability-alerts