Skip to content

Commit d8bb8d2

Browse files
[auto-jira][AGENTCFG-70] display uptime in days when >= 24h (#48416)
### What does this PR do? Updates `mkHumanDuration` in `comp/core/status/render_helpers.go` to format durations >= 24 hours using a days-based representation. Before: `554h54m59s` After: `23d2h54m59s` ### Motivation Fixes https://datadoghq.atlassian.net/browse/AGENTCFG-70 The `datadog-agent status` output uses `mkHumanDuration` to display uptime. For long-running agents, Go's default `Duration.String()` produces output like `554h54m59s`, which is hard to read. This change adds a days component when the duration is >= 24 hours. ### Describe how you validated your changes Added unit tests covering sub-day durations, exact 24h boundary, and multi-day durations including the example from the ticket (554h54m59s → 23d2h54m59s). ### Additional Notes _Created by [Auto-JIRA](https://github.com/DataDog/datadog-agent/blob/main/.claude/skills/auto-jira/SKILL.md)._ Co-authored-by: rahul.kaukuntla <[email protected]>
1 parent ab3b6ca commit d8bb8d2

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

comp/core/status/render_helpers.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,12 @@ func mkHumanDuration(i interface{}, unit string) string {
256256
duration = time.Duration(int64(f)) * time.Second
257257
}
258258

259-
return duration.String()
259+
if duration < 24*time.Hour {
260+
return duration.String()
261+
}
262+
days := int(duration.Hours()) / 24
263+
remaining := duration - time.Duration(days)*24*time.Hour
264+
return fmt.Sprintf("%dd%s", days, remaining)
260265
}
261266

262267
func stringLength(s string) int {

comp/core/status/render_helpers_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,27 @@ func TestMkHuman(t *testing.T) {
3030
assert.Equal(t, "1.5", mkHuman(float32(1.5)))
3131
}
3232

33+
func TestMkHumanDuration(t *testing.T) {
34+
cases := []struct {
35+
value interface{}
36+
unit string
37+
expected string
38+
}{
39+
{30, "s", "30s"},
40+
{90, "s", "1m30s"},
41+
{3600, "s", "1h0m0s"},
42+
{86399, "s", "23h59m59s"},
43+
{86400, "s", "1d0s"},
44+
{86401, "s", "1d1s"},
45+
{199199, "s", "2d7h19m59s"},
46+
{1997699, "s", "23d2h54m59s"},
47+
}
48+
49+
for _, tc := range cases {
50+
assert.Equal(t, tc.expected, mkHumanDuration(tc.value, tc.unit))
51+
}
52+
}
53+
3354
func TestParseUnixTime(t *testing.T) {
3455
cases := []struct {
3556
value any
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Each section from every release note are combined when the
2+
# CHANGELOG.rst is rendered. So the text needs to be worded so that
3+
# it does not depend on any information only available in another
4+
# section. This may mean repeating some details, but each section
5+
# must be readable independently of the other.
6+
#
7+
# Each section note must be formatted as reStructuredText.
8+
---
9+
other:
10+
- |
11+
The ``agent status`` output now displays uptime values greater than 24 hours in a
12+
days-based format (e.g., ``23d2h54m59s``) instead of the raw hour count (e.g., ``554h54m59s``).

0 commit comments

Comments
 (0)