Skip to content

Commit

Permalink
[AIRFLOW-2086][AIRFLOW-2393] Customize default dagrun number in tree …
Browse files Browse the repository at this point in the history
…view

Closes apache#3279 from feng-tao/reduce-tree-view

This introduces a new configuration variable to set the default
number of dag runs displayed in the tree view. For large DAGs, this
could cause timeouts in the webserver.
  • Loading branch information
Tao feng authored and artwr committed May 9, 2018
1 parent 2728138 commit 2a55ffe
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 17 deletions.
3 changes: 3 additions & 0 deletions UPDATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ assists users migrating to a new version.

## Airflow Master

### Add a configuration variable(default_dag_run_display_number) to control numbers of dag run for display
Add a configuration variable(default_dag_run_display_number) under webserver section to control num of dag run to show in UI.

### Default executor for SubDagOperator is changed to SequentialExecutor

### New Webserver UI with Role-Based Access Control
Expand Down
3 changes: 3 additions & 0 deletions airflow/config_templates/default_airflow.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ rbac = False
# Define the color of navigation bar
navbar_color = #007A87

# Default dagrun to show in UI
default_dag_run_display_number = 25


[email]
email_backend = airflow.utils.email.send_email_smtp
Expand Down
2 changes: 1 addition & 1 deletion airflow/www/templates/airflow/dag.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ <h4 class="pull-right">
<li><a href="{{ url_for("airflow.graph", dag_id=dag.dag_id, root=root, execution_date=execution_date) }}">
<span class="glyphicon glyphicon-certificate" aria-hidden="true"></span>
Graph View</a></li>
<li><a href="{{ url_for("airflow.tree", dag_id=dag.dag_id, num_runs=25, root=root) }}">
<li><a href="{{ url_for("airflow.tree", dag_id=dag.dag_id, num_runs=num_runs, root=root) }}">
<span class="glyphicon glyphicon-tree-deciduous" aria-hidden="true"></span>
Tree View
</a></li>
Expand Down
2 changes: 1 addition & 1 deletion airflow/www/templates/airflow/dags.html
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ <h2>DAGs</h2>
</a>

<!-- Tree -->
<a href="{{ url_for('airflow.tree', dag_id=dag.dag_id, num_runs=25) }}">
<a href="{{ url_for('airflow.tree', dag_id=dag.dag_id, num_runs=num_runs) }}">
<span class="glyphicon glyphicon-tree-deciduous" aria-hidden="true" data-original-title="Tree View"></span>
</a>

Expand Down
2 changes: 1 addition & 1 deletion airflow/www/templates/airflow/list_dags.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ <h2>DAGs</h2>
<svg height="10" width="10" id='dag-{{ row.dag_id }}' style="display: block;"></svg>
</td>
<td>
<a href="{{ url_for("airflow.tree", dag_id=row.dag_id, num_runs=25) }}" title="Tree View">
<a href="{{ url_for("airflow.tree", dag_id=row.dag_id, num_runs=num_runs) }}" title="Tree View">
<span class="glyphicon glyphicon-tree-deciduous" aria-hidden="true"></span>
</a>
<a href="{{ url_for("airflow.graph", dag_id=row.dag_id) }}" title="Graph View">
Expand Down
19 changes: 12 additions & 7 deletions airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
Expand Down Expand Up @@ -1227,6 +1227,7 @@ def success(self):
@wwwutils.action_logging
@provide_session
def tree(self, session=None):
default_dag_run = conf.getint('webserver', 'default_dag_run_display_number')
dag_id = request.args.get('dag_id')
blur = conf.getboolean('webserver', 'demo_mode')
dag = dagbag.get_dag(dag_id)
Expand All @@ -1239,7 +1240,7 @@ def tree(self, session=None):

base_date = request.args.get('base_date')
num_runs = request.args.get('num_runs')
num_runs = int(num_runs) if num_runs else 25
num_runs = int(num_runs) if num_runs else default_dag_run

if base_date:
base_date = timezone.parse(base_date)
Expand Down Expand Up @@ -1348,7 +1349,7 @@ def set_duration(tid):
),
root=root,
form=form,
dag=dag, data=data, blur=blur)
dag=dag, data=data, blur=blur, num_runs=num_runs)

@expose('/graph')
@login_required
Expand Down Expand Up @@ -1468,11 +1469,12 @@ class GraphForm(Form):
@wwwutils.action_logging
@provide_session
def duration(self, session=None):
default_dag_run = conf.getint('webserver', 'default_dag_run_display_number')
dag_id = request.args.get('dag_id')
dag = dagbag.get_dag(dag_id)
base_date = request.args.get('base_date')
num_runs = request.args.get('num_runs')
num_runs = int(num_runs) if num_runs else 25
num_runs = int(num_runs) if num_runs else default_dag_run

if base_date:
base_date = pendulum.parse(base_date)
Expand Down Expand Up @@ -1575,11 +1577,12 @@ def duration(self, session=None):
@wwwutils.action_logging
@provide_session
def tries(self, session=None):
default_dag_run = conf.getint('webserver', 'default_dag_run_display_number')
dag_id = request.args.get('dag_id')
dag = dagbag.get_dag(dag_id)
base_date = request.args.get('base_date')
num_runs = request.args.get('num_runs')
num_runs = int(num_runs) if num_runs else 25
num_runs = int(num_runs) if num_runs else default_dag_run

