Skip to content

Commit 7cd2af7

Browse files
authored
Merge branch 'main' into cj/cli-testprovisionerjobs-speedup
2 parents f44c4af + 82f2e15 commit 7cd2af7

File tree

58 files changed

+1984
-1136
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1984
-1136
lines changed

.vscode/settings.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,5 @@
6060
"typos.config": ".github/workflows/typos.toml",
6161
"[markdown]": {
6262
"editor.defaultFormatter": "DavidAnson.vscode-markdownlint"
63-
},
64-
"biome.configurationPath": "./site/biome.jsonc",
65-
"biome.lsp.bin": "./site/node_modules/.bin/biome"
63+
}
6664
}

cli/provisioners.go

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package cli
22

33
import (
44
"fmt"
5+
"time"
56

67
"golang.org/x/xerrors"
78

89
"github.com/coder/coder/v2/cli/cliui"
10+
"github.com/coder/coder/v2/coderd/util/slice"
911
"github.com/coder/coder/v2/codersdk"
1012
"github.com/coder/serpent"
1113
)
@@ -39,7 +41,10 @@ func (r *RootCmd) provisionerList() *serpent.Command {
3941
cliui.TableFormat([]provisionerDaemonRow{}, []string{"created at", "last seen at", "key name", "name", "version", "status", "tags"}),
4042
cliui.JSONFormat(),
4143
)
42-
limit int64
44+
limit int64
45+
offline bool
46+
status []string
47+
maxAge time.Duration
4348
)
4449

4550
cmd := &serpent.Command{
@@ -59,7 +64,10 @@ func (r *RootCmd) provisionerList() *serpent.Command {
5964
}
6065

6166
daemons, err := client.OrganizationProvisionerDaemons(ctx, org.ID, &codersdk.OrganizationProvisionerDaemonsOptions{
62-
Limit: int(limit),
67+
Limit: int(limit),
68+
Offline: offline,
69+
Status: slice.StringEnums[codersdk.ProvisionerDaemonStatus](status),
70+
MaxAge: maxAge,
6371
})
6472
if err != nil {
6573
return xerrors.Errorf("list provisioner daemons: %w", err)
@@ -98,6 +106,27 @@ func (r *RootCmd) provisionerList() *serpent.Command {
98106
Default: "50",
99107
Value: serpent.Int64Of(&limit),
100108
},
109+
{
110+
Flag: "show-offline",
111+
FlagShorthand: "f",
112+
Env: "CODER_PROVISIONER_SHOW_OFFLINE",
113+
Description: "Show offline provisioners.",
114+
Value: serpent.BoolOf(&offline),
115+
},
116+
{
117+
Flag: "status",
118+
FlagShorthand: "s",
119+
Env: "CODER_PROVISIONER_LIST_STATUS",
120+
Description: "Filter by provisioner status.",
121+
Value: serpent.EnumArrayOf(&status, slice.ToStrings(codersdk.ProvisionerDaemonStatusEnums())...),
122+
},
123+
{
124+
Flag: "max-age",
125+
FlagShorthand: "m",
126+
Env: "CODER_PROVISIONER_LIST_MAX_AGE",
127+
Description: "Filter provisioners by maximum age.",
128+
Value: serpent.DurationOf(&maxAge),
129+
},
101130
}...)
102131

103132
orgContext.AttachOptions(cmd)

cli/provisioners_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,74 @@ func TestProvisioners_Golden(t *testing.T) {
197197
clitest.TestGoldenFile(t, t.Name(), got.Bytes(), replace)
198198
})
199199

