Infrastructure

Azure Monitor: diagnose a stateful log alert stuck fired before going stateless

A production runbook for separating query windows, ingestion delay, dimensions and resolution timing before changing an Azure Monitor log alert from stateful to stateless.

16 Nov 2026 azureazure-monitorlog-analyticslog-alertscheduled-query-rulekqlobservabilityalertingincidentcanaryrunbookrollbackproduction

A stateful Azure Monitor log alert detects a queue backlog for one service. The queue is drained, the dashboard returns to normal, but the alert remains fired and no new notification arrives during the next spike. The fastest-looking fix is to disable automatic resolution and make the rule stateless.

That change may restore repeated notifications while creating an alert storm. A stateful rule deliberately keeps one alert instance open until its condition has remained clear for a frequency-dependent period. The query can also keep returning an old row because its lookback window is wider than the evaluation frequency, data arrived late, or one split dimension is still unhealthy.

This runbook separates those cases. It ends with one bounded decision: keep the stateful rule, correct its query or dimensions, adjust its timing, or canary a stateless rule with an explicit notification budget.

Freeze the rule and one alert instance

Stop editing the rule while diagnosing it. Export the deployed scheduled query rule and record one fired alert instance, its dimensions, first activation time and last evaluation. Preserve the action group and alert processing rules too: a fired condition with no notification is not the same failure as a condition that never resolved.

yaml 01-log-alert-scope.yml
incident: INC-MON-642
window_utc: 2026-11-16T08:00:00Z/2026-11-16T10:00:00Z

rule:
name: orders-backlog-by-service
resource_id: /subscriptions/<subscription>/resourceGroups/<rg>/providers/Microsoft.Insights/scheduledQueryRules/<rule>
evaluation_frequency: PT5M
query_window: PT15M
automatically_resolve: true
mute_actions_duration: <observed-value>
threshold: 100
operator: GreaterThan
dimensions: [Service]

instance:
monitor_condition: Fired
service: orders-api
first_activated_utc: <timestamp>
last_evaluated_utc: <timestamp>

evidence:
deployed_rule_digest: <sha256>
query_text_digest: <sha256>
action_group_ids: [<resource-id>]
processing_rule_ids: [<resource-id-or-none>]
rollback_owner: <role>

Do not close the alert manually as a diagnostic action. User response and monitor condition are different states; acknowledgement can help workflow ownership, but it does not prove that the rule evaluated clear.

Reconstruct the three clocks

Log alerts combine three time axes:

  • event time, usually TimeGenerated;
  • ingestion time, when the row became queryable;
  • evaluation time, when the scheduled rule ran its query window.

A dashboard can show the current queue depth while the alert query still counts a failure row from the previous 15 minutes. Late data can enter a later evaluation even though its event timestamp belongs to the incident. Pin all three clocks before changing alert state.

kusto 02-backlog-evaluation-replay.kql
let EvaluationTime = datetime(2026-11-16T09:30:00Z);
let Window = 15m;
QueueBacklog_CL
| where TimeGenerated > EvaluationTime - Window
| where TimeGenerated <= EvaluationTime
| summarize
  LatestDepth=arg_max(TimeGenerated, BacklogDepth),
  Rows=count(),
  LastIngested=max(ingestion_time())
by Service
| project Service,
        SampleTime=LatestDepth_TimeGenerated,
        BacklogDepth=LatestDepth_BacklogDepth,
        Rows,
        LastIngested,
        EvaluationTime

QueueBacklog_CL is an example normalized table. Adapt the column names and aggregation to the real signal. If each row is a point-in-time depth, alert on the latest valid sample per service; summing every depth in the window measures accumulated samples, not the queue.

Replay the query for each evaluation boundary around fire and expected recovery. Avoid now() and ago() during reconstruction because the evidence moves every time the query is rerun.

Prove which dimension is still fired

When a rule splits by Service, each dimension value has its own alert lifecycle. A healthy orders-api dashboard does not clear an instance for orders-worker, an empty service name or a stale renamed dimension. List every series returned by the exact alert query and compare it with open alert instances.

Check for:

  • casing or whitespace that creates two values for the same service;
  • a deployment that changed the dimension name;
  • null values mapped to an unexpected series;
  • a resource ID or region dimension that keeps an old instance separate;
  • more returned series than the team can operationally own.

