|
The existing SLA implementation before Airflow 3.0 has been problematic and a constant point of debate. In the Airflow 3 planning meetings, it was discussed and decided that the move to a new major version is a good time to tear out the old implementation and replace it with something new. Since AIP-57 has been abandoned, this proposal will replace and supersede AIP-57. That AIP and the discussion around it are not to be considered as part of this proposal and, unless mentioned here, nothing in those discussions or that AIP is considered to be part of this one.
The old SLA feature is removed in Airflow 3.0 (PR here) and in 3.1 it will be replaced with Airflow Alerts. The purpose of this AIP is to discuss the implementation of the new Alerts feature to replace the SLA feature.
One of the main points of contention of the SLA feature revolves around when you start counting. If you set an SLA of "1 hour", is that one hour after it was scheduled, one hour after it starts running, one hour after it was queued, or something else entirely. This leads to frequent questions and confusion. This AIP revolves around the idea of allowing the user to define that starting point and treat the new SLA as a calculated "need-by date". To avoid confusion, the new feature will be referred to as Alerts rather than SLA and the implementation will allow a much more versatile experience for the user.
(credit for this section to Sung Yun in AIP-57)
As stated above, this AIP intentionally ignores all previous discussion on the topic or fixing, changing, redefining, or re-implementing "SLA". Previous discussions have been ongoing for a very long time, across many different mediums, and have gone through multiple proposals. It is impossible to summarize or collate all those discussions, so treat this as a "blank slate" proposal and do not assume any other changes outside of what is explicitly stated herein.
As this is a topic that has been discussed many times, in an effort to avoid confusion, I am using the following definitions in this project.
An Enum will contain a selection of options, similar to how a user currently provides the TriggerRule. The implementation will include an interface which allows future work to easily add new anchors, but they will not be a freeform input for the user. These options will resolve to a datetime() representing the possible points in time to start counting from. This value can be dynamic (examples include NEXT_DAGRUN_EXECUTION_DATE or DAGRUN_QUEUED_AT, which map to their respective database fields), or a static date/time value provided as a string and cast to a datetime() object.
A datetime.timedelta. When added to the anchor you get the “need-by date”. (see below)
“Need-by” will be defined as the anchor time (see above) plus some delta. For example, `need_by = AlertAnchors.NEXT_DAGRUN_EXECUTION_DATE + 1_hour`
A Callable (or, by extension, a functools.partial) to execute when a miss is detected. This implementation will not be limited to picking either "email" or "notify", it will allow any user-provided callable and include those as built-in options/examples.
Before diving into the challenges with the current SLA feature, let's consider what our users are expecting from an SLA feature in Airflow:
Elmo, a data engineer at a large e-commerce company, manages a DAG that generates a critical daily sales report. This report must be ready by 9 AM every day for the executive team's business review.
Elmo expects:
Rosita, a data scientist at a finance firm, works with a DAG that includes a data processing task which transforms the data using EMR extracted from an external API. This task occasionally runs much longer than expected, delaying downstream processes.
Rosita needs:
Zoe, an engineer at a tech startup, manages a DAG with multiple stages: data ingestion, preparation, processing, and reporting. She needs to ensure each stage completes within a specific timeframe.
Zoe requires:
Allowing the user to decide which point int he DAG's lifecycle the need-by time is based off will help clear up much of the confusion around the old SLA implementation.
All users who currently use the SLA feature will need to migrate. The SLA feature has been removed in 3.0 and replaced with a notification to this effect, and the documentation for the Alerts will include examples to set an Alertthat works the same way as the old SLA to help minimize the transition effort for those users who liked the old way.
The SLAMiss table has been removed in 3.0 and this implementation will likely replace it with a similar Alerts table which maps dagrun_id::timestamp.
DAGs which implement the old SLA feature will need to be manually migrated. Documentation will include examples showing the old vs new configurations to make that as easy as possible
This AIP will only cover DAG-level Alerts.
Future work can add: