- Use Astro alerts to configure Dag failure or success alerts for common communication channels like Slack, PagerDuty, or email.
- Use Astro alerts to implement pipeline SLAs based on task duration or Timeliness.
- Use Airflow email notifications and callbacks for custom task-level alerting logic.
Feature overview
This guide highlights when to use the following Astro and Airflow features to create different types of alerts for your pipelines:- Astro alerts for configuring Dag SLAs and failure notifications.
- Airflow callbacks for custom task-level alerts.
Best practice guidance
Using a combination of Astro alerts and Airflow notifications allows your team to implement alerting logic using the best tool for each scenario. You might need different types of alerts that are better suited towards one option or the other, for example:- Task-level alerts with custom logic are recommended if you want be notified of success or failure only for a specific task, or you want to run custom code if a task succeeds or fails. Task-level success or failure alerts or alerts with custom logic are not currently supported with Astro alerts, but they’re straightforward to implement in Airflow.
- Dag-level success or failure alerts can be created using either Airflow notifications or Astro alerts, but on Astro they are easy to configure and don’t require any code changes. To implement these alerts with Airflow, you need to update your Dag code and complete additional configuration for your communication channel (for example, setting up an SMTP server for email alerts).
- Timeliness alerts are recommended when you need your Dag to complete by a certain time of day. These types of alerts are available only on Astro.
- Task duration alerts are recommended when you need to know if your task has taken longer than a certain amount of time to complete. These types of alerts are easy to implement with Astro alerts, but are unintuitive in Airflow.
Programmatically creating Astro alerts is coming soon. This will make it easy to configure alerts for a large number of Dags without having to create each alert manually.
- The Astro alert for task duration is relevant to the task start time, making it easy to understand and implement for your use case. Airflow SLAs often cause confusion because they are relevant to the Dag execution date, not the task start time.
- The Astro alert for Timeliness allows you to implement alerts based on a specific time of day your Dag should complete. This type of SLA is not available in Airflow.
- Astro alerts allow you to easily choose between multiple common communication channels. With Airflow SLAs, if you want your notification sent somewhere other than your email, you have to write your own custom callback logic. Additionally, if you have an SMTP service configured in your Airflow environment you will get email notifications for SLA misses; there is no way to turn this behavior off.
Recommended alerts
Astronomer recommends choosing the following alerts in these common scenarios:
For more information on different types of alerts, check out the documentation linked in See also.
Example
This example shows how to implement a combination of Airflow and Astro alerts to cover notifications for common scenarios including Dag failures, specific task failures, and pipeline SLAs.Prerequisites
To implement the alerts shown in this example, you need:- At least one Astro Deployment. Your Deployment must run Astro Runtime 7.1.0 or later and it must have OpenLineage enabled.
- An Astro project with at least one dag. Your Dag should have at least two tasks.
Implementation
To implement this use case:- Open the Dag in your Astro project and configure a pre-built SlackNotifier for one of its tasks as a task-level argument. See Example pre-built notifier: Slack for sample code.
- Deploy your project to your Astro Deployment. See Deploy code to Astro.
- Add a connection to Slack in the Astro UI. See Create Airflow connections in the Astro UI. This connection will be used by your SlackNotifier, so make sure the connection ID matches what you used in your Dag code in Step 1.
- In your Astro Deployment, configure an Astro Dag failure alert for your Dag using the communication channel of your choice. See Set up Astro alerts.
- Configure an Astro Timeliness alert for your Dag based on the amount of time you expect your Dag to complete in. Use the communication channel of your choice. See Set up Astro alerts.