Don't rely on timezone in conversion of durations to HH:MM strings in Job logs
Summary
When the GitLab server runs on a non-UTC timezone, and specifically a timezone that uses a 30 minute offset such as the India Standard Time, the section durations on the Web UI when viewing job logs show up as 30:00
instead of 00:00
.
This is because we're using the expression Time.at(duration_in_seconds).strftime("%M:%S")
to convert a duration value such as 0
into 00:00
.
Since Time.at applies the local timezone, the epoch timestamp returned carries the configured timezone's 30 minute offset, which gets printed by %M
.
Steps to reproduce
- Install GitLab on a server that has IST (India) or SGT (Singapore) timezones configured as its default.
- Run a CI job on this instance.
- Check job logs for section durations.
Note: Singapore is +0800, but in 1970 (epoch time for 0) it used to be +0730.
Example Project
This does not affect GitLab.com, whose server timezone isn't one amongst the affected.
What is the current bug behavior?
Zero job log section durations are shown as 30 minutes (30:00
)
What is the expected correct behavior?
Zero job log section durations are shown as 0 minutes (00:00
)
Relevant logs and/or screenshots
Output of checks
The bug can be reproduced on current GitLab master too. It was originally reported on 13.6.
[24] pry(main)> Time.at(0)
=> 1970-01-01 05:30:00 +0530
[25] pry(main)> Time.at(0).zone
=> "IST"
[26] pry(main)> Time.at(0).strftime("%M:%S")
=> "30:00"
Possible fixes
Change the way a job log section duration is formatted into a MM:SS
string: https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/ansi2json/line.rb#L79-81 (in method set_section_duration
), so it does not rely on timezone correctness.