Skip to content

feat(cli): add daily_cost to coder ls #9200

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 1 commit into from
Aug 19, 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
feat(cli): add daily_cost to coder ls
  • Loading branch information
ammario committed Aug 18, 2023
commit b24e47684367033f20673dcde5b797bf0d2bc152
16 changes: 15 additions & 1 deletion cli/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type workspaceListRow struct {
Outdated bool `json:"-" table:"outdated"`
StartsAt string `json:"-" table:"starts at"`
StopsAfter string `json:"-" table:"stops after"`
DailyCost string `json:"-" table:"daily cost"`
}

func workspaceListRowFromWorkspace(now time.Time, usersByID map[uuid.UUID]codersdk.User, workspace codersdk.Workspace) workspaceListRow {
Expand Down Expand Up @@ -68,6 +69,7 @@ func workspaceListRowFromWorkspace(now time.Time, usersByID map[uuid.UUID]coders
Outdated: workspace.Outdated,
StartsAt: autostartDisplay,
StopsAfter: autostopDisplay,
DailyCost: strconv.Itoa(int(workspace.LatestBuild.DailyCost)),
}
}

Expand All @@ -78,7 +80,19 @@ func (r *RootCmd) list() *clibase.Cmd {
searchQuery string
displayWorkspaces []workspaceListRow
formatter = cliui.NewOutputFormatter(
cliui.TableFormat([]workspaceListRow{}, nil),
cliui.TableFormat(
[]workspaceListRow{},
[]string{
"workspace",
"template",
"status",
"healthy",
"last built",
"outdated",
"starts at",
"stops after",
},
),
cliui.JSONFormat(),
)
)
Expand Down
2 changes: 1 addition & 1 deletion cli/testdata/coder_list_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Aliases: ls
-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, healthy, last built, outdated, starts at, stops
after.
after, daily cost.

-o, --output string (default: table)
Output format. Available formats: table, json.
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/list.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions provisionerd/proto/provisionerd.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion provisionerd/proto/provisionerd_drpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion provisionerd/provisionerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ func (p *Server) acquireJob(ctx context.Context) {
runner.Options{
Updater: p,
QuotaCommitter: p,
Logger: p.opts.Logger,
Logger: p.opts.Logger.Named("runner"),
Filesystem: p.opts.Filesystem,
WorkDirectory: p.opts.WorkDirectory,
Provisioner: provisioner,
Expand Down
3 changes: 3 additions & 0 deletions provisionerd/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,9 @@ func (r *Runner) buildWorkspace(ctx context.Context, stage string, req *sdkproto
}

func (r *Runner) commitQuota(ctx context.Context, resources []*sdkproto.Resource) *proto.FailedJob {
r.logger.Debug(ctx, "committing quota",
slog.F("resources", resources),
)
cost := sumDailyCost(resources)
if cost == 0 {
return nil
Expand Down
4 changes: 2 additions & 2 deletions provisionersdk/proto/provisioner.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions provisionersdk/proto/provisioner_drpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.