0
0
Apache Airflowdevops~10 mins

SLA misses and notifications in Apache Airflow - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - SLA misses and notifications
DAG runs task
Check if task finishes before SLA time
Yes
No action
Send notification email
Log SLA miss for review
The DAG runs a task and checks if it finishes before the SLA deadline. If it misses, an SLA miss event triggers a notification and logging.
Execution Sample
Apache Airflow
from airflow import DAG
from airflow.operators.bash import BashOperator
from airflow.utils.dates import days_ago
from datetime import timedelta

default_args = {
    'sla': timedelta(minutes=5),
    'email': ['alert@example.com'],
    'email_on_failure': True
}
with DAG('sla_example', default_args=default_args, start_date=days_ago(1)) as dag:
    task = BashOperator(task_id='task1', bash_command='sleep 600')
This DAG defines a task with a 5-minute SLA and email notification on SLA miss.
Process Table
StepTask StatusElapsed TimeSLA TimeSLA Miss?Action TakenNotification Sent
1Task started0s5mNoNoneNo
2Task running3m5mNoNoneNo
3Task running5m5mNoNoneNo
4Task finished10m5mYesSLA miss event triggeredYes
5Notification sent---Email sent to alert@example.comYes
6SLA miss logged---Logged in Airflow UIYes
7End---No further actionNo
💡 Task finished after 10 minutes, exceeding SLA of 5 minutes, triggering SLA miss and notification.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
task_statusNot startedStartedRunningRunningFinishedFinished
elapsed_time0s0s3m5m10m10m
sla_missFalseFalseFalseFalseTrueTrue
notification_sentFalseFalseFalseFalseTrueTrue
Key Moments - 2 Insights
Why does the SLA miss only trigger after the task finishes, not during the run?
The SLA miss event triggers only after the task finishes and the elapsed time is compared to the SLA. See execution_table step 4 where the task finishes at 10 minutes, exceeding the 5-minute SLA.
Does Airflow send notifications automatically on SLA miss?
Yes, if email_on_failure or email_on_retry is set and email addresses are configured, Airflow sends notifications automatically on SLA miss events as shown in execution_table step 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step does the SLA miss get detected?
AStep 3
BStep 4
CStep 2
DStep 5
💡 Hint
Check the 'SLA Miss?' column in the execution_table rows.
According to the variable tracker, what is the value of 'notification_sent' after step 3?
ATrue
BUndefined
CFalse
DError
💡 Hint
Look at the 'notification_sent' row and the column 'After Step 3' in variable_tracker.
If the task finished in 4 minutes instead of 10, how would the SLA miss column change in the execution table?
AIt would be 'No' at step 4
BIt would be 'Yes' at step 4
CIt would be 'Yes' at step 3
DIt would be 'No' at step 2
💡 Hint
Compare elapsed time with SLA time in execution_table rows.
Concept Snapshot
SLA misses in Airflow occur when a task exceeds its defined SLA time.
Airflow detects SLA misses after task completion.
Notifications (e.g., emails) can be sent automatically on SLA miss.
Configure SLA and email in DAG default_args.
SLA miss events are logged for monitoring.
Full Transcript
This visual execution shows how Airflow handles SLA misses and notifications. The DAG runs a task with a 5-minute SLA. The task runs longer (10 minutes), so after it finishes, Airflow detects the SLA miss and triggers an event. This event sends an email notification and logs the miss in the Airflow UI. Variables like task status, elapsed time, SLA miss flag, and notification sent flag change step-by-step. Key moments clarify why SLA miss triggers after task completion and how notifications are sent. Quiz questions test understanding of when SLA miss is detected and notification status.