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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]