200+
t.Run("list with offline provisioner daemons", func(t *testing.T) {
201+
t.Parallel()
202+
203+
var got bytes.Buffer
204+
inv, root := clitest.New(t,
205+
"provisioners",
206+
"list",
207+
"--show-offline",
208+
)
209+
inv.Stdout = &got
210+
clitest.SetupConfig(t, templateAdminClient, root)
211+
err := inv.Run()
212+
require.NoError(t, err)
213+
214+
clitest.TestGoldenFile(t, t.Name(), got.Bytes(), replace)
215+
})
216+
217+
t.Run("list provisioner daemons by status", func(t *testing.T) {
218+
t.Parallel()
219+
220+
var got bytes.Buffer
221+
inv, root := clitest.New(t,
222+
"provisioners",
223+
"list",
224+
"--status=idle,offline,busy",
225+
)
226+
inv.Stdout = &got
227+
clitest.SetupConfig(t, templateAdminClient, root)
228+
err := inv.Run()
229+
require.NoError(t, err)
230+
231+
clitest.TestGoldenFile(t, t.Name(), got.Bytes(), replace)
232+
})
233+
234+
t.Run("list provisioner daemons without offline", func(t *testing.T) {
235+
t.Parallel()
236+
237+
var got bytes.Buffer
238+
inv, root := clitest.New(t,
239+
"provisioners",
240+
"list",
241+
"--status=idle,busy",
242+
)
243+
inv.Stdout = &got
244+
clitest.SetupConfig(t, templateAdminClient, root)
245+
err := inv.Run()
246+
require.NoError(t, err)
247+
248+
clitest.TestGoldenFile(t, t.Name(), got.Bytes(), replace)
249+
})
250+
251+
t.Run("list provisioner daemons by max age", func(t *testing.T) {
252+
t.Parallel()
253+
254+
var got bytes.Buffer
255+
inv, root := clitest.New(t,
256+
"provisioners",
257+
"list",
258+
"--max-age=1h",
259+
)
260+
inv.Stdout = &got
261+
clitest.SetupConfig(t, templateAdminClient, root)
262+
err := inv.Run()
263+
require.NoError(t, err)
264+
265+
clitest.TestGoldenFile(t, t.Name(), got.Bytes(), replace)
266+
})
267+
200268
// Test jobs list with template admin as members are currently
201269
// unable to access provisioner jobs. In the future (with RBAC
202270
// changes), we may allow them to view _their_ jobs.
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
ID CREATED AT LAST SEEN AT NAME VERSION TAGS KEY NAME STATUS CURRENT JOB ID CURRENT JOB STATUS PREVIOUS JOB ID PREVIOUS JOB STATUS ORGANIZATION
2-
00000000-0000-0000-aaaa-000000000000 ====[timestamp]===== ====[timestamp]===== default-provisioner v0.0.0-devel map[owner: scope:organization] built-in idle <nil> <nil> 00000000-0000-0000-bbbb-000000000001 succeeded Coder
3-
00000000-0000-0000-aaaa-000000000001 ====[timestamp]===== ====[timestamp]===== provisioner-1 v0.0.0 map[foo:bar owner: scope:organization] built-in busy 00000000-0000-0000-bbbb-000000000002 running <nil> <nil> Coder
4-
00000000-0000-0000-aaaa-000000000002 ====[timestamp]===== ====[timestamp]===== provisioner-2 v0.0.0 map[owner: scope:organization] built-in offline <nil> <nil> 00000000-0000-0000-bbbb-000000000003 succeeded Coder
5-
00000000-0000-0000-aaaa-000000000003 ====[timestamp]===== ====[timestamp]===== provisioner-3 v0.0.0 map[owner: scope:organization] built-in idle <nil> <nil> <nil> <nil> Coder
1+
ID CREATED AT LAST SEEN AT NAME VERSION TAGS KEY NAME STATUS CURRENT JOB ID CURRENT JOB STATUS PREVIOUS JOB ID PREVIOUS JOB STATUS ORGANIZATION
2+
00000000-0000-0000-aaaa-000000000000 ====[timestamp]===== ====[timestamp]===== default-provisioner v0.0.0-devel map[owner: scope:organization] built-in idle <nil> <nil> 00000000-0000-0000-bbbb-000000000001 succeeded Coder
3+
00000000-0000-0000-aaaa-000000000001 ====[timestamp]===== ====[timestamp]===== provisioner-1 v0.0.0 map[foo:bar owner: scope:organization] built-in busy 00000000-0000-0000-bbbb-000000000002 running <nil> <nil> Coder
4+
00000000-0000-0000-aaaa-000000000003 ====[timestamp]===== ====[timestamp]===== provisioner-3 v0.0.0 map[owner: scope:organization] built-in idle <nil> <nil> <nil> <nil> Coder
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CREATED AT LAST SEEN AT KEY NAME NAME VERSION STATUS TAGS
2+
====[timestamp]===== ====[timestamp]===== built-in default-provisioner v0.0.0-devel idle map[owner: scope:organization]
3+
====[timestamp]===== ====[timestamp]===== built-in provisioner-1 v0.0.0 busy map[foo:bar owner: scope:organization]
4+
====[timestamp]===== ====[timestamp]===== built-in provisioner-3 v0.0.0 idle map[owner: scope:organization]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATED AT LAST SEEN AT KEY NAME NAME VERSION STATUS TAGS
2+
====[timestamp]===== ====[timestamp]===== built-in default-provisioner v0.0.0-devel idle map[owner: scope:organization]
3+
====[timestamp]===== ====[timestamp]===== built-in provisioner-1 v0.0.0 busy map[foo:bar owner: scope:organization]
4+
====[timestamp]===== ====[timestamp]===== built-in provisioner-2 v0.0.0 offline map[owner: scope:organization]
5+
====[timestamp]===== ====[timestamp]===== built-in provisioner-3 v0.0.0 idle map[owner: scope:organization]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CREATED AT LAST SEEN AT KEY NAME NAME VERSION STATUS TAGS
2+
====[timestamp]===== ====[timestamp]===== built-in default-provisioner v0.0.0-devel idle map[owner: scope:organization]
3+
====[timestamp]===== ====[timestamp]===== built-in provisioner-1 v0.0.0 busy map[foo:bar owner: scope:organization]
4+
====[timestamp]===== ====[timestamp]===== built-in provisioner-3 v0.0.0 idle map[owner: scope:organization]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATED AT LAST SEEN AT KEY NAME NAME VERSION STATUS TAGS
2+
====[timestamp]===== ====[timestamp]===== built-in default-provisioner v0.0.0-devel idle map[owner: scope:organization]
3+
====[timestamp]===== ====[timestamp]===== built-in provisioner-1 v0.0.0 busy map[foo:bar owner: scope:organization]
4+
====[timestamp]===== ====[timestamp]===== built-in provisioner-2 v0.0.0 offline map[owner: scope:organization]
5+
====[timestamp]===== ====[timestamp]===== built-in provisioner-3 v0.0.0 idle map[owner: scope:organization]

