Skip to content

Commit

Permalink
Allow changing Task States Colors (#9520)
Browse files Browse the repository at this point in the history
(cherry picked from commit e1108d42d2b3b9c049ed8872176923621b4c8d79)

GitOrigin-RevId: 80089bab2ea1d2a29b678e813ea026d841c4cfde
  • Loading branch information
kaxil authored and Cloud Composer Team committed Jun 4, 2021
1 parent 2ac1b12 commit dd10cee
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 54 deletions.
14 changes: 14 additions & 0 deletions airflow/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@ def timing(self, stat, dt):
# The JSON library to use for DAG Serialization and De-Serialization
json = json

# Dictionary containing State and colors associated to each state to
# display on the Webserver
STATE_COLORS = {
"queued": "gray",
"running": "lime",
"success": "green",
"failed": "red",
"up_for_retry": "gold",
"up_for_reschedule": "turquoise",
"upstream_failed": "orange",
"skipped": "pink",
"scheduled": "tan",
}


def policy(task_instance):
"""
Expand Down
3 changes: 3 additions & 0 deletions airflow/utils/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

from builtins import object

from airflow.settings import STATE_COLORS


class State(object):
"""
Expand Down Expand Up @@ -80,6 +82,7 @@ class State(object):
SCHEDULED: 'tan',
NONE: 'lightblue',
}
state_color.update(STATE_COLORS) # type: ignore

@classmethod
def color(cls, state):
Expand Down
5 changes: 3 additions & 2 deletions airflow/www/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from airflow import models, version, LoggingMixin
from airflow.configuration import conf
from airflow.models.connection import Connection
from airflow.settings import Session
from airflow.settings import Session, STATE_COLORS

from airflow.www.blueprints import routes
from airflow.logging_config import configure_logging
Expand Down Expand Up @@ -188,7 +188,8 @@ def jinja_globals():
'log_auto_tailing_offset': conf.getint(
'webserver', 'log_auto_tailing_offset', fallback=30),
'log_animation_speed': conf.getint(
'webserver', 'log_animation_speed', fallback=1000)
'webserver', 'log_animation_speed', fallback=1000),
'state_color_mapping': STATE_COLORS
}

@app.before_request
Expand Down
7 changes: 7 additions & 0 deletions airflow/www/templates/admin/master.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
<link href="{{ url_for('static', filename='bootstrap-theme.css') }}" rel="stylesheet">
<link rel="icon" type="image/png" href="{{ url_for("static", filename="pin_32.png") }}">
<link rel="stylesheet" type="text/css" href="{{ url_for("static", filename="main.css") }}">
<style type="text/css">
{% for state, state_color in state_color_mapping.items() %}
span.{{state}} {
background-color: {{state_color}};
}
{% endfor %}
</style>
{% endblock %}

{% block tail_js %}
Expand Down
7 changes: 7 additions & 0 deletions airflow/www/templates/airflow/gantt.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
<link href="{{ admin_static.url(filename='vendor/bootstrap-daterangepicker/daterangepicker-bs2.css') }}" rel="stylesheet"/>
<link type="text/css" href="{{ url_for('static', filename='gantt.css') }}" rel="stylesheet" />
<link type="text/css" href="{{ url_for('static', filename='tree.css') }}" rel="stylesheet" />
<style type="text/css">
{% for state, state_color in state_color_mapping.items() %}
rect.{{state}} {
fill: {{state_color}};
}
{% endfor %}
</style>
{% endblock %}

{% block body %}
Expand Down
18 changes: 10 additions & 8 deletions airflow/www/templates/airflow/graph.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
{{ super() }}
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='dagre.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='graph.css') }}">
<style type="text/css">
{% for state, state_color in state_color_mapping.items() %}
g.node.{{state}} rect {
stroke: {{state_color}};
}
{% endfor %}
</style>
{% endblock %}

{% block body %}
Expand Down Expand Up @@ -64,14 +71,9 @@

