From b289028d0abf56f453be9b2ba01969bfe38c3352 Mon Sep 17 00:00:00 2001 From: Helen Koike Date: Sun, 24 Dec 2023 12:55:47 -0300 Subject: [PATCH] ci/ci_gantt_chart: show duration on hover Show the duration of the given phase on hover. Signed-off-by: Helen Koike Part-of: --- bin/ci/ci_gantt_chart.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bin/ci/ci_gantt_chart.py b/bin/ci/ci_gantt_chart.py index 882ab5424b3..8b9472217a0 100755 --- a/bin/ci/ci_gantt_chart.py +++ b/bin/ci/ci_gantt_chart.py @@ -10,6 +10,7 @@ import argparse import gitlab import plotly.express as px +from gitlab_common import pretty_duration from datetime import datetime, timedelta from gitlab_common import read_token, GITLAB_URL, get_gitlab_pipeline_from_url @@ -22,6 +23,17 @@ def calculate_queued_at(job): return datetime.fromisoformat(started_at) - timedelta(seconds=job.queued_duration) +def calculate_time_difference(time1, time2): + if not time1 or not time2: + return None + if type(time1) is str: + time1 = datetime.fromisoformat(time1.replace("Z", "+00:00")) + if type(time2) is str: + time2 = datetime.fromisoformat(time2.replace("Z", "+00:00")) + + diff = time2 - time1 + return pretty_duration(diff.seconds) + def create_task_name(job): status_color = {"success": "green", "failed": "red"}.get(job.status, "grey") @@ -37,6 +49,7 @@ def add_gantt_bar(job, tasks): "Job": task_name, "Start": job.created_at, "Finish": queued_at, + "Duration": calculate_time_difference(job.created_at, queued_at), "Phase": "Waiting dependencies", } ) @@ -45,6 +58,7 @@ def add_gantt_bar(job, tasks): "Job": task_name, "Start": queued_at, "Finish": job.started_at, + "Duration": calculate_time_difference(queued_at, job.started_at), "Phase": "Queued", } ) @@ -53,6 +67,7 @@ def add_gantt_bar(job, tasks): "Job": task_name, "Start": job.started_at, "Finish": job.finished_at, + "Duration": calculate_time_difference(job.started_at, job.finished_at), "Phase": "Running", } ) @@ -86,6 +101,7 @@ def generate_gantt_chart(pipeline): y="Job", color="Phase", title=title, + hover_data=["Duration"], ) # Calculate the height dynamically