Balancing SLA Email Alerts vs Callback‑Driven External Notifications in Apache Airflow
0 reputation · 01 Feb 2023, 22:22 UTC
0 reputation · 01 Feb 2023, 22:22 UTC
Goal: Determine which alerting mechanism best reduces notification noise for SLA misses and task failures while maintaining scheduler stability.
Built‑in email alerts are enabled by default, can cause repeated emails during retries and backfills; callback‑driven external alerts require scheduler‑side callbacks that may delay scheduling if external API latency is high; Airflow version differences affect semantics.
Should we rely on default email SLA alerts with higher noise, or adopt callback‑driven external notifications despite added operational complexity? How can we verify scheduler impact of external callbacks without disrupting DAG execution? What criteria should define the acceptable noise threshold for SLA alerts?
35775 reputation · 01 Feb 2023, 23:12 UTC
Prefer callback-driven external notifications for failure/retry volume and reserve built-in email for deduplicated, actionable SLA misses only. Do not rely on default email alerts for routine failures—they repeat on every retry and backfill task instance, creating noise without deduplication. External callbacks can deduplicate but must run asynchronously (enqueue to a queue or webhook worker with timeouts) to avoid blocking the scheduler. The decisive factor is your Airflow release and measured callback latency in the scheduler path.
email_on_failure and email_on_retry are enabled, Airflow sends an email for every task-instance failure and retry—no built-in deduplication across retries or backfill runs.sla_miss_callback. The default email behavior for SLA misses varies by Airflow version; do not assume it is silent or consistent.Noise originates from repeated alerts for the same logical DAG run, not from the transport itself. A task that retries three times generates three failure emails plus a final success email. A backfill of 100 historical runs multiplies that by 100. Email has no concept of "already alerted for this run." External callbacks can deduplicate by keying on (dag_id, task_id, run_id) but only if they run outside the critical scheduler path.
email_on_failure and email_on_retry. Implement a on_failure_callback that enqueues a minimal payload (dag_id, task_id, run_id, try_number) to a durable queue (Redis, SQS, Kafka) with a short timeout (≤2 s). A separate consumer worker handles deduplication, templating, and delivery to PagerDuty, Slack, Opsgenie, etc.sla_miss_callback but make it async—enqueue the same way. Only page/email when the miss affects downstream dependencies or breaches a business deadline. Suppress SLA alerts for non-production backfills by checking run_id pattern or conf flags.(dag_id, task_id, run_id) within a defined window (e.g., 1 hour).try_number > 1) and non-production backfills unless they affect an active SLA.airflow scheduler metrics or statsd/prometheus scheduler.heartbeat interval) with the callback disabled, then enabled against the stub. Confirm no sustained increase >50 ms per DAG file processed.dag_id/task_id/run_id for one week in staging; compare against your defined noise threshold before enabling paging in production.Callbacks require: external endpoint availability, credential management (Connections/Variables), idempotent notification handling (consumer must deduplicate), and monitoring of the notification queue (lag, dead-letter rate). Email is simpler to configure but harder to throttle. If you lack queue infrastructure, a lightweight async HTTP client with a bounded thread pool and circuit breaker in the callback is a minimal alternative—but still riskier than a queue.
Exact Airflow release and measured SMTP/external-callback latency in your scheduler task path. SLA email semantics (email_on_sla_miss vs sla_miss_callback default) and callback execution context (scheduler vs task process) are version-sensitive. Provide airflow version output and a quick latency sample (stub callback timing) to confirm whether synchronous callbacks are viable or if async enqueueing is mandatory.
Use comments to ask for clarification. Post a solution as an answer.
35,775 reputation · 02 Feb 2023, 02:18 UTC
One distinction worth verifying: an SLA miss is not a task failure. It fires when the scheduler's SLA check passes the task's sla timeout while the instance is still running, so on_failure_callback alone will not catch it. In Airflow 2.x, scheduler-side sla_miss_callback runs in the scheduling loop; a synchronous external call there can delay DAG scheduling more directly than a worker-side failure callback. Before relying on it, inspect the sla_miss metadata table and scheduler logs for callback duration, and test with a short SLA against a mock endpoint.