-
Notifications
You must be signed in to change notification settings - Fork 125
[reboot-cause] Use UTC to ensure consistent sorting #293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
[reboot-cause] Use UTC to ensure consistent sorting #293
Conversation
Previously reboot cause uses local timezone. This could result in the timestamp being in UTC, IDT, or any other timezone depending on the system configuration. When reboot cause history files are sorted, mixing different timezones can lead to incorrect chronological order and cause reboot cause test failure. Now change the code to use datetime.datetime.utcnow() for reboot_cause_gen_time, ensuring that all timestamps are consistently in UTC. Signed-off-by: Jianyue Wu <[email protected]>
Signed-off-by: Jianyue Wu <[email protected]>
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
hi @vvolam , do you mind to help reviewing this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, same change might be needed in scripts/procdockerstatsd as we are still using systemtime.
sonic-host-services/scripts/procdockerstatsd
Line 248 in 0028383
datetimeobj = datetime.now() |
Could you also update the PR description with the reboot history command after the fix?
@@ -254,7 +254,7 @@ def main(): | |||
previous_reboot_cause, additional_reboot_info = determine_reboot_cause() | |||
|
|||
# Current time | |||
reboot_cause_gen_time = str(datetime.datetime.now().strftime('%Y_%m_%d_%H_%M_%S')) | |||
reboot_cause_gen_time = str(datetime.datetime.utcnow().strftime('%Y_%m_%d_%H_%M_%S')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please share more details on why we need this change. I have this question because we display two timestamps in each line. The first timestamp is this one which we are trying to change to utcnow(). The second time stamp is put I believe by platform code when system goes down.
2025_07_28_13_34_54 reboot Mon Jul 28 01:32:25 PM IDT 2025 admin N/A
So if we change at one place we should change at both places?
Ideally I feel if the system tz is configured as UTC, both timestamps will be in UTC.
Previously reboot cause uses local timezone. This could result in the timestamp being in UTC, IDT, or any other timezone depending on the system configuration. When reboot cause history files are sorted, mixing different timezones can lead to incorrect chronological order and cause reboot cause test failure.
Now change the code to use datetime.datetime.utcnow() for reboot_cause_gen_time, ensuring that all timestamps are consistently in UTC.
Details:
Previously reboot-cause history will sort by name, name is using system time, could be UTC or IDT.
2025_07_28_10_48_14 reboot Mon Jul 28 01:45:45 PM IDT 2025 admin N/A
Here left side 10_48_14 is UTC time, while right side 01:45:45 is IDT time.
2025_07_28_13_41_44 reboot Mon Jul 28 01:39:13 PM IDT 2025 admin N/A
Left and right are both IDT time.
We need to make left side time aligned, so sort index will be always correct.
show reboot-cause history cmd:
Reboot cause history in test: