Skip to content
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

add uptime to hostinfo checkup and tests #1392

Merged
merged 2 commits into from
Oct 12, 2023

Conversation

zackattack01
Copy link
Contributor

This change adds uptime to the Host Info checkup.

It will appear as informational output for doctor/flare as follows:

Host Info: hostname: example-macbook.localdomain, uptime: 7 days, 23 hours, 8 minutes, 38 seconds

It will be logged within checkpoints as follows:

zack:launcher❱ lastcheck 'Host Info' | jq '{uptime, uptime_friendly}'
{
  "uptime": 687982,
  "uptime_friendly": "7 days, 23 hours, 6 minutes, 22 seconds"
}

RebeccaMahany
RebeccaMahany previously approved these changes Oct 11, 2023
hc.data["uptime_friendly"] = formatUptime(uptimeRaw)
}

hc.data["uptime"] = uptimeRaw
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be inside that err == nil

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i assumed it would just be zero value and the friendly would show the error. I can leave unset in that case if you'd like

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm never really sure if the return is defined if there's an error. So my bias would be to drop it. (it should be zero, but...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah makes sense, adding to the follow up! thanks

@@ -71,6 +82,34 @@ func hostName() string {
return hostname
}

// formatUptime takes a raw uptime value in seconds
// and returns a human friendly relative time string
func formatUptime(uptime uint64) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fancy! I'd take fractional days.

tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := formatUptime(tt.uptime); got != tt.want {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, but we usually use expected and actual

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thank you!

@zackattack01 zackattack01 added this pull request to the merge queue Oct 12, 2023
Merged via the queue into main with commit 9c09e63 Oct 12, 2023
24 checks passed
@zackattack01 zackattack01 deleted the zack/add_uptime_to_checkups branch October 12, 2023 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants