Skip to content

feat(cli): show workspace health in list #8541

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

Merged
merged 3 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions cli/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"fmt"
"strconv"
"time"

"github.com/google/uuid"
Expand All @@ -24,6 +25,7 @@ type workspaceListRow struct {
WorkspaceName string `json:"-" table:"workspace,default_sort"`
Template string `json:"-" table:"template"`
Status string `json:"-" table:"status"`
Healthy string `json:"-" table:"healthy"`
LastBuilt string `json:"-" table:"last built"`
Outdated bool `json:"-" table:"outdated"`
StartsAt string `json:"-" table:"starts at"`
Expand Down Expand Up @@ -51,12 +53,17 @@ func workspaceListRowFromWorkspace(now time.Time, usersByID map[uuid.UUID]coders
}
}

healthy := ""
Copy link
Member

Choose a reason for hiding this comment

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

Technically, it could be covered with unit tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

Testing an individual column feels a bit overkill, I think this would be a good fit for a golden-file type test (we could do that for multiple commands).

Essentially, set up a server, some workspace and agents, a list of commands to run, and generate a golden file for each command.

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with leaving it as is.

if status == "Starting" || status == "Started" {
healthy = strconv.FormatBool(workspace.Health.Healthy)
}
user := usersByID[workspace.OwnerID]
return workspaceListRow{
Workspace: workspace,
WorkspaceName: user.Username + "/" + workspace.Name,
Template: workspace.TemplateName,
Status: status,
Healthy: healthy,
LastBuilt: durationDisplay(lastBuilt),
Outdated: workspace.Outdated,
StartsAt: autostartDisplay,
Expand Down
5 changes: 3 additions & 2 deletions cli/testdata/coder_list_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ Aliases: ls
-a, --all bool
Specifies whether all workspaces will be listed or not.

-c, --column string-array (default: workspace,template,status,last built,outdated,starts at,stops after)
-c, --column string-array (default: workspace,template,status,healthy,last built,outdated,starts at,stops after)
Columns to display in table output. Available columns: workspace,
template, status, last built, outdated, starts at, stops after.
template, status, healthy, last built, outdated, starts at, stops
after.

-o, --output string (default: table)
Output format. Available formats: table, json.
Expand Down
10 changes: 5 additions & 5 deletions docs/cli/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ Specifies whether all workspaces will be listed or not.

### -c, --column

| | |
| ------- | -------------------------------------------------------------------------------- |
| Type | <code>string-array</code> |
| Default | <code>workspace,template,status,last built,outdated,starts at,stops after</code> |
| | |
| ------- | ---------------------------------------------------------------------------------------- |
| Type | <code>string-array</code> |
| Default | <code>workspace,template,status,healthy,last built,outdated,starts at,stops after</code> |

Columns to display in table output. Available columns: workspace, template, status, last built, outdated, starts at, stops after.
Columns to display in table output. Available columns: workspace, template, status, healthy, last built, outdated, starts at, stops after.

### -o, --output

Expand Down