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

Condense output of compose top #12391

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
compose top: ensure CMD is right-most column
Signed-off-by: Dominik Menke <dom@digineo.de>
  • Loading branch information
dmke committed Dec 31, 2024
commit 33a819ef9d24f1ffbc40296e4e38f8ed6fd68f95
15 changes: 15 additions & 0 deletions cmd/compose/top.go
Original file line number Diff line number Diff line change
@@ -101,6 +101,21 @@ func collectTop(containers []api.ContainerProcSummary) (topHeader, []topEntries)
entries = append(entries, entry)
}
}

// ensure CMD is the right-most column
if pos, ok := header["CMD"]; ok {
max := pos
for h, i := range header {
if i > max {
max = i
}
if i > pos {
header[h] = i - 1
}
}
header["CMD"] = max
}

return header, entries
}

16 changes: 8 additions & 8 deletions cmd/compose/top_test.go
Original file line number Diff line number Diff line change
@@ -245,8 +245,8 @@ func TestRunTopCore(t *testing.T) {
"STIME": 6,
"TTY": 7,
"TIME": 8,
"CMD": 9,
"GID": 10,
"GID": 9,
"CMD": 10,
}, header)
assert.EqualValues(t, []topEntries{
{
@@ -311,12 +311,12 @@ func TestRunTopCore(t *testing.T) {
err := topPrint(&buf, header, entries)
require.NoError(t, err)
assert.Equal(t, trim(`
SERVICE # UID PID PPID C STIME TTY TIME CMD GID
simple 1 root 1 1 0 12:00 ? 00:00:01 /entrypoint -
noppid 1 root 1 - 0 12:00 ? 00:00:02 /entrypoint -
extra-hdr 1 root 1 1 0 12:00 ? 00:00:03 /entrypoint 1
multiple 1 root 1 1 0 12:00 ? 00:00:04 /entrypoint -
multiple 1 root 123 1 0 12:00 ? 00:00:42 sleep infinity -
SERVICE # UID PID PPID C STIME TTY TIME GID CMD
simple 1 root 1 1 0 12:00 ? 00:00:01 - /entrypoint
noppid 1 root 1 - 0 12:00 ? 00:00:02 - /entrypoint
extra-hdr 1 root 1 1 0 12:00 ? 00:00:03 1 /entrypoint
multiple 1 root 1 1 0 12:00 ? 00:00:04 - /entrypoint
multiple 1 root 123 1 0 12:00 ? 00:00:42 - sleep infinity
`), buf.String())

})