-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AIRFLOW-5714] Collect SLA miss emails only from tasks missed SLA (#6384
) Currently when a task in the DAG missed the SLA, Airflow would traverse through all the tasks in the DAG and collect all the task-level emails. Then Airflow would send an SLA miss email to all those collected emails, which can add unnecessary noise to task owners that does not contribute to the SLA miss. Thus, changing the code to only collect emails from the tasks that missed the SLA. (cherry picked from commit bc53412)
- Loading branch information
1 parent
2379061
commit 5ebc27d
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1993,6 +1993,47 @@ def test_scheduler_sla_miss_callback_exception(self): | |
'Could not call sla_miss_callback for DAG %s', | ||
'test_sla_miss') | ||
|
||
@mock.patch('airflow.jobs.scheduler_job.send_email') | ||
def test_scheduler_only_collect_emails_from_sla_missed_tasks(self, mock_send_email): | ||
session = settings.Session() | ||
|
||
test_start_date = days_ago(2) | ||
dag = DAG(dag_id='test_sla_miss', | ||
default_args={'start_date': test_start_date, | ||
'sla': datetime.timedelta(days=1)}) | ||
|
||
email1 = '[email protected]' | ||
task = DummyOperator(task_id='sla_missed', | ||
dag=dag, | ||
owner='airflow', | ||
email=email1, | ||
sla=datetime.timedelta(hours=1)) | ||
|
||
session.merge(models.TaskInstance(task=task, | ||
execution_date=test_start_date, | ||
state='Success')) | ||
|
||
email2 = '[email protected]' | ||
DummyOperator(task_id='sla_not_missed', | ||
dag=dag, | ||
owner='airflow', | ||
email=email2) | ||
|
||
session.merge(SlaMiss(task_id='sla_missed', | ||
dag_id='test_sla_miss', | ||
execution_date=test_start_date)) | ||
|
||
scheduler = SchedulerJob(dag_id='test_sla_miss', | ||
num_runs=1) | ||
|
||
scheduler.manage_slas(dag=dag, session=session) | ||
|
||
self.assertTrue(1, len(mock_send_email.call_args_list)) | ||
|
||
send_email_to = mock_send_email.call_args_list[0][0][0] | ||
self.assertIn(email1, send_email_to) | ||
self.assertNotIn(email2, send_email_to) | ||
|
||
@mock.patch("airflow.utils.email.send_email") | ||
def test_scheduler_sla_miss_email_exception(self, mock_send_email): | ||
""" | ||
|