<div>
<div class="legend_item state" style="border-color:white;">no_status</div>
<div class="legend_item state" style="border-color:grey;">queued</div>
<div class="legend_item state" style="border-color:gold;">up_for_retry</div>
<div class="legend_item state" style="border-color:turquoise;">up_for_reschedule</div>
<div class="legend_item state" style="border-color:orange;">upstream_failed</div>
<div class="legend_item state" style="border-color:pink;">skipped</div>
<div class="legend_item state" style="border-color:red;">failed</div>
<div class="legend_item state" style="border-color:lime;">running</div>
<div class="legend_item state" style="border-color:green;">success</div>
{% for state, state_color in state_color_mapping.items() %}
<div class="legend_item state" style="border-color:{{state_color}};">{{state}}</div>
{% endfor %}
</div>
<div style="clear:both;"></div>
</div>
Expand Down
27 changes: 11 additions & 16 deletions airflow/www/templates/airflow/tree.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
{{ super() }}
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='tree.css') }}">
<link href="{{ admin_static.url(filename='vendor/bootstrap-daterangepicker/daterangepicker-bs2.css') }}" rel="stylesheet">
<style type="text/css">
{% for state, state_color in state_color_mapping.items() %}
rect.{{state}} {
fill: {{state_color}};
}
{% endfor %}
</style>
{% endblock %}

{% block body %}
Expand All @@ -46,22 +53,10 @@
<div>
<div class="legend_item" style="border: none;">no_status</div>
<div class="square" style="background: white;"></div>
<div class="legend_item" style="border: none;">queued</div>
<div class="square" style="background: grey;"></div>
<div class="legend_item" style="border: none;">up_for_retry</div>
<div class="square" style="background: gold;"></div>
<div class="legend_item" style="border: none;">up_for_reschedule</div>
<div class="square" style="background: turquoise;"></div>
<div class="legend_item" style="border: none;">upstream_failed</div>
<div class="square" style="background: orange;"></div>
<div class="legend_item" style="border: none;">skipped</div>
<div class="square" style="background: pink;"></div>
<div class="legend_item" style="border: none;">failed</div>
<div class="square" style="background: red;"></div>
<div class="legend_item" style="border: none;">running</div>
<div class="square" style="background: lime;"></div>
<div class="legend_item" style="border: none;">success</div>
<div class="square" style="background: green;"></div>
{% for state, state_color in state_color_mapping.items() %}
<div class="legend_item" style="border: none;">{{state}}</div>
<div class="square" style="background: {{state_color}};"></div>
{% endfor %}
{% for op in operators %}
<div class="legend_circle" style="background:{{ op.ui_color }};">
</div>
Expand Down
3 changes: 2 additions & 1 deletion airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
from airflow.exceptions import AirflowException
from airflow.models import BaseOperator, Connection, DagRun, errors, XCom
from airflow.models.dagcode import DagCode
from airflow.settings import STORE_SERIALIZED_DAGS
from airflow.settings import STATE_COLORS, STORE_SERIALIZED_DAGS
from airflow.operators.subdag_operator import SubDagOperator
from airflow.ti_deps.dep_context import RUNNING_DEPS, SCHEDULER_QUEUED_DEPS, DepContext
from airflow.utils import timezone
Expand Down Expand Up @@ -2319,6 +2319,7 @@ def get_int_arg(value, default=0):

state_color_mapping = State.state_color.copy()
state_color_mapping["null"] = state_color_mapping.pop(None)
state_color_mapping.update(STATE_COLORS)

return self.render(
'airflow/dags.html',
Expand Down
4 changes: 3 additions & 1 deletion airflow/www_rbac/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from airflow import settings, version
from airflow.configuration import conf
from airflow.logging_config import configure_logging
from airflow.settings import STATE_COLORS
from airflow.www_rbac.static_config import configure_manifest_files

app = None # type: Any
Expand Down Expand Up @@ -242,7 +243,8 @@ def jinja_globals(): # pylint: disable=unused-variable
'log_auto_tailing_offset': conf.getint(
'webserver', 'log_auto_tailing_offset', fallback=30),
'log_animation_speed': conf.getint(
'webserver', 'log_animation_speed', fallback=1000)
'webserver', 'log_animation_speed', fallback=1000),
'state_color_mapping': STATE_COLORS
}

if 'analytics_tool' in conf.getsection('webserver'):
Expand Down
7 changes: 7 additions & 0 deletions airflow/www_rbac/templates/airflow/gantt.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
{{ super() }}
<link type="text/css" href="{{ url_for('static', filename='css/gantt.css') }}" rel="stylesheet" />
<link type="text/css" href="{{ url_for('static', filename='css/tree.css') }}" rel="stylesheet" />
<style type="text/css">
{% for state, state_color in state_color_mapping.items() %}
rect.{{state}} {
fill: {{state_color}};
}
{% endfor %}
</style>
{% endblock %}