cli/testdata/coder_provisioner_list_--help.golden

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,17 @@ OPTIONS:
1717
-l, --limit int, $CODER_PROVISIONER_LIST_LIMIT (default: 50)
1818
Limit the number of provisioners returned.
1919

20+
-m, --max-age duration, $CODER_PROVISIONER_LIST_MAX_AGE
21+
Filter provisioners by maximum age.
22+
2023
-o, --output table|json (default: table)
2124
Output format.
2225

26+
-f, --show-offline bool, $CODER_PROVISIONER_SHOW_OFFLINE
27+
Show offline provisioners.
28+
29+
-s, --status [offline|idle|busy], $CODER_PROVISIONER_LIST_STATUS
30+
Filter by provisioner status.
31+
2332
———
2433
Run `coder --help` for a list of global options.

coderd/agentapi/stats_test.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ func TestUpdateStates(t *testing.T) {
4141
Name: "tpl",
4242
}
4343
workspace = database.Workspace{
44-
ID: uuid.New(),
45-
OwnerID: user.ID,
46-
TemplateID: template.ID,
47-
Name: "xyz",
48-
TemplateName: template.Name,
44+
ID: uuid.New(),
45+
OwnerID: user.ID,
46+
OwnerUsername: user.Username,
47+
TemplateID: template.ID,
48+
Name: "xyz",
49+
TemplateName: template.Name,
4950
}
5051
agent = database.WorkspaceAgent{
5152
ID: uuid.New(),
@@ -138,9 +139,6 @@ func TestUpdateStates(t *testing.T) {
138139
// Workspace gets fetched.
139140
dbM.EXPECT().GetWorkspaceByAgentID(gomock.Any(), agent.ID).Return(workspace, nil)
140141

141-
// User gets fetched to hit the UpdateAgentMetricsFn.
142-
dbM.EXPECT().GetUserByID(gomock.Any(), user.ID).Return(user, nil)
143-
144142
// We expect an activity bump because ConnectionCount > 0.
145143
dbM.EXPECT().ActivityBumpWorkspace(gomock.Any(), database.ActivityBumpWorkspaceParams{
146144
WorkspaceID: workspace.ID,
@@ -380,9 +378,6 @@ func TestUpdateStates(t *testing.T) {
380378
LastUsedAt: now.UTC(),
381379
}).Return(nil)
382380

383-
// User gets fetched to hit the UpdateAgentMetricsFn.
384-
dbM.EXPECT().GetUserByID(gomock.Any(), user.ID).Return(user, nil)
385-
386381
resp, err := api.UpdateStats(context.Background(), req)
387382
require.NoError(t, err)
388383
require.Equal(t, &agentproto.UpdateStatsResponse{
@@ -498,9 +493,6 @@ func TestUpdateStates(t *testing.T) {
498493
LastUsedAt: now,
499494
}).Return(nil)
500495

501-
// User gets fetched to hit the UpdateAgentMetricsFn.
502-
dbM.EXPECT().GetUserByID(gomock.Any(), user.ID).Return(user, nil)
503-
504496
// Ensure that pubsub notifications are sent.
505497
notifyDescription := make(chan struct{})
506498
ps.SubscribeWithErr(wspubsub.WorkspaceEventChannel(workspace.OwnerID),

0 commit comments

Comments
 (0)