如何在Airflow中运行的ETL作业中添加SLA?

时间:2019-07-23 18:26:42

标签: airflow airflow-scheduler service-level-agreement

我是Apache Airflow的新手。我有一些DAG已在Airflow中运行。现在,我想在其中添加SLA,以便我可以跟踪和监视任务并在出现问题时获得警报。

我知道如何使用如下所示的timedelta()将SLA添加到DAG的default_args中

default_args = {
    'owner': 'airflow',
    'depends_on_past': False,
    'start_date': datetime(2015, 6, 1),
    'email': ['airflow@example.com'],
    'email_on_failure': False,
    'email_on_retry': False,
    'retries': 1,
    'retry_delay': timedelta(minutes=5),
    'sla': timedelta(minutes=30)
}

但是我有以下问题:

  1. 我们可以为整个DAG指定SLA还是仅为单个任务指定SLA?

  2. 对于运行30分钟的DAG,合适的SLA时间是多少?

  3. 对于运行5分钟的任务,什么是适当的SLA时间?

  4. 在指定SLA时我们还需要考虑retry_delay吗?

1 个答案:

答案 0 :(得分:0)

  

我们可以为整个DAG指定SLA还是仅为单个任务指定SLA?

我认为SLA总体上仅配置for individual tasksnot for DAG。但是我认为,通过在末尾创建一个任务(DummyOperator)来实现整个DAG的相同效果(虽然不能肯定地说),该任务依赖于DAG的所有其他任务并在该任务上设置SLA关闭任务


  

对于运行30的DAG,什么是适当的SLA时间?   分钟?

这将完全取决于诸如任务的关键性,其失败率等因素。但是我建议您从“严格足够”的时间增量(如5分钟)开始,然后从以下时间调整(增加或减少)在那里


  

对于5个正在运行的任务,什么是适当的SLA时间?   分钟?

与上述相同,从1分钟开始,然后从那里进行调音


  

在指定SLA时我们还需要考虑retry_delay吗?

docs旁边,我会说

:param sla: time by which the job is expected to succeed. Note that
        this represents the ``timedelta`` after the period is closed. For
        example if you set an SLA of 1 hour, the scheduler would send an email
        soon after 1:00AM on the ``2016-01-02`` if the ``2016-01-01`` instance
        has not succeeded yet.