if base_date:
base_date = pendulum.parse(base_date)
Expand Down Expand Up @@ -1638,11 +1641,12 @@ def tries(self, session=None):
@wwwutils.action_logging
@provide_session
def landing_times(self, session=None):
default_dag_run = conf.getint('webserver', 'default_dag_run_display_number')
dag_id = request.args.get('dag_id')
dag = dagbag.get_dag(dag_id)
base_date = request.args.get('base_date')
num_runs = request.args.get('num_runs')
num_runs = int(num_runs) if num_runs else 25
num_runs = int(num_runs) if num_runs else default_dag_run

if base_date:
base_date = pendulum.parse(base_date)
Expand Down Expand Up @@ -1759,6 +1763,7 @@ def refresh_all(self):
@wwwutils.action_logging
@provide_session
def gantt(self, session=None):

dag_id = request.args.get('dag_id')
dag = dagbag.get_dag(dag_id)
demo_mode = conf.getboolean('webserver', 'demo_mode')
Expand Down
2 changes: 1 addition & 1 deletion airflow/www_rbac/templates/airflow/dag.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ <h4 class="pull-right">
<li><a href="{{ url_for("Airflow.graph", dag_id=dag.dag_id, root=root) }}">
<span class="glyphicon glyphicon-certificate" aria-hidden="true"></span>
Graph View</a></li>
<li><a href="{{ url_for("Airflow.tree", dag_id=dag.dag_id, num_runs=25, root=root) }}">
<li><a href="{{ url_for("Airflow.tree", dag_id=dag.dag_id, num_runs=num_runs, root=root) }}">
<span class="glyphicon glyphicon-tree-deciduous" aria-hidden="true"></span>
Tree View
</a></li>
Expand Down
2 changes: 1 addition & 1 deletion airflow/www_rbac/templates/airflow/dags.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ <h2>DAGs</h2>
</a>

<!-- Tree -->
<a href="{{ url_for('Airflow.tree', dag_id=dag.dag_id, num_runs=25) }}">
<a href="{{ url_for('Airflow.tree', dag_id=dag.dag_id, num_runs=num_runs) }}">
<span class="glyphicon glyphicon-tree-deciduous" aria-hidden="true" data-original-title="Tree View"></span>
</a>

Expand Down
14 changes: 9 additions & 5 deletions airflow/www_rbac/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ def success(self):
@action_logging
@provide_session
def tree(self, session=None):
default_dag_run = conf.getint('webserver', 'default_dag_run_display_number')
dag_id = request.args.get('dag_id')
blur = conf.getboolean('webserver', 'demo_mode')
dag = dagbag.get_dag(dag_id)
Expand All @@ -872,7 +873,7 @@ def tree(self, session=None):

base_date = request.args.get('base_date')
num_runs = request.args.get('num_runs')
num_runs = int(num_runs) if num_runs else 25
num_runs = int(num_runs) if num_runs else default_dag_run

if base_date:
base_date = timezone.parse(base_date)
Expand Down Expand Up @@ -980,7 +981,7 @@ def set_duration(tid):
),
root=root,
form=form,
dag=dag, data=data, blur=blur)
dag=dag, data=data, blur=blur, num_runs=num_runs)

@expose('/graph')
@has_access
Expand Down Expand Up @@ -1101,11 +1102,12 @@ class GraphForm(Form):
@action_logging
@provide_session
def duration(self, session=None):
default_dag_run = conf.getint('webserver', 'default_dag_run_display_number')
dag_id = request.args.get('dag_id')
dag = dagbag.get_dag(dag_id)
base_date = request.args.get('base_date')
num_runs = request.args.get('num_runs')
num_runs = int(num_runs) if num_runs else 25
num_runs = int(num_runs) if num_runs else default_dag_run

if base_date:
base_date = pendulum.parse(base_date)
Expand Down Expand Up @@ -1204,11 +1206,12 @@ def duration(self, session=None):
@action_logging
@provide_session
def tries(self, session=None):
default_dag_run = conf.getint('webserver', 'default_dag_run_display_number')
dag_id = request.args.get('dag_id')
dag = dagbag.get_dag(dag_id)
base_date = request.args.get('base_date')
num_runs = request.args.get('num_runs')
num_runs = int(num_runs) if num_runs else 25
num_runs = int(num_runs) if num_runs else default_dag_run

if base_date:
base_date = pendulum.parse(base_date)
Expand Down Expand Up @@ -1267,11 +1270,12 @@ def tries(self, session=None):
@action_logging
@provide_session
def landing_times(self, session=None):
default_dag_run = conf.getint('webserver', 'default_dag_run_display_number')
dag_id = request.args.get('dag_id')
dag = dagbag.get_dag(dag_id)
base_date = request.args.get('base_date')
num_runs = request.args.get('num_runs')
num_runs = int(num_runs) if num_runs else 25
num_runs = int(num_runs) if num_runs else default_dag_run

if base_date:
base_date = pendulum.parse(base_date)
Expand Down

0 comments on commit 2a55ffe

Please sign in to comment.