Infrastructure

Azure Managed Prometheus: diagnose a silent recording rule before changing alerts

A production runbook for separating raw metrics, PromQL, scope, evaluation order and ruler health when a Managed Prometheus recording rule stops producing series.

08 Nov 2026 azureazure-monitormanaged-prometheusaksprometheuspromqlrecording-rulesobservabilityautomationrunbookrollbackproduction

An AKS saturation alert stops firing after a recording-rule deployment. Grafana also shows an empty panel, yet the raw container metrics still exist in the Azure Monitor workspace. The quick fixes are tempting: point the alert back to an expensive raw query, widen its selectors, or recreate the rule group. Each action changes the evidence and can turn one silent derived metric into a query-cost or paging incident.

The running case uses a recording rule named namespace:container_cpu_usage:rate5m, consumed by a dashboard and a Prometheus alert rule. This runbook separates collection, source series, PromQL semantics, rule-group scope, evaluation order and managed ruler health. It ends with one decision: keep the candidate, correct a bounded defect, use a temporary raw-query fallback, or restore the previous rule group.

Freeze the rule contract and incident window

Start with the resource that Azure evaluates, not the YAML fragment remembered by the team. Record the Azure Monitor workspace, rule-group resource ID, scope, region, interval, rule order, deployed expression and every downstream consumer.

yaml recording-rule-incident.yml
incident: inc-20261108-002
workspace: amw-platform-prod
rule_group: prg-aks-capacity-prod
record: namespace:container_cpu_usage:rate5m
window_utc:
start: 2026-11-08T06:20:00Z
end: 2026-11-08T07:20:00Z
expected_scope:
cluster: aks-platform-prod
consumers:
- grafana-capacity-dashboard
- aks-cpu-saturation-alert
preserve:
- deployed-rule-group-json
- previous-known-good-json
- raw-and-recorded-promql-results
- resource-health-history
- change-commit-and-deployment-id

Export the live resource before editing it. Prometheus rule groups are Azure resources of type Microsoft.AlertsManagement/prometheusRuleGroups; the repository is intent, while the resource is the effective state.

bash 01-export-rule-group.sh
RULE_GROUP_ID="/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-observability-prod/providers/Microsoft.AlertsManagement/prometheusRuleGroups/prg-aks-capacity-prod"

az resource show --ids "$RULE_GROUP_ID" --api-version 2023-03-01 --output json > deployed-rule-group.json

jq '{id, location, properties: {
enabled: .properties.enabled,
interval: .properties.interval,
scopes: .properties.scopes,
rules: .properties.rules
}}' deployed-rule-group.json

Do not copy secret-bearing headers or tokens into the incident record. The useful evidence is the rule definition, its scope and the results returned by the workspace.

Prove the source series before blaming the ruler

A recording rule cannot create a useful series from an empty expression. Run the exact deployed expression against the same Azure Monitor workspace and a time range that includes the incident. Then reduce the query until the first missing selector or label appears.

promql 02-source-expression.promql
sum by (cluster, namespace) (
rate(container_cpu_usage_seconds_total{
  cluster="aks-platform-prod",
  container!="",
  image!=""
}[5m])
)

Classify the result before changing anything:

  • no raw metric points to scraping, relabeling, DCR or workspace routing;
  • raw metric present but the full expression empty points to selectors or label drift;
  • the full expression returns data while the recorded metric is empty points to rule scope, evaluation or ruler health;
  • the recorded metric exists under unexpected labels points to aggregation or injected-label semantics;
  • the recorded metric is healthy while the consumer is empty points to the dashboard or alert query.

Check the labels that actually exist instead of assuming that cluster, namespace or container survived collection unchanged. A deployment can keep the metric name while relabeling removes the value used by the rule.

Compare source and recorded metrics on the same timeline

Query the expression and the recorded metric over several evaluation intervals. An instant query taken immediately after deployment can confuse propagation or a sparse source with a permanent failure.

promql 03-recorded-series.promql
namespace:container_cpu_usage:rate5m{
cluster="aks-platform-prod"
}

count by (cluster, namespace) (
namespace:container_cpu_usage:rate5m
)

Use a range that includes at least one known-good interval, the change, and several expected evaluations. Compare timestamps and labels, not only the last value. If the raw expression has intermittent gaps, the recording rule may be faithfully exposing an upstream collection problem.

Also verify the recording-rule name exactly. Colons are a Prometheus naming convention, not hierarchy. A consumer querying namespace_container_cpu_usage_rate5m will never match namespace:container_cpu_usage:rate5m.

