Skip to content

Commit 1282878

Browse files
authored
[CI] Fix bad timestamps being reported (#130941)
Yesterday, the monitoring reported a job queued for 23h59. After some checks, it appears no such job existed: the age of the workflows on completion was at most 5 hours during the last 48 hours. After some digging, I found out GitHub could return a job with a start date slightly before the creation date, or completion date before start date. This would cause python to compute a negative timedelta, which would then be reported in grafana as a full 24h delta due to the conversions. Adding code to ignore negative delta, but logging them.
1 parent d77ef14 commit 1282878

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

.ci/metrics/metrics.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,24 @@ def github_get_metrics(
168168
created_at = job.created_at
169169
started_at = job.started_at
170170
completed_at = job.completed_at
171-
queue_time = started_at - created_at
172-
run_time = completed_at - started_at
171+
172+
# GitHub API can return results where the started_at is slightly
173+
# later then the created_at (or completed earlier than started).
174+
# This would cause a -23h59mn delta, which will show up as +24h
175+
# queue/run time on grafana.
176+
if started_at < created_at:
177+
logging.info(
178+
"Workflow {} started before being created.".format(task.id)
179+
)
180+
queue_time = datetime.timedelta(seconds=0)
181+
else:
182+
queue_time = started_at - created_at
183+
if completed_at < started_at:
184+
logging.info("Workflow {} finished before starting.".format(task.id))
185+
run_time = datetime.timedelta(seconds=0)
186+
else:
187+
run_time = completed_at - started_at
188+
173189
if run_time.seconds == 0:
174190
continue
175191

0 commit comments

Comments
 (0)