Skip to content

Commit

Permalink
[AIRFLOW-225] Better units for task duration graph
Browse files Browse the repository at this point in the history
Right now the job duration window defaults to hours, which for short lived tasks
results in numbers out to five decimals. This patch adjusts the scale of the Y-axis
in accordance with the maximum value of the durations to be shown.
  • Loading branch information
sekikn committed Jun 15, 2016
1 parent 8aa7160 commit 1141165
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1477,18 +1477,35 @@ def duration(self):
include_downstream=False)

all_data = []
max_duration = 0
for task in dag.tasks:
data = []
for ti in task.get_task_instances(session, start_date=min_date,
end_date=base_date):
if ti.duration:
data.append([
ti.execution_date.isoformat(),
float(ti.duration) / (60*60)
ti.duration
])
if max_duration < ti.duration:
max_duration = ti.duration
if data:
all_data.append({'data': data, 'name': task.task_id})

def divide_durations(all_data, denom):
for data in all_data:
for d in data['data']:
d[1] /= denom

if 60*60 < max_duration:
unit = 'hours'
divide_durations(all_data, float(60*60))
elif 60 < max_duration:
unit = 'minutes'
divide_durations(all_data, 60.0)
else:
unit = 'seconds'

tis = dag.get_task_instances(
session, start_date=min_date, end_date=base_date)
dates = sorted(list({ti.execution_date for ti in tis}))
Expand All @@ -1503,7 +1520,7 @@ def duration(self):
'airflow/chart.html',
dag=dag,
data=json.dumps(all_data),
chart_options={'yAxis': {'title': {'text': 'hours'}}},
chart_options={'yAxis': {'title': {'text': unit}}},
height="700px",
demo_mode=conf.getboolean('webserver', 'demo_mode'),
root=root,
Expand Down

0 comments on commit 1141165

Please sign in to comment.