Skip to content

Conversation

@codecae
Copy link
Contributor

@codecae codecae commented Aug 19, 2025

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, the existing behavior of 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'
  1. Wait for the api-server to restart completely.
  2. Open the UI and refresh the dashboard page multiple times to see the UI 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.

@boring-cyborg boring-cyborg bot added the area:API Airflow's REST/HTTP API label Aug 19, 2025
@codecae codecae force-pushed the feature/dynamic_ui_alerts branch 2 times, most recently from 1fc2e95 to b358eda Compare August 19, 2025 18:06
Copy link
Member

@pierrejeambrun pierrejeambrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@codecae
Copy link
Contributor Author

codecae commented Aug 21, 2025

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. Also -- we have made use of this functionality in Airflow 2 for years and would love to continue using it in Airflow 3.

@pierrejeambrun
Copy link
Member

pierrejeambrun commented Aug 22, 2025

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.

@codecae
Copy link
Contributor Author

codecae commented Aug 24, 2025

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!

@eladkal
Copy link
Contributor

eladkal commented Aug 24, 2025

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

Add custom alert messages on the dashboard

@eladkal eladkal added this to the Airflow 3.1.0 milestone Aug 24, 2025
@codecae codecae force-pushed the feature/dynamic_ui_alerts branch from b358eda to 9415506 Compare August 25, 2025 14:01
@codecae
Copy link
Contributor Author

codecae commented Aug 25, 2025

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.