{% block content %}
Expand Down
18 changes: 10 additions & 8 deletions airflow/www_rbac/templates/airflow/graph.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
{% block head_css %}
{{ super() }}
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/graph.css') }}">
<style type="text/css">
{% for state, state_color in state_color_mapping.items() %}
g.node.{{state}} rect {
stroke: {{state_color}};
}
{% endfor %}
</style>
{% endblock %}

{% block content %}
Expand Down Expand Up @@ -58,14 +65,9 @@

<div>
<div class="legend_item state" style="border-color:white;">no_status</div>
<div class="legend_item state" style="border-color:grey;">queued</div>
<div class="legend_item state" style="border-color:gold;">up_for_retry</div>
<div class="legend_item state" style="border-color:turquoise;">up_for_reschedule</div>
<div class="legend_item state" style="border-color:orange;">upstream_failed</div>
<div class="legend_item state" style="border-color:pink;">skipped</div>
<div class="legend_item state" style="border-color:red;">failed</div>
<div class="legend_item state" style="border-color:lime;">running</div>
<div class="legend_item state" style="border-color:green;">success</div>
{% for state, state_color in state_color_mapping.items() %}
<div class="legend_item state" style="border-color:{{state_color}};">{{state}}</div>
{% endfor %}
</div>
<div style="clear:both;"></div>
</div>
Expand Down
8 changes: 7 additions & 1 deletion airflow/www_rbac/templates/airflow/master.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
{% endif %}
<link href="{{ url_for_asset('main.css') }}" rel="stylesheet">
<link href="{{ url_for_asset('bootstrap-datetimepicker.min.css') }}" rel="stylesheet">

<style type="text/css">
{% for state, state_color in state_color_mapping.items() %}
span.{{state}} {
background-color: {{state_color}};
}
{% endfor %}
</style>
<link rel="icon" type="image/png" href="{{ url_for('static', filename='pin_32.png') }}">
{% endblock %}

Expand Down
27 changes: 11 additions & 16 deletions airflow/www_rbac/templates/airflow/tree.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
{% block head_css %}
{{ super() }}
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/tree.css') }}">
<style type="text/css">
{% for state, state_color in state_color_mapping.items() %}
rect.{{state}} {
fill: {{state_color}};
}
{% endfor %}
</style>
{% endblock %}

{% block content %}
Expand All @@ -44,22 +51,10 @@
<div>
<div class="legend_item" style="border: none;">no_status</div>
<div class="square" style="background: white;"></div>
<div class="legend_item" style="border: none;">queued</div>
<div class="square" style="background: grey;"></div>
<div class="legend_item" style="border: none;">up_for_retry</div>
<div class="square" style="background: gold;"></div>
<div class="legend_item" style="border: none;">up_for_reschedule</div>
<div class="square" style="background: turquoise;"></div>
<div class="legend_item" style="border: none;">upstream_failed</div>
<div class="square" style="background: orange;"></div>
<div class="legend_item" style="border: none;">skipped</div>
<div class="square" style="background: pink;"></div>
<div class="legend_item" style="border: none;">failed</div>
<div class="square" style="background: red;"></div>
<div class="legend_item" style="border: none;">running</div>
<div class="square" style="background: lime;"></div>
<div class="legend_item" style="border: none;">success</div>
<div class="square" style="background: green;"></div>
{% for state, state_color in state_color_mapping.items() %}
<div class="legend_item" style="border: none;">{{state}}</div>
<div class="square" style="background: {{state_color}};"></div>
{% endfor %}
{% for op in operators %}
<div class="legend_circle" style="background:{{ op.ui_color }};">
</div>
Expand Down
3 changes: 2 additions & 1 deletion airflow/www_rbac/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
from airflow.models import Connection, DagModel, DagRun, DagTag, Log, SlaMiss, TaskFail, XCom, errors
from airflow.exceptions import AirflowException
from airflow.models.dagcode import DagCode
from airflow.settings import STORE_SERIALIZED_DAGS
from airflow.settings import STATE_COLORS, STORE_SERIALIZED_DAGS
from airflow.ti_deps.dep_context import RUNNING_DEPS, SCHEDULER_QUEUED_DEPS, DepContext
from airflow.utils import timezone
from airflow.utils.dates import infer_time_unit, scale_time_units
Expand Down Expand Up @@ -334,6 +334,7 @@ def get_int_arg(value, default=0):

state_color_mapping = State.state_color.copy()
state_color_mapping["null"] = state_color_mapping.pop(None)
state_color_mapping.update(STATE_COLORS)

return self.render_template(
'airflow/dags.html',
Expand Down

0 comments on commit dd10cee

Please sign in to comment.