Pcornel
Browse topics
Options
Recent
Favorites
Observability · Technical reference

Recording Rules

Direct answer

Recording rules precompute expensive PromQL expressions into new series at each evaluation, speeding up dashboards and alerts.

When to use this

Use it for heavy or frequently used queries such as SLI ratios.

First 30 seconds

1. Validate: promtool check rules rules.yml.

2. Rule loaded: curl -s localhost:9090/api/v1/rules.

3. Evaluation errors/duration.

4. Dashboard uses recorded series.

5. Naming convention.

Operational verification

expression → rule group evaluation → new series → queries

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
OpenTelemetry / Prometheus / Grafana / common metrics-log-trace pipelines
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformOpenTelemetry / Prometheus / Grafana / common metrics-log-trace pipelines
Scope / prerequisiteUse it for heavy or frequently used queries such as SLI ratios.
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 How to verify Verify boundary

Compare recorded and raw results for a few timestamps. Watch prometheus_rule_group_last_duration_seconds.

Step 2 Common failures Narrow the fault

Changing a recording rule breaks dashboards that use the old name. Recorded series have no history before the rule was added. Very many rules increase load and series count.

Key points

Name as level:metric:operations (e.g. job:http_requests:rate5m). Validate with promtool. Rules evaluate per group interval.

Key checks
  • promtool check rules rules.yml — first check for this topic
  • curl -s localhost:9090/-/ready — Prometheus ready
  • curl -s 'localhost:9090/api/v1/query?query=up' — scrape targets up/down
  • promtool check config prometheus.yml — config valid
ReferenceWhat it is1 section · depth on demand

How it works

The rule manager evaluates each group on its interval and writes results back into the TSDB. Evaluations that take longer than the interval are skipped.

ReferenceImportant terms & boundaries3 sections · depth on demand

Example

groups:
  - name: http
    rules:
      - record: job:http_requests:rate5m
        expr: sum by (job) (rate(http_requests_total[5m]))
      - record: job:http_errors:ratio_rate5m
        expr: sum by (job) (rate(http_requests_total{code=~"5.."}[5m])) / sum by (job) (rate(http_requests_total[5m]))

Documented example, not captured output. Naming convention level:metric:operations. Use recording rules for dashboards and SLO alerts that query large ranges; validate with promtool check rules.

In depth

When to record

Use a recording ruleKeep the raw query
A dashboard panel used by many people is slowAd-hoc investigation
SLO and burn-rate alerts that need long windows (30 d)Queries that need every label
Federation or remote write should send aggregates, not raw seriesRarely viewed panels

Naming convention level:metric:operations

groups:
- name: http-aggregates
  interval: 30s
  rules:
  - record: job:http_requests:rate5m
    expr: sum by (job) (rate(http_requests_total[5m]))
  - record: job:http_request_errors:ratio_rate5m
    expr: |
      sum by (job) (rate(http_requests_total{code=~"5.."}[5m]))
        / sum by (job) (rate(http_requests_total[5m]))

level lists the labels kept (job), metric the source, operations what was applied, newest last. Anyone reading job:http_request_errors:ratio_rate5m knows what it contains without opening the rule file.

Rules in a group run in order

A rule can use the result of a rule above it in the same group in the same evaluation. If a group takes longer than its interval, evaluations are skipped:

prometheus_rule_group_last_duration_seconds > prometheus_rule_group_interval_seconds
rate(prometheus_rule_group_iterations_missed_total[10m]) > 0

Validate before deploying

promtool check rules rules/*.yaml
promtool test rules tests/http-aggregates_test.yaml     # unit tests with input series and expected output

A recorded series starts at the time the rule is added; it has no history. Keep the raw expression on the dashboard for older ranges or backfill with promtool tsdb create-blocks-from rules.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Common mistakes

  • Recording rules with high cardinality.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
recording rulesprometheus recording rulespromtool check rules
Confirmation

Confirm action

Continue?