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
systemd: Display uptime on overview page #13885
systemd: Display uptime on overview page #13885
Conversation
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.
Nice, thanks!
I have some comments about codestyle, nothing serious really.
The main problem this PR has is that the uptime will never update while the page is loaded. It needs to follow up and update itself. (When it shows 15 minutes, it needs to update to 16, 17... automatically).
Thanks for the comments. I fixed them and implemented automatic update of the uptime via a separate timer. |
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.
Thanks for working on this feature!
This needs a test as well, in check-system-info. I suggest one that uses the real uptime and merely asserts that it shows something (text is not empty), and then another one that fakes it with a known value. I. e. create a temporary file with a fixed uptime value, bind-mount it to /proc/uptime, log into Cockpit, and assert the human-formatted value. If that sounds too daunting for you, I'm happy to help with the test.
Thanks! This looks and works nicely now: @garrett, any objections/comments? So from my POV what remains is an integration test. Do you want to have a stab at this, or want me to write one? |
First impressions from what I see in this PR:
I'll check it out locally now. |
My machine has been up for 2 hours and 26 minutes, but it just says "2 hours" in the system information area. It should say "2 hours 26 minutes". Otherwise, it's looking good (once the string is just "Uptime", without the "System" part, as it's already under "System information".) |
There is a lot of bantering about humanize() precision on StackOverflow and moment issue. If you prefer a more precise result, then we can't use humanize(), and you need to go back to a custom implementation. (But you may want to extend it to cover months and years as well?) |
@martinpitt: That's fine then, if we're using humanize() as-is. We can optimize it later (or not). |
I changed to label to contain "Uptime" only. |
Thanks @martin-schiffner! I added a small code cleanup and an integration test. I didn't force-push, the whole thing will be squashed into a single commit on landing anyway. @marusak, as I meddled with this PR quite a bit now, do you mind reviewing this? Thanks! I also updated the screenshot. |
Happy with the code now, but don't want to self-review.
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.
Nice thanks!
The test is a bit simpler than I expected, but I think good enough :)
I'm happy to extend it a bit, what do you have in mind? |
I was thinking something like:
|
We could check that the string contains "second", "minute", "hour", "day", or "month", and then hope that nobody runs the test on a machine that runs for longer. But that gets dangerously close to testing moment itself, which I'd like to avoid.
Yes, I'll add one more case (although it's similar to above -- we don't really want to test moment).
The test already checks that it updates automatically (if that is what you mean by "follows"). We just need to take into account that each new case will increase the test time by a full minute. |
@marusak: I added a second case. |
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.
thanks!
I see this was merged into master on 22 April - does that mean it should automatically show system uptime in the "System Information" panel? Asking as mine doesn't and I ended up making a plugin to show the system uptime and last boot time, before finding this issue. |
yes, if you use cockpit-218 or newer |
Ah, CentOS 8 default repos are only cockpit-211. Bummer. Thanks for the response! 👍 |
Implementing issue #13541 for displaying the system uptime in the System Information card on the Overview page.