You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "codecae (via GitHub)" <gi...@apache.org> on 2025/08/19 17:19:07 UTC
[PR] feat: Dynamic UI Alerts [airflow]
codecae opened a new pull request, #54677:
URL: https://github.com/apache/airflow/pull/54677
UI Alerts are helpful for a variety of reasons, but in the current Airflow 3 implementation, they are strictly static for the entire lifetime of the webserver/api-server. Therefore, updates to UI alerts require code changes and special automation or manual rollouts/restarts when alerts must change.
This change simply updates the `get_configs()` response to obtain alerts from `DASHBOARD_UIALERTS` using a list comprehension instead of simply returning the `DASHBOARD_UIALERTS` list as a constant. This is actually legacy behavior from Airflow 2 that has become more rigid Airflow 3.
This change allows for the ability define `DASHBOARD_UIALERTS` as an iterator instead of simply a static list, allowing for dynamic updates of UI alerts upon refresh of the dashboard page. Given that a static list acts as a iterator, existing behavior `DASHBOARD_UIALERTS` is not affected.
For example, checkout this code and:
1. Start breeze: `breeze start-airflow --python 3.11 --dev-mode`
2. Wait for api-server to complete startup.
3. Paste the following into the terminal pane:
```
bash -c 'pip install fortune-python
mkdir -p /root/airflow/config
cat << EOF > /root/airflow/config/airflow_local_settings.py
from typing import Any, Iterator
from fortune import fortune
from airflow.api_fastapi.common.types import UIAlert
class DynamicAlerts(list):
def __iter__(self) -> Iterator[Any]:
_types = ["info","warning","error"]
return iter([UIAlert(text=fortune(),category=t) for t in _types])
DASHBOARD_UIALERTS = DynamicAlerts()
EOF
touch airflow-core/src/airflow/api_fastapi/main.py'
```
4. Open the UI and refresh the dashboard page multiple times to see the Alerts change.
Every refresh should render a new set of fortune outputs at the top of the dashboard page in "info", "warning" and "error" formats.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Dynamic UI Alerts [airflow]
Posted by "codecae (via GitHub)" <gi...@apache.org>.
codecae commented on code in PR #54677:
URL: https://github.com/apache/airflow/pull/54677#discussion_r2342814096
##########
airflow-core/docs/howto/customize-ui.rst:
##########
@@ -81,19 +111,65 @@ or announcing changes to end users. The following example shows how to add alert
UIAlert(text="Critical error detected!", category="error"),
]
- See :ref:`Configuring local settings <set-config:configuring-local-settings>` for details on how to
- configure local settings.
+.. image:: ../img/ui-alert-message.png
-2. Restart Airflow Webserver, and you should now see:
+Markdown Content in Alerts
+--------------------------
-.. image:: ../img/ui-alert-message.png
+Markdown can be included in alert messages for richer formatting. In the following example, we show an alert
+message of heading 2 with a link included:
-Alert messages also support Markdown. In the following example, we show an alert message of heading 2 with a link included.
+.. code-block:: python
- .. code-block:: python
+ from airflow.www.utils import UIAlert
- DASHBOARD_UIALERTS = [
- UIAlert(text="## Visit [airflow.apache.org](https://airflow.apache.org)", category="info"),
- ]
+ DASHBOARD_UIALERTS = [
+ UIAlert(text="## Visit [airflow.apache.org](https://airflow.apache.org)", category="info"),
+ ]
.. image:: ../img/ui-alert-message-markdown.png
+
+Dynamic Dashboard Alerts
+------------------------
+
+Dashboard alerts support dynamic content that updates each time the dashboard page is refreshed. This allows for real-time
+status updates without requiring webserver restarts. Dynamic alerts must be defined as an instance of an iterable object.
+The recommended approach is to create a class that subclasses ``list`` and implements a custom ``__iter__`` method that
+yields fresh alerts each time Airflow iterates over the alerts.
+
+.. note::
+ When implementing dynamic alerts it is important to keep alert generation logic lightweight to avoid
+ impacting dashboard load times. Consider caching results for expensive operations and handle exceptions
+ gracefully to prevent alert generation from breaking the UI.
+
+Dynamic alerts are particularly useful for:
+
+- **Real-time notifications**: Display current status updates or announcements
+- **Deployment notifications**: Show current deployment status, build progress, or GitOps state
+- **Temporary maintenance alerts**: Provide time-sensitive information about ongoing maintenance or issues
+- **Environment-specific warnings**: Display different alerts based on current environment conditions
+- **External service status**: Show the availability of dependent services or APIs
+
+Creating Dynamic Alerts
+^^^^^^^^^^^^^^^^^^^^^^^
+
+To create dynamic alerts, define ``DASHBOARD_UIALERTS`` as an instance of a class that subclasses ``list`` and implements the ``__iter__`` method:
+
+.. code-block:: python
+
+ import random
+ from airflow.www.utils import UIAlert
+
+
+ class DynamicAlerts(list):
+ def __iter__(self):
+ # This method is called each time Airflow iterates over DASHBOARD_UIALERTS
+ # Example: Flip a coin
+ if random.choice([True, False]):
+ yield UIAlert("Heads!", category="info")
+ else:
+ yield UIAlert("Tails!", category="warning")
Review Comment:
The random bit isn't really a practical example, but the intent was to show that the alerts change without needing to restart the service.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Dynamic UI Alerts [airflow]
Posted by "codecae (via GitHub)" <gi...@apache.org>.
codecae commented on PR #54677:
URL: https://github.com/apache/airflow/pull/54677#issuecomment-3211538992
> I'm not sure of the use case you are trying to address here.
>
> Also mutating the underlying list after startup would have the same effect.
>
> I don't understand why we should recreate a new list on each config call.
Mutating the list is definitely possible. However, attempts to find a hook that that is invoked at any interval to affect such a mutation can't be found. Such an invocation would need to occur within the api-server process, or require communicating from some other thread. From what I could find, this was the simplest way to create this ability without over-engineering some other new api route, async loop or threaded solution. If you have suggestions, I will happily implement otherwise, provided it has the same outcome. As far as I can tell, mutating this list can only occur with physical code changes and service restarts.
The use cases for such an iteration are numerous. In the case there are transient issues with a production environment, temporary alerts can be provided without requiring additional code merges and service restarts (both of which create the potential for additional risk and delay in alerting). Other cases include informing developers the state of GitOps processing of their merged code (current commit, build progress, etc) as processes are in progress.
I suppose, in my mind, the nature of alerts should be short-lived and transient in nature. Having more runtime control over which alerts are displayed is very helpful in this regard.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Dynamic UI Alerts [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #54677:
URL: https://github.com/apache/airflow/pull/54677#discussion_r2348334805
##########
airflow-core/docs/howto/customize-ui.rst:
##########
@@ -81,19 +111,65 @@ or announcing changes to end users. The following example shows how to add alert
UIAlert(text="Critical error detected!", category="error"),
]
- See :ref:`Configuring local settings <set-config:configuring-local-settings>` for details on how to
- configure local settings.
+.. image:: ../img/ui-alert-message.png
-2. Restart Airflow Webserver, and you should now see:
+Markdown Content in Alerts
+--------------------------
-.. image:: ../img/ui-alert-message.png
+Markdown can be included in alert messages for richer formatting. In the following example, we show an alert
+message of heading 2 with a link included:
-Alert messages also support Markdown. In the following example, we show an alert message of heading 2 with a link included.
+.. code-block:: python
- .. code-block:: python
+ from airflow.www.utils import UIAlert
- DASHBOARD_UIALERTS = [
- UIAlert(text="## Visit [airflow.apache.org](https://airflow.apache.org)", category="info"),
- ]
+ DASHBOARD_UIALERTS = [
+ UIAlert(text="## Visit [airflow.apache.org](https://airflow.apache.org)", category="info"),
+ ]
.. image:: ../img/ui-alert-message-markdown.png
+
+Dynamic Dashboard Alerts
+------------------------
+
+Dashboard alerts support dynamic content that updates each time the dashboard page is refreshed. This allows for real-time
+status updates without requiring webserver restarts. Dynamic alerts must be defined as an instance of an iterable object.
+The recommended approach is to create a class that subclasses ``list`` and implements a custom ``__iter__`` method that
+yields fresh alerts each time Airflow iterates over the alerts.
+
+.. note::
+ When implementing dynamic alerts it is important to keep alert generation logic lightweight to avoid
+ impacting dashboard load times. Consider caching results for expensive operations and handle exceptions
+ gracefully to prevent alert generation from breaking the UI.
+
+Dynamic alerts are particularly useful for:
+
+- **Real-time notifications**: Display current status updates or announcements
+- **Deployment notifications**: Show current deployment status, build progress, or GitOps state
+- **Temporary maintenance alerts**: Provide time-sensitive information about ongoing maintenance or issues
+- **Environment-specific warnings**: Display different alerts based on current environment conditions
+- **External service status**: Show the availability of dependent services or APIs
+
+Creating Dynamic Alerts
+^^^^^^^^^^^^^^^^^^^^^^^
+
+To create dynamic alerts, define ``DASHBOARD_UIALERTS`` as an instance of a class that subclasses ``list`` and implements the ``__iter__`` method:
+
+.. code-block:: python
+
+ import random
+ from airflow.www.utils import UIAlert
+
+
+ class DynamicAlerts(list):
+ def __iter__(self):
+ # This method is called each time Airflow iterates over DASHBOARD_UIALERTS
+ # Example: Flip a coin
+ if random.choice([True, False]):
+ yield UIAlert("Heads!", category="info")
+ else:
+ yield UIAlert("Tails!", category="warning")
Review Comment:
This example shows that on every `get_configs` calls code sample is run and the response will keep changing (dynamic aspect of alerts). I don't think we need 100 lines of code to demonstrate all use cases.
Users are free to implement `__iter__` with their own logic, replacing the random generation by an http call for instance.
This code sample + the documentation on how that logic should be kept `lightweight` for the reasons mentioned are enough IMO, I don't want to complicate the doc by adding extra lines of codes unrelated to airflow (fetching external resources, converting an http response into a generator, etc...)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Dynamic UI Alerts [airflow]
Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal commented on code in PR #54677:
URL: https://github.com/apache/airflow/pull/54677#discussion_r2338417371
##########
airflow-core/docs/howto/customize-ui.rst:
##########
@@ -81,19 +111,65 @@ or announcing changes to end users. The following example shows how to add alert
UIAlert(text="Critical error detected!", category="error"),
]
- See :ref:`Configuring local settings <set-config:configuring-local-settings>` for details on how to
- configure local settings.
+.. image:: ../img/ui-alert-message.png
-2. Restart Airflow Webserver, and you should now see:
+Markdown Content in Alerts
+--------------------------
-.. image:: ../img/ui-alert-message.png
+Markdown can be included in alert messages for richer formatting. In the following example, we show an alert
+message of heading 2 with a link included:
-Alert messages also support Markdown. In the following example, we show an alert message of heading 2 with a link included.
+.. code-block:: python
- .. code-block:: python
+ from airflow.www.utils import UIAlert
- DASHBOARD_UIALERTS = [
- UIAlert(text="## Visit [airflow.apache.org](https://airflow.apache.org)", category="info"),
- ]
+ DASHBOARD_UIALERTS = [
+ UIAlert(text="## Visit [airflow.apache.org](https://airflow.apache.org)", category="info"),
+ ]
.. image:: ../img/ui-alert-message-markdown.png
+
+Dynamic Dashboard Alerts
+------------------------
+
+Dashboard alerts support dynamic content that updates each time the dashboard page is refreshed. This allows for real-time
+status updates without requiring webserver restarts. Dynamic alerts must be defined as an instance of an iterable object.
+The recommended approach is to create a class that subclasses ``list`` and implements a custom ``__iter__`` method that
+yields fresh alerts each time Airflow iterates over the alerts.
+
+.. note::
+ When implementing dynamic alerts it is important to keep alert generation logic lightweight to avoid
+ impacting dashboard load times. Consider caching results for expensive operations and handle exceptions
+ gracefully to prevent alert generation from breaking the UI.
+
+Dynamic alerts are particularly useful for:
+
+- **Real-time notifications**: Display current status updates or announcements
+- **Deployment notifications**: Show current deployment status, build progress, or GitOps state
+- **Temporary maintenance alerts**: Provide time-sensitive information about ongoing maintenance or issues
+- **Environment-specific warnings**: Display different alerts based on current environment conditions
+- **External service status**: Show the availability of dependent services or APIs
+
+Creating Dynamic Alerts
+^^^^^^^^^^^^^^^^^^^^^^^
+
+To create dynamic alerts, define ``DASHBOARD_UIALERTS`` as an instance of a class that subclasses ``list`` and implements the ``__iter__`` method:
+
+.. code-block:: python
+
+ import random
+ from airflow.www.utils import UIAlert
+
+
+ class DynamicAlerts(list):
+ def __iter__(self):
+ # This method is called each time Airflow iterates over DASHBOARD_UIALERTS
+ # Example: Flip a coin
+ if random.choice([True, False]):
+ yield UIAlert("Heads!", category="info")
+ else:
+ yield UIAlert("Tails!", category="warning")
Review Comment:
This isn't a really practical example is it?
I think we need to clarify if the dynamic part (which you implemented here as random) can be taken from API, query database or read a text file from S3.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Dynamic UI Alerts [airflow]
Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal commented on code in PR #54677:
URL: https://github.com/apache/airflow/pull/54677#discussion_r2347099565
##########
airflow-core/docs/howto/customize-ui.rst:
##########
@@ -81,19 +111,65 @@ or announcing changes to end users. The following example shows how to add alert
UIAlert(text="Critical error detected!", category="error"),
]
- See :ref:`Configuring local settings <set-config:configuring-local-settings>` for details on how to
- configure local settings.
+.. image:: ../img/ui-alert-message.png
-2. Restart Airflow Webserver, and you should now see:
+Markdown Content in Alerts
+--------------------------
-.. image:: ../img/ui-alert-message.png
+Markdown can be included in alert messages for richer formatting. In the following example, we show an alert
+message of heading 2 with a link included:
-Alert messages also support Markdown. In the following example, we show an alert message of heading 2 with a link included.
+.. code-block:: python
- .. code-block:: python
+ from airflow.www.utils import UIAlert
- DASHBOARD_UIALERTS = [
- UIAlert(text="## Visit [airflow.apache.org](https://airflow.apache.org)", category="info"),
- ]
+ DASHBOARD_UIALERTS = [
+ UIAlert(text="## Visit [airflow.apache.org](https://airflow.apache.org)", category="info"),
+ ]
.. image:: ../img/ui-alert-message-markdown.png
+
+Dynamic Dashboard Alerts
+------------------------
+
+Dashboard alerts support dynamic content that updates each time the dashboard page is refreshed. This allows for real-time
+status updates without requiring webserver restarts. Dynamic alerts must be defined as an instance of an iterable object.
+The recommended approach is to create a class that subclasses ``list`` and implements a custom ``__iter__`` method that
+yields fresh alerts each time Airflow iterates over the alerts.
+
+.. note::
+ When implementing dynamic alerts it is important to keep alert generation logic lightweight to avoid
+ impacting dashboard load times. Consider caching results for expensive operations and handle exceptions
+ gracefully to prevent alert generation from breaking the UI.
+
+Dynamic alerts are particularly useful for:
+
+- **Real-time notifications**: Display current status updates or announcements
+- **Deployment notifications**: Show current deployment status, build progress, or GitOps state
+- **Temporary maintenance alerts**: Provide time-sensitive information about ongoing maintenance or issues
+- **Environment-specific warnings**: Display different alerts based on current environment conditions
+- **External service status**: Show the availability of dependent services or APIs
+
+Creating Dynamic Alerts
+^^^^^^^^^^^^^^^^^^^^^^^
+
+To create dynamic alerts, define ``DASHBOARD_UIALERTS`` as an instance of a class that subclasses ``list`` and implements the ``__iter__`` method:
+
+.. code-block:: python
+
+ import random
+ from airflow.www.utils import UIAlert
+
+
+ class DynamicAlerts(list):
+ def __iter__(self):
+ # This method is called each time Airflow iterates over DASHBOARD_UIALERTS
+ # Example: Flip a coin
+ if random.choice([True, False]):
+ yield UIAlert("Heads!", category="info")
+ else:
+ yield UIAlert("Tails!", category="warning")
Review Comment:
Can you share here?
The doc shouldn't be extra long but just to provide a sense of how dynamic alerting can be achieved. Say that I have a cluster that serve over 30 data engineers and there are issues with the scheduler resources. I want to post a message that notify them there is an issue and I am on it. If you can add examples of how to setup a message for similar scenario I think that would be enough.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Dynamic UI Alerts [airflow]
Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal commented on PR #54677:
URL: https://github.com/apache/airflow/pull/54677#issuecomment-3218297869
> UI Alerts are helpful for a variety of reasons, but in the current Airflow 3 implementation, they are strictly static for the entire lifetime of the webserver/api-server. Therefore, updates to UI alerts require code changes and special automation or manual rollouts/restarts when alerts must change.
This is very good if we can do that!
It's not just in Airflow 3.
@pierrejeambrun The use case of such capability is for announcing something in large dag author deployments. For example: "We have issues with K8s cluster, task may be delayed no need to contact cluster admins".
@codecae I think this feature needs some explanation in the UI alert docs about how to make it dynamic
https://github.com/apache/airflow/blob/18690f7babce185a2aa456452c6acee41fa7b77c/airflow-core/docs/howto/customize-ui.rst#L65
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Dynamic UI Alerts [airflow]
Posted by "phanikumv (via GitHub)" <gi...@apache.org>.
phanikumv commented on PR #54677:
URL: https://github.com/apache/airflow/pull/54677#issuecomment-3267266469
@codecae any chance you can address the docs change soon?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Dynamic UI Alerts [airflow]
Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal commented on code in PR #54677:
URL: https://github.com/apache/airflow/pull/54677#discussion_r2338417371
##########
airflow-core/docs/howto/customize-ui.rst:
##########
@@ -81,19 +111,65 @@ or announcing changes to end users. The following example shows how to add alert
UIAlert(text="Critical error detected!", category="error"),
]
- See :ref:`Configuring local settings <set-config:configuring-local-settings>` for details on how to
- configure local settings.
+.. image:: ../img/ui-alert-message.png
-2. Restart Airflow Webserver, and you should now see:
+Markdown Content in Alerts
+--------------------------
-.. image:: ../img/ui-alert-message.png
+Markdown can be included in alert messages for richer formatting. In the following example, we show an alert
+message of heading 2 with a link included:
-Alert messages also support Markdown. In the following example, we show an alert message of heading 2 with a link included.
+.. code-block:: python
- .. code-block:: python
+ from airflow.www.utils import UIAlert
- DASHBOARD_UIALERTS = [
- UIAlert(text="## Visit [airflow.apache.org](https://airflow.apache.org)", category="info"),
- ]
+ DASHBOARD_UIALERTS = [
+ UIAlert(text="## Visit [airflow.apache.org](https://airflow.apache.org)", category="info"),
+ ]
.. image:: ../img/ui-alert-message-markdown.png
+
+Dynamic Dashboard Alerts
+------------------------
+
+Dashboard alerts support dynamic content that updates each time the dashboard page is refreshed. This allows for real-time
+status updates without requiring webserver restarts. Dynamic alerts must be defined as an instance of an iterable object.
+The recommended approach is to create a class that subclasses ``list`` and implements a custom ``__iter__`` method that
+yields fresh alerts each time Airflow iterates over the alerts.
+
+.. note::
+ When implementing dynamic alerts it is important to keep alert generation logic lightweight to avoid
+ impacting dashboard load times. Consider caching results for expensive operations and handle exceptions
+ gracefully to prevent alert generation from breaking the UI.
+
+Dynamic alerts are particularly useful for:
+
+- **Real-time notifications**: Display current status updates or announcements
+- **Deployment notifications**: Show current deployment status, build progress, or GitOps state
+- **Temporary maintenance alerts**: Provide time-sensitive information about ongoing maintenance or issues
+- **Environment-specific warnings**: Display different alerts based on current environment conditions
+- **External service status**: Show the availability of dependent services or APIs
+
+Creating Dynamic Alerts
+^^^^^^^^^^^^^^^^^^^^^^^
+
+To create dynamic alerts, define ``DASHBOARD_UIALERTS`` as an instance of a class that subclasses ``list`` and implements the ``__iter__`` method:
+
+.. code-block:: python
+
+ import random
+ from airflow.www.utils import UIAlert
+
+
+ class DynamicAlerts(list):
+ def __iter__(self):
+ # This method is called each time Airflow iterates over DASHBOARD_UIALERTS
+ # Example: Flip a coin
+ if random.choice([True, False]):
+ yield UIAlert("Heads!", category="info")
+ else:
+ yield UIAlert("Tails!", category="warning")
Review Comment:
This isn't a really practical example.
I think we need to clarify if the dynamic part (which you implemented here as random) can be taken from API, query database or read a text file from S3.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Dynamic UI Alerts [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on PR #54677:
URL: https://github.com/apache/airflow/pull/54677#issuecomment-3276577803
Can you reformat the code, static checks are still failing.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Dynamic UI Alerts [airflow]
Posted by "codecae (via GitHub)" <gi...@apache.org>.
codecae commented on code in PR #54677:
URL: https://github.com/apache/airflow/pull/54677#discussion_r2342813095
##########
airflow-core/docs/howto/customize-ui.rst:
##########
@@ -81,19 +111,65 @@ or announcing changes to end users. The following example shows how to add alert
UIAlert(text="Critical error detected!", category="error"),
]
- See :ref:`Configuring local settings <set-config:configuring-local-settings>` for details on how to
- configure local settings.
+.. image:: ../img/ui-alert-message.png
-2. Restart Airflow Webserver, and you should now see:
+Markdown Content in Alerts
+--------------------------
-.. image:: ../img/ui-alert-message.png
+Markdown can be included in alert messages for richer formatting. In the following example, we show an alert
+message of heading 2 with a link included:
-Alert messages also support Markdown. In the following example, we show an alert message of heading 2 with a link included.
+.. code-block:: python
- .. code-block:: python
+ from airflow.www.utils import UIAlert
- DASHBOARD_UIALERTS = [
- UIAlert(text="## Visit [airflow.apache.org](https://airflow.apache.org)", category="info"),
- ]
+ DASHBOARD_UIALERTS = [
+ UIAlert(text="## Visit [airflow.apache.org](https://airflow.apache.org)", category="info"),
+ ]
.. image:: ../img/ui-alert-message-markdown.png
+
+Dynamic Dashboard Alerts
+------------------------
+
+Dashboard alerts support dynamic content that updates each time the dashboard page is refreshed. This allows for real-time
+status updates without requiring webserver restarts. Dynamic alerts must be defined as an instance of an iterable object.
+The recommended approach is to create a class that subclasses ``list`` and implements a custom ``__iter__`` method that
+yields fresh alerts each time Airflow iterates over the alerts.
+
+.. note::
+ When implementing dynamic alerts it is important to keep alert generation logic lightweight to avoid
+ impacting dashboard load times. Consider caching results for expensive operations and handle exceptions
+ gracefully to prevent alert generation from breaking the UI.
+
+Dynamic alerts are particularly useful for:
+
+- **Real-time notifications**: Display current status updates or announcements
+- **Deployment notifications**: Show current deployment status, build progress, or GitOps state
+- **Temporary maintenance alerts**: Provide time-sensitive information about ongoing maintenance or issues
+- **Environment-specific warnings**: Display different alerts based on current environment conditions
+- **External service status**: Show the availability of dependent services or APIs
+
+Creating Dynamic Alerts
+^^^^^^^^^^^^^^^^^^^^^^^
+
+To create dynamic alerts, define ``DASHBOARD_UIALERTS`` as an instance of a class that subclasses ``list`` and implements the ``__iter__`` method:
+
+.. code-block:: python
+
+ import random
+ from airflow.www.utils import UIAlert
+
+
+ class DynamicAlerts(list):
+ def __iter__(self):
+ # This method is called each time Airflow iterates over DASHBOARD_UIALERTS
+ # Example: Flip a coin
+ if random.choice([True, False]):
+ yield UIAlert("Heads!", category="info")
+ else:
+ yield UIAlert("Tails!", category="warning")
Review Comment:
I had a few examples previously that demonstrated a few use cases with a schedule and an api health check. I'm happy to augment the docs,.. just need some consensus over what those examples should be.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Dynamic UI Alerts [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on PR #54677:
URL: https://github.com/apache/airflow/pull/54677#issuecomment-3214661661
Maybe add a comment above, to explain that this allows to override the value with a Iterable. Otherwise I'm affreaid someone might remove it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Dynamic UI Alerts [airflow]
Posted by "codecae (via GitHub)" <gi...@apache.org>.
codecae commented on PR #54677:
URL: https://github.com/apache/airflow/pull/54677#issuecomment-3218181674
> Maybe add a comment above, to explain that this allows to override the value with an Iterable. Otherwise I'm affreaid someone might remove it.
Will do!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support Dynamic UI Alerts [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on PR #54677:
URL: https://github.com/apache/airflow/pull/54677#issuecomment-3352569767
labeling as bugfix because this was supported in AF2 and we probably don't want to wait for `3.2.0` release to have that behavior back.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support Dynamic UI Alerts [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun merged PR #54677:
URL: https://github.com/apache/airflow/pull/54677
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Dynamic UI Alerts [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on PR #54677:
URL: https://github.com/apache/airflow/pull/54677#issuecomment-3275748150
Looks good to me, we need to fix the CI. And I would also remove the `Advanced Dynamic Alert Examples` sections. Those super specific and the previous example is enough to understand that we can basically implement whatever we like in here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Dynamic UI Alerts [airflow]
Posted by "codecae (via GitHub)" <gi...@apache.org>.
codecae commented on PR #54677:
URL: https://github.com/apache/airflow/pull/54677#issuecomment-3275653574
Documentation updated
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Dynamic UI Alerts [airflow]
Posted by "codecae (via GitHub)" <gi...@apache.org>.
codecae commented on PR #54677:
URL: https://github.com/apache/airflow/pull/54677#issuecomment-3268040915
Absolutely!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Dynamic UI Alerts [airflow]
Posted by "codecae (via GitHub)" <gi...@apache.org>.
codecae commented on PR #54677:
URL: https://github.com/apache/airflow/pull/54677#issuecomment-3220504812
> This is very good if we can do that! It's not just in Airflow 3.
Not that it really matters, but in Airflow 2, we've been successful at making them dynamic by subclassing `list` and implementing an override for `__iter__()` (as demonstrated in the example). This could be done in a far simpler way, but the example was more representative of the workaround we've used in the past.
https://github.com/apache/airflow/blob/d9ed7b94d033dc61ee1c05aafb9f1c1f7b82cfb2/airflow/www/views.py#L1070
> @codecae I think this feature needs some explanation in the UI alert docs about how to make it dynamic
I'll try to come up with some simple doc updates to explain how to implement.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Dynamic UI Alerts [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on PR #54677:
URL: https://github.com/apache/airflow/pull/54677#issuecomment-3276578554
Other CI failures are unrelated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Support Dynamic UI Alerts [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #54677:
URL: https://github.com/apache/airflow/pull/54677#issuecomment-3352855007
### Backport successfully created: v3-1-test
<table>
<tr>
<th>Status</th>
<th>Branch</th>
<th>Result</th>
</tr>
<tr>
<td>✅</td>
<td>v3-1-test</td>
<td><a href="https://github.com/apache/airflow/pull/56259"><img src="https://img.shields.io/badge/PR-56259-blue" alt="PR Link"></a></td>
</tr>
</table>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Dynamic UI Alerts [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #54677:
URL: https://github.com/apache/airflow/pull/54677#discussion_r2348334805
##########
airflow-core/docs/howto/customize-ui.rst:
##########
@@ -81,19 +111,65 @@ or announcing changes to end users. The following example shows how to add alert
UIAlert(text="Critical error detected!", category="error"),
]
- See :ref:`Configuring local settings <set-config:configuring-local-settings>` for details on how to
- configure local settings.
+.. image:: ../img/ui-alert-message.png
-2. Restart Airflow Webserver, and you should now see:
+Markdown Content in Alerts
+--------------------------
-.. image:: ../img/ui-alert-message.png
+Markdown can be included in alert messages for richer formatting. In the following example, we show an alert
+message of heading 2 with a link included:
-Alert messages also support Markdown. In the following example, we show an alert message of heading 2 with a link included.
+.. code-block:: python
- .. code-block:: python
+ from airflow.www.utils import UIAlert
- DASHBOARD_UIALERTS = [
- UIAlert(text="## Visit [airflow.apache.org](https://airflow.apache.org)", category="info"),
- ]
+ DASHBOARD_UIALERTS = [
+ UIAlert(text="## Visit [airflow.apache.org](https://airflow.apache.org)", category="info"),
+ ]
.. image:: ../img/ui-alert-message-markdown.png
+
+Dynamic Dashboard Alerts
+------------------------
+
+Dashboard alerts support dynamic content that updates each time the dashboard page is refreshed. This allows for real-time
+status updates without requiring webserver restarts. Dynamic alerts must be defined as an instance of an iterable object.
+The recommended approach is to create a class that subclasses ``list`` and implements a custom ``__iter__`` method that
+yields fresh alerts each time Airflow iterates over the alerts.
+
+.. note::
+ When implementing dynamic alerts it is important to keep alert generation logic lightweight to avoid
+ impacting dashboard load times. Consider caching results for expensive operations and handle exceptions
+ gracefully to prevent alert generation from breaking the UI.
+
+Dynamic alerts are particularly useful for:
+
+- **Real-time notifications**: Display current status updates or announcements
+- **Deployment notifications**: Show current deployment status, build progress, or GitOps state
+- **Temporary maintenance alerts**: Provide time-sensitive information about ongoing maintenance or issues
+- **Environment-specific warnings**: Display different alerts based on current environment conditions
+- **External service status**: Show the availability of dependent services or APIs
+
+Creating Dynamic Alerts
+^^^^^^^^^^^^^^^^^^^^^^^
+
+To create dynamic alerts, define ``DASHBOARD_UIALERTS`` as an instance of a class that subclasses ``list`` and implements the ``__iter__`` method:
+
+.. code-block:: python
+
+ import random
+ from airflow.www.utils import UIAlert
+
+
+ class DynamicAlerts(list):
+ def __iter__(self):
+ # This method is called each time Airflow iterates over DASHBOARD_UIALERTS
+ # Example: Flip a coin
+ if random.choice([True, False]):
+ yield UIAlert("Heads!", category="info")
+ else:
+ yield UIAlert("Tails!", category="warning")
Review Comment:
This example shows that on every `get_configs` calls code sample is run and the response will keep changing (dynamic aspect of alerts). I don't think we need 100 lines of code to demonstrate all use cases.
Users are free to implement `__iter__` with their own logic, replacing the random generation by an http call for instance.
This code sample + the documentation on how that logic should be kept `lightweight` for the reasons mentioned are enough IMO, I don't want to complicate the doc by adding extra lines of codes unrelated to airflow (fetching external resources, converting an http response into a generator, etc...).
Maybe a good middle ground is to add an extra 'sentence' to the doc to mention that dynamic alerts can be:
> taken from API, query database or read a text file from S3.
Basically anything is valid at this point.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: Dynamic UI Alerts [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #54677:
URL: https://github.com/apache/airflow/pull/54677#discussion_r2348334805
##########
airflow-core/docs/howto/customize-ui.rst:
##########
@@ -81,19 +111,65 @@ or announcing changes to end users. The following example shows how to add alert
UIAlert(text="Critical error detected!", category="error"),
]
- See :ref:`Configuring local settings <set-config:configuring-local-settings>` for details on how to
- configure local settings.
+.. image:: ../img/ui-alert-message.png
-2. Restart Airflow Webserver, and you should now see:
+Markdown Content in Alerts
+--------------------------
-.. image:: ../img/ui-alert-message.png
+Markdown can be included in alert messages for richer formatting. In the following example, we show an alert
+message of heading 2 with a link included:
-Alert messages also support Markdown. In the following example, we show an alert message of heading 2 with a link included.
+.. code-block:: python
- .. code-block:: python
+ from airflow.www.utils import UIAlert
- DASHBOARD_UIALERTS = [
- UIAlert(text="## Visit [airflow.apache.org](https://airflow.apache.org)", category="info"),
- ]
+ DASHBOARD_UIALERTS = [
+ UIAlert(text="## Visit [airflow.apache.org](https://airflow.apache.org)", category="info"),
+ ]
.. image:: ../img/ui-alert-message-markdown.png
+
+Dynamic Dashboard Alerts
+------------------------
+
+Dashboard alerts support dynamic content that updates each time the dashboard page is refreshed. This allows for real-time
+status updates without requiring webserver restarts. Dynamic alerts must be defined as an instance of an iterable object.
+The recommended approach is to create a class that subclasses ``list`` and implements a custom ``__iter__`` method that
+yields fresh alerts each time Airflow iterates over the alerts.
+
+.. note::
+ When implementing dynamic alerts it is important to keep alert generation logic lightweight to avoid
+ impacting dashboard load times. Consider caching results for expensive operations and handle exceptions
+ gracefully to prevent alert generation from breaking the UI.
+
+Dynamic alerts are particularly useful for:
+
+- **Real-time notifications**: Display current status updates or announcements
+- **Deployment notifications**: Show current deployment status, build progress, or GitOps state
+- **Temporary maintenance alerts**: Provide time-sensitive information about ongoing maintenance or issues
+- **Environment-specific warnings**: Display different alerts based on current environment conditions
+- **External service status**: Show the availability of dependent services or APIs
+
+Creating Dynamic Alerts
+^^^^^^^^^^^^^^^^^^^^^^^
+
+To create dynamic alerts, define ``DASHBOARD_UIALERTS`` as an instance of a class that subclasses ``list`` and implements the ``__iter__`` method:
+
+.. code-block:: python
+
+ import random
+ from airflow.www.utils import UIAlert
+
+
+ class DynamicAlerts(list):
+ def __iter__(self):
+ # This method is called each time Airflow iterates over DASHBOARD_UIALERTS
+ # Example: Flip a coin
+ if random.choice([True, False]):
+ yield UIAlert("Heads!", category="info")
+ else:
+ yield UIAlert("Tails!", category="warning")
Review Comment:
This example shows that on every `get_configs` calls code sample is run and the response will keep changing (dynamic aspect of alerts). I don't think we need 100 lines of code to demonstrate all use cases.
Users are free to implement `__iter__` with their own logic, replacing the random generation by an http call for instance.
This code sample + the documentation on how that logic should be kept `lightweight` for the reasons mentioned are enough IMO, I don't want to complicate the doc by adding extra lines of codes unrelated to airflow (fetching external resources, converting an http response into a generator, etc...).
Maybe we can add an extra 'sentence' to clarify:
> taken from API, query database or read a text file from S3.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org