dashboard_alerts = [

@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.

Copy link
Member

@pierrejeambrun pierrejeambrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad to hear that this will serve users, I agree a small piece of documentation would be great!

@phanikumv
Copy link
Contributor

@codecae any chance you can address the docs change soon?

@codecae
Copy link
Contributor Author

codecae commented Sep 8, 2025

Absolutely!

@kaxil kaxil modified the milestones: Airflow 3.1.0, Airflow 3.1+ Sep 9, 2025
@codecae codecae force-pushed the feature/dynamic_ui_alerts branch from 9415506 to c97766a Compare September 10, 2025 16:19
@codecae
Copy link
Contributor Author

codecae commented Sep 10, 2025

Documentation updated

@codecae codecae force-pushed the feature/dynamic_ui_alerts branch 2 times, most recently from 504e6ca to 2464b58 Compare September 10, 2025 16:23
@pierrejeambrun
Copy link
Member

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.

@codecae codecae force-pushed the feature/dynamic_ui_alerts branch from 2464b58 to 2294543 Compare September 10, 2025 19:48
@pierrejeambrun pierrejeambrun added this to the Airflow 3.1.1 milestone Sep 30, 2025
@pierrejeambrun pierrejeambrun added the type:bug-fix Changelog: Bug Fixes label Sep 30, 2025
@pierrejeambrun pierrejeambrun changed the title feat: Dynamic UI Alerts Support Dynamic UI Alerts Sep 30, 2025
@pierrejeambrun
Copy link
Member

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.

@pierrejeambrun pierrejeambrun added the backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch label Sep 30, 2025
@pierrejeambrun pierrejeambrun merged commit 12a9d7b into apache:main Sep 30, 2025
113 checks passed
github-actions bot pushed a commit that referenced this pull request Sep 30, 2025
* feat: Dynamic UI Alerts

* docs: updated ui customization docs to include dynamic alerts

* docs: updated dynamic alerts documentation

* fix: corrected whitespace in customize-ui.rst

* fix: corrected whitespace in customize-ui.rst

---------
(cherry picked from commit 12a9d7b)

Co-authored-by: codecae <codecae@users.noreply.github.com>
Co-authored-by: Curtis Bangert <bangert.curtis+git@gmail.com>
@github-actions
Copy link

Backport successfully created: v3-1-test

Status Branch Result
v3-1-test PR Link

abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 1, 2025
* feat: Dynamic UI Alerts

* docs: updated ui customization docs to include dynamic alerts

* docs: updated dynamic alerts documentation

* fix: corrected whitespace in customize-ui.rst

* fix: corrected whitespace in customize-ui.rst

---------

Co-authored-by: Curtis Bangert <bangert.curtis+git@gmail.com>
pierrejeambrun pushed a commit that referenced this pull request Oct 1, 2025
* feat: Dynamic UI Alerts

* docs: updated ui customization docs to include dynamic alerts

* docs: updated dynamic alerts documentation

* fix: corrected whitespace in customize-ui.rst

* fix: corrected whitespace in customize-ui.rst

---------
(cherry picked from commit 12a9d7b)

Co-authored-by: codecae <codecae@users.noreply.github.com>
Co-authored-by: Curtis Bangert <bangert.curtis+git@gmail.com>
pierrejeambrun pushed a commit that referenced this pull request Oct 1, 2025
* feat: Dynamic UI Alerts

* docs: updated ui customization docs to include dynamic alerts

* docs: updated dynamic alerts documentation

* fix: corrected whitespace in customize-ui.rst

* fix: corrected whitespace in customize-ui.rst

---------
(cherry picked from commit 12a9d7b)

Co-authored-by: codecae <codecae@users.noreply.github.com>
Co-authored-by: Curtis Bangert <bangert.curtis+git@gmail.com>
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 2, 2025
* feat: Dynamic UI Alerts

* docs: updated ui customization docs to include dynamic alerts

* docs: updated dynamic alerts documentation

* fix: corrected whitespace in customize-ui.rst

* fix: corrected whitespace in customize-ui.rst

---------

Co-authored-by: Curtis Bangert <bangert.curtis+git@gmail.com>
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 3, 2025
* feat: Dynamic UI Alerts

* docs: updated ui customization docs to include dynamic alerts

* docs: updated dynamic alerts documentation

* fix: corrected whitespace in customize-ui.rst

* fix: corrected whitespace in customize-ui.rst

---------

Co-authored-by: Curtis Bangert <bangert.curtis+git@gmail.com>
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 4, 2025
* feat: Dynamic UI Alerts

* docs: updated ui customization docs to include dynamic alerts

* docs: updated dynamic alerts documentation

* fix: corrected whitespace in customize-ui.rst

* fix: corrected whitespace in customize-ui.rst

---------

Co-authored-by: Curtis Bangert <bangert.curtis+git@gmail.com>
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 5, 2025
* feat: Dynamic UI Alerts

* docs: updated ui customization docs to include dynamic alerts

* docs: updated dynamic alerts documentation

* fix: corrected whitespace in customize-ui.rst

* fix: corrected whitespace in customize-ui.rst

---------

Co-authored-by: Curtis Bangert <bangert.curtis+git@gmail.com>
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 5, 2025
* feat: Dynamic UI Alerts

* docs: updated ui customization docs to include dynamic alerts

* docs: updated dynamic alerts documentation

* fix: corrected whitespace in customize-ui.rst

* fix: corrected whitespace in customize-ui.rst

---------

Co-authored-by: Curtis Bangert <bangert.curtis+git@gmail.com>
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 7, 2025
* feat: Dynamic UI Alerts

* docs: updated ui customization docs to include dynamic alerts

* docs: updated dynamic alerts documentation

* fix: corrected whitespace in customize-ui.rst

* fix: corrected whitespace in customize-ui.rst

---------

Co-authored-by: Curtis Bangert <bangert.curtis+git@gmail.com>
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 8, 2025
* feat: Dynamic UI Alerts

* docs: updated ui customization docs to include dynamic alerts

* docs: updated dynamic alerts documentation

* fix: corrected whitespace in customize-ui.rst

* fix: corrected whitespace in customize-ui.rst

---------

Co-authored-by: Curtis Bangert <bangert.curtis+git@gmail.com>
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 9, 2025
* feat: Dynamic UI Alerts

* docs: updated ui customization docs to include dynamic alerts

* docs: updated dynamic alerts documentation

* fix: corrected whitespace in customize-ui.rst

* fix: corrected whitespace in customize-ui.rst

---------

Co-authored-by: Curtis Bangert <bangert.curtis+git@gmail.com>
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 10, 2025
* feat: Dynamic UI Alerts

* docs: updated ui customization docs to include dynamic alerts

* docs: updated dynamic alerts documentation

* fix: corrected whitespace in customize-ui.rst

* fix: corrected whitespace in customize-ui.rst

---------

Co-authored-by: Curtis Bangert <bangert.curtis+git@gmail.com>
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 11, 2025
* feat: Dynamic UI Alerts

* docs: updated ui customization docs to include dynamic alerts

* docs: updated dynamic alerts documentation

* fix: corrected whitespace in customize-ui.rst

* fix: corrected whitespace in customize-ui.rst

---------

Co-authored-by: Curtis Bangert <bangert.curtis+git@gmail.com>
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 12, 2025
* feat: Dynamic UI Alerts

* docs: updated ui customization docs to include dynamic alerts

* docs: updated dynamic alerts documentation

* fix: corrected whitespace in customize-ui.rst

* fix: corrected whitespace in customize-ui.rst

---------

Co-authored-by: Curtis Bangert <bangert.curtis+git@gmail.com>
dabla pushed a commit to dabla/airflow that referenced this pull request Oct 12, 2025
* feat: Dynamic UI Alerts

* docs: updated ui customization docs to include dynamic alerts

* docs: updated dynamic alerts documentation

* fix: corrected whitespace in customize-ui.rst

* fix: corrected whitespace in customize-ui.rst

---------

Co-authored-by: Curtis Bangert <bangert.curtis+git@gmail.com>
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 14, 2025
* feat: Dynamic UI Alerts

* docs: updated ui customization docs to include dynamic alerts

* docs: updated dynamic alerts documentation

* fix: corrected whitespace in customize-ui.rst

* fix: corrected whitespace in customize-ui.rst

---------

Co-authored-by: Curtis Bangert <bangert.curtis+git@gmail.com>
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 15, 2025
* feat: Dynamic UI Alerts

* docs: updated ui customization docs to include dynamic alerts

* docs: updated dynamic alerts documentation

* fix: corrected whitespace in customize-ui.rst

* fix: corrected whitespace in customize-ui.rst

---------

Co-authored-by: Curtis Bangert <bangert.curtis+git@gmail.com>
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 17, 2025
* feat: Dynamic UI Alerts

* docs: updated ui customization docs to include dynamic alerts

* docs: updated dynamic alerts documentation

* fix: corrected whitespace in customize-ui.rst

* fix: corrected whitespace in customize-ui.rst

---------

Co-authored-by: Curtis Bangert <bangert.curtis+git@gmail.com>
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 19, 2025
* feat: Dynamic UI Alerts

* docs: updated ui customization docs to include dynamic alerts

* docs: updated dynamic alerts documentation

* fix: corrected whitespace in customize-ui.rst

* fix: corrected whitespace in customize-ui.rst

---------

Co-authored-by: Curtis Bangert <bangert.curtis+git@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch type:bug-fix Changelog: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants