This is an automated email from the ASF dual-hosted git repository. potiuk pushed a commit to branch v1-10-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 9d97eaa5e2cfa0f792af00bfb539acd6cf4bd35a Author: Xiaodong DENG <[email protected]> AuthorDate: Mon May 11 08:35:31 2020 +0200 Avoid color info in response of /dag_stats & /task_stats (#8742) * Avoid color info in response of /dag_stats & /task_stats Currently the color for each state is repeatedly appearing in the response payload of endpoints /dag_stats and /task_stats. This can be avoided by having the mapping between state and color in the static file, and map each state into different color at client side after client receives the necessary info, instead of passing duplicated color information in the response payload. This significantly reduces the size of data to be transferred from server to client. (cherry-picked from bed1995) --- airflow/www_rbac/templates/airflow/dags.html | 5 +++-- airflow/www_rbac/views.py | 10 ++++++---- tests/www_rbac/test_views.py | 12 ++++++++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/airflow/www_rbac/templates/airflow/dags.html b/airflow/www_rbac/templates/airflow/dags.html index f2f131c..095c213 100644 --- a/airflow/www_rbac/templates/airflow/dags.html +++ b/airflow/www_rbac/templates/airflow/dags.html @@ -244,6 +244,7 @@ const DAGS_INDEX = "{{ url_for('Airflow.index') }}"; const ENTER_KEY_CODE = 13; + const STATE_COLOR = {{ state_color|tojson }}; $('#tags_filter').select2({ placeholder: "Filter dags", @@ -412,7 +413,7 @@ }) .attr('stroke', function(d) { if (d.count > 0) - return d.color; + return STATE_COLOR[d.state]; else { return 'gainsboro'; } @@ -489,7 +490,7 @@ }) .attr('stroke', function(d) { if (d.count > 0) - return d.color; + return STATE_COLOR[d.state]; else { return 'gainsboro'; } diff --git a/airflow/www_rbac/views.py b/airflow/www_rbac/views.py index c7831c4..a626d87 100644 --- a/airflow/www_rbac/views.py +++ b/airflow/www_rbac/views.py @@ -332,6 +332,9 @@ class Airflow(AirflowBaseView): num_of_pages = int(math.ceil(num_of_all_dags / float(dags_per_page))) + state_color_mapping = State.state_color.copy() + state_color_mapping["null"] = state_color_mapping.pop(None) + return self.render_template( 'airflow/dags.html', dags=dags, @@ -348,6 +351,7 @@ class Airflow(AirflowBaseView): status=arg_status_filter if arg_status_filter else None), num_runs=num_runs, tags=tags, + state_color=state_color_mapping, status_filter=arg_status_filter, status_count_all=all_dags_count, status_count_active=status_count_active, @@ -395,8 +399,7 @@ class Airflow(AirflowBaseView): count = data.get(dag_id, {}).get(state, 0) payload[dag_id].append({ 'state': state, - 'count': count, - 'color': State.color(state) + 'count': count }) return wwwutils.json_response(payload) @@ -489,8 +492,7 @@ class Airflow(AirflowBaseView): count = data.get(dag_id, {}).get(state, 0) payload[dag_id].append({ 'state': state, - 'count': count, - 'color': State.color(state) + 'count': count }) return wwwutils.json_response(payload) diff --git a/tests/www_rbac/test_views.py b/tests/www_rbac/test_views.py index 35dab60..2a18c6a 100644 --- a/tests/www_rbac/test_views.py +++ b/tests/www_rbac/test_views.py @@ -487,6 +487,14 @@ class TestAirflowBaseViews(TestBase): def test_home(self): resp = self.client.get('home', follow_redirects=True) self.check_content_in_response('DAGs', resp) + val_state_color_mapping = 'const STATE_COLOR = {"failed": "red", ' \ + '"null": "lightblue", "queued": "gray", ' \ + '"removed": "lightgrey", "running": "lime", ' \ + '"scheduled": "tan", "shutdown": "blue", ' \ + '"skipped": "pink", "success": "green", ' \ + '"up_for_reschedule": "turquoise", ' \ + '"up_for_retry": "gold", "upstream_failed": "orange"};' + self.check_content_in_response(val_state_color_mapping, resp) def test_home_filter_tags(self): from airflow.www_rbac.views import FILTER_TAGS_COOKIE @@ -548,7 +556,7 @@ class TestAirflowBaseViews(TestBase): resp = self.client.post('task_stats', follow_redirects=True) self.assertEqual(resp.status_code, 200) self.assertEqual(set(list(resp.json.items())[0][1][0].keys()), - {'state', 'count', 'color'}) + {'state', 'count'}) def test_task_stats_only_noncompleted(self): conf.set("webserver", "show_recent_stats_for_completed_runs", "False") @@ -1538,7 +1546,7 @@ class TestDagACLView(TestBase): resp = self.client.post('dag_stats', follow_redirects=True) self.check_content_in_response('example_bash_operator', resp) self.assertEqual(set(list(resp.json.items())[0][1][0].keys()), - {'state', 'count', 'color'}) + {'state', 'count'}) def test_dag_stats_failure(self): self.logout()
