Skip to content

Commit b24e476

Browse files
committed
feat(cli): add daily_cost to coder ls
1 parent be40dc8 commit b24e476

File tree

9 files changed

+27
-18
lines changed

9 files changed

+27
-18
lines changed

cli/list.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type workspaceListRow struct {
3030
Outdated bool `json:"-" table:"outdated"`
3131
StartsAt string `json:"-" table:"starts at"`
3232
StopsAfter string `json:"-" table:"stops after"`
33+
DailyCost string `json:"-" table:"daily cost"`
3334
}
3435

3536
func workspaceListRowFromWorkspace(now time.Time, usersByID map[uuid.UUID]codersdk.User, workspace codersdk.Workspace) workspaceListRow {
@@ -68,6 +69,7 @@ func workspaceListRowFromWorkspace(now time.Time, usersByID map[uuid.UUID]coders
6869
Outdated: workspace.Outdated,
6970
StartsAt: autostartDisplay,
7071
StopsAfter: autostopDisplay,
72+
DailyCost: strconv.Itoa(int(workspace.LatestBuild.DailyCost)),
7173
}
7274
}
7375

@@ -78,7 +80,19 @@ func (r *RootCmd) list() *clibase.Cmd {
7880
searchQuery string
7981
displayWorkspaces []workspaceListRow
8082
formatter = cliui.NewOutputFormatter(
81-
cliui.TableFormat([]workspaceListRow{}, nil),
83+
cliui.TableFormat(
84+
[]workspaceListRow{},
85+
[]string{
86+
"workspace",
87+
"template",
88+
"status",
89+
"healthy",
90+
"last built",
91+
"outdated",
92+
"starts at",
93+
"stops after",
94+
},
95+
),
8296
cliui.JSONFormat(),
8397
)
8498
)

cli/testdata/coder_list_--help.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Aliases: ls
1111
-c, --column string-array (default: workspace,template,status,healthy,last built,outdated,starts at,stops after)
1212
Columns to display in table output. Available columns: workspace,
1313
template, status, healthy, last built, outdated, starts at, stops
14-
after.
14+
after, daily cost.
1515

1616
-o, --output string (default: table)
1717
Output format. Available formats: table, json.

docs/cli/list.md

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisionerd/proto/provisionerd.pb.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisionerd/proto/provisionerd_drpc.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisionerd/provisionerd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ func (p *Server) acquireJob(ctx context.Context) {
404404
runner.Options{
405405
Updater: p,
406406
QuotaCommitter: p,
407-
Logger: p.opts.Logger,
407+
Logger: p.opts.Logger.Named("runner"),
408408
Filesystem: p.opts.Filesystem,
409409
WorkDirectory: p.opts.WorkDirectory,
410410
Provisioner: provisioner,

provisionerd/runner/runner.go

+3
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,9 @@ func (r *Runner) buildWorkspace(ctx context.Context, stage string, req *sdkproto
964964
}
965965

966966
func (r *Runner) commitQuota(ctx context.Context, resources []*sdkproto.Resource) *proto.FailedJob {
967+
r.logger.Debug(ctx, "committing quota",
968+
slog.F("resources", resources),
969+
)
967970
cost := sumDailyCost(resources)
968971
if cost == 0 {
969972
return nil

provisionersdk/proto/provisioner.pb.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

provisionersdk/proto/provisioner_drpc.pb.go

+1-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)