When should you create recording rules, and how do you name them?
IntermediateScenarioPrometheus and PromQL at Scale
Answer
Situation read → Expensive or frequently reused queries slow dashboards and alert evaluation.
What I'd do →
- Create recording rules for aggregations used by dashboards or alerts, especially
histogram_quantileand cross-label sums over many series. - Use the convention
level:metric:operations:
groups:
- name: api.rules
interval: 30s
rules:
- record: job:http_requests:rate5m
expr: sum by (job) (rate(http_requests_total[5m]))
- Keep labels the aggregation preserves in the
levelpart. The name should say what was aggregated. - Do not record everything. Each rule adds series and evaluation cost.
Why → Pre-computation trades small storage for fast, consistent queries.
Interview tip → Alerts should use recording rules for SLI expressions, so dashboards and alerts agree.
More on Prometheus and PromQL at Scale
Prometheus memory has grown to 60 GB and keeps climbing. How do you find the cause?IntermediateA developer added `user_id` as a metric label. What is the problem and what do you advise?BeginnerYour dashboard shows the average of per-pod p99 latencies. Why is it wrong, and how do you compute a correct fleet-wide p99?IntermediateChoose histogram bucket boundaries for a service with a 300 ms latency SLO.AdvancedYou have 500 short-lived batch jobs that finish before Prometheus can scrape them. How do you capture their metrics?IntermediateYour EC2 fleet autoscales constantly. How do you keep Prometheus targets up to date?Intermediate