Verify scope, enablement and evaluation order

Azure Managed Prometheus evaluates every rule in a group against the Azure Monitor workspace and scope declared by that group. A cluster-scoped group moved to another cluster, a disabled group, or an empty scope match can leave the source visible at workspace level while producing no derived series for the intended target.

text rule-group-checks.txt
Rule group
Provisioning state is Succeeded
Group is enabled
Location matches the Azure Monitor workspace region
Scope contains the intended workspace and cluster
Evaluation interval matches the operational contract

Recording rule
Rule is enabled
Record name matches every consumer exactly
Expression returns bounded source series
Required labels exist in the scoped source
Added labels do not overwrite diagnostic dimensions

Dependencies
A rule that consumes another recorded metric follows it in the same group
Cross-group dependencies are treated as asynchronous
The fallback does not create a circular dependency

Rules inside one group run in their defined order. If rule B consumes the series produced by rule A, keep A first and validate both expressions separately. Do not assume deterministic order between different groups. For a cross-group dependency, either consume raw metrics, combine the rules in one owned group, or design for the extra evaluation delay.

Inspect managed ruler health before recreating the group

Resource Health for the Prometheus rule group can expose degraded evaluation, query throttling, unavailable workspace references or a disabled state. Preserve the recent health history before deletion: recreation removes the resource you need to explain.

Query cost matters even when the expression works interactively. Managed recording rules have a finite query-cost budget. A broad regex, long range vector or unbounded join can succeed on a quiet interval and then fail as series grow. Reduce the expression by cluster, job or namespace and remove dimensions that the recorded metric does not need.

promql 04-bounded-candidate.promql
sum by (cluster, namespace) (
rate(container_cpu_usage_seconds_total{
  cluster="aks-platform-prod",
  job="cadvisor",
  container!="",
  image!=""
}[5m])
)

The correction must preserve operational dimensions. Aggregating away namespace may make the rule cheaper but also make the saturation alert impossible to route. Conversely, keeping pod and instance in a capacity rule can retain churn the consumer never uses.

Canary the correction without mutating the production contract

Create a temporary recording rule with a new name and no paging action. Run it beside the existing rule long enough to cover normal and peak traffic. A new name avoids silently changing dashboards before the candidate has evidence.

yaml candidate-contract.yml
candidate_record: namespace:container_cpu_usage:rate5m_canary
evaluation_interval: PT1M
scope:
cluster: aks-platform-prod
validation:
- source_expression_non_empty
- candidate_fresh_for_five_intervals
- namespace_label_preserved
- cardinality_within_expected_bound
- dashboard_query_matches_candidate
- alert_expression_evaluated_without_action_group
stop_conditions:
- source_query_throttled
- candidate_series_unbounded
- required_namespace_missing
- unrelated_rule_health_degrades

Compare the candidate against the raw expression with the same time range and step. Exact sample timestamps may differ by evaluation interval, so validate freshness, label set, series count and an agreed numerical tolerance. Test the alert expression as a shadow rule without an action group before reconnecting paging.

Decide, validate and roll back

Keep the candidate only when the raw expression, recorded series and consumers tell the same story.

text recording-rule-decision.txt
Promote the candidate
Raw expression is stable in the intended scope
Recorded series remain fresh across representative load
Required labels and bounded cardinality are preserved
Dashboard and shadow alert agree with the source
Rule-group health remains Available

Correct a bounded defect
One selector, scope, enablement flag or dependency order explains the gap
The correction is isolated and canaried
Previous group JSON remains immediately deployable

Use a temporary raw-query fallback
The incident needs visibility before ruler repair completes
Query cost is measured and the fallback is time-bounded
Paging thresholds are revalidated against the raw expression

Roll back
The candidate changes aggregation semantics
Query throttling or unrelated rule degradation appears
A required consumer cannot be validated
Source labels are still unstable or collection remains incomplete

Rollback means redeploying the captured known-good rule group, not recreating a visually similar rule in the portal. After rollback, query both the source expression and recorded name for several intervals, then verify the dashboard and a nonpaging alert canary. Remove the temporary rule and raw fallback only after the original contract is healthy.

Conclusion

A silent recording rule is not automatically a PromQL defect. The failure can sit in raw collection, label selectors, Azure scope, rule order, query cost, managed ruler health or the consumer itself.

Freeze the deployed resource, prove the source expression, compare the derived series on the same timeline, and canary a new record name before changing alerts. The final decision is operationally valid only when it restores fresh, bounded series without hiding collection gaps or weakening paging.