Normalize dimensions in the query before splitting and keep the resulting cardinality bounded. Do not remove a dimension merely to make one instance resolve; that can collapse unrelated failures into one alert and suppress later notifications.

Apply the actual stateful resolution clock

A stateful log alert does not resolve on the first healthy evaluation. Azure Monitor requires the condition to remain unmet for a time derived from the evaluation frequency:

  • at 1 minute, the condition must remain clear for 10 minutes;
  • from 5 to 15 minutes, it must remain clear for three frequency periods;
  • from 15 minutes to 11 hours, it must remain clear for two frequency periods;
  • from 11 to 12 hours, one frequency period is required.

For a five-minute rule, three consecutive clear periods are therefore expected before resolution. Any matching result during that sequence resets the effective recovery evidence. Include ingestion latency and the query window when estimating the earliest legitimate resolve time.

Distinguish this from action muting. A mute duration can suppress repeated actions; an alert processing rule can suppress notifications; neither changes whether the scheduled query condition is fired or resolved.

Test the query contract, not only its threshold

Build a small contract set with one series that must fire, one that must stay healthy and one that transitions from fire to clear. Validate the query at fixed evaluation times.

For a point-in-time backlog signal, the contract should prove:

  • the latest sample wins within the window;
  • a stale high value cannot override a newer healthy value;
  • a missing current sample is handled explicitly;
  • late arrivals cannot resurrect an already-cleared operational period without being visible;
  • every split dimension is stable and nonempty.

Missing data deserves its own decision. Log search alerts are strongest when detecting present evidence. If the real requirement is “no fresh heartbeat,” a metric alert or a deliberately designed absence query may be safer than treating an empty result as health.

Canary the full fire-to-resolve lifecycle

Clone the rule under a canary name and route it to a non-paging action group. Keep the candidate query, frequency, window, threshold, dimensions and automatic-resolution setting identical to the intended production rule. Use one unique canary dimension.

Inject controlled samples that produce this sequence:

  1. healthy evaluation;
  2. threshold breach and one fired notification;
  3. continued breach without duplicate stateful actions;
  4. healthy samples for the full resolution period;
  5. one resolved notification;
  6. a new breach that creates a new fired transition.
yaml 03-alert-lifecycle-canary.yml
canary: CHG-MON-642
dimension: orders-alert-canary
evaluation_frequency: PT5M
query_window: PT15M

expected_transitions:
- Healthy -> Fired
- Fired -> Fired without repeated action
- Fired -> Resolved after three clear frequency periods
- Resolved -> Fired on a new breach

abort_conditions:
- production dimension matched by canary query
- more than one fired action for one stateful breach
- resolution before the documented clear period
- no new fired transition after confirmed resolution
- action payload cannot identify rule and dimension

Observe monitor condition and notification delivery separately. A webhook or email resolved notification may not carry the same metric value as the fired notification because log-alert resolution is time-based. Consumers should route on the alert state and identifiers, not on a non-null measured value alone.

Decide whether stateless is actually required

Keep the rule stateful when responders need one incident per dimension, a clear recovery signal and suppression of duplicate actions during a continuing condition. Correct the query when an overlapping window, wrong aggregation or unstable dimension prevents resolution. Adjust timing when the evaluation frequency and query window cannot represent the operational recovery objective.

Use stateless behavior only when each matching evaluation is independently actionable and the downstream system can absorb repeated notifications. Before promotion, define the maximum notifications per hour, action-group cost, deduplication key and stop condition. Muting actions is a notification throttle, not a substitute for correct incident state.

Roll back without losing the active incident

Keep the previous rule definition and action-group mapping deployable. If the candidate produces duplicate pages, unexpected dimensions or misses the second breach, disable only the candidate and restore the previous digest. Do not delete the original fired instance as part of configuration rollback.

After restoration, replay the fixed-time query, confirm the intended dimension state, validate the next evaluation and test action delivery through the non-paging path. Record whether the original instance resolved naturally, remained fired for a valid reason or required a separate correction to the query contract.

Conclusion

A stateful log alert that remains fired is not automatically stuck. Its state reflects query results, dimensions, ingestion timing and a deliberate clear period. Making the rule stateless can turn one misunderstood lifecycle into repeated operational noise.

The production decision should come from a complete transition test: freeze the rule, replay fixed evaluation windows, identify the exact dimension, wait for the documented resolution clock, canary fire and recovery, then either keep stateful behavior, correct the contract or introduce bounded stateless notifications with a tested rollback.