Skip to content

feat: add provisioner daemon name to provisioner jobs responses #17877

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 8 commits into from
May 19, 2025
2 changes: 1 addition & 1 deletion cli/testdata/coder_provisioner_jobs_list_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ OPTIONS:
-O, --org string, $CODER_ORGANIZATION
Select which organization (uuid or name) to use.

-c, --column [id|created at|started at|completed at|canceled at|error|error code|status|worker id|file id|tags|queue position|queue size|organization id|template version id|workspace build id|type|available workers|template version name|template id|template name|template display name|template icon|workspace id|workspace name|organization|queue] (default: created at,id,type,template display name,status,queue,tags)
-c, --column [id|created at|started at|completed at|canceled at|error|error code|status|worker id|worker name|file id|tags|queue position|queue size|organization id|template version id|workspace build id|type|available workers|template version name|template id|template name|template display name|template icon|workspace id|workspace name|organization|queue] (default: created at,id,type,template display name,status,queue,tags)
Columns to display in table output.

-l, --limit int, $CODER_PROVISIONER_JOB_LIST_LIMIT (default: 50)
Expand Down
2 changes: 2 additions & 0 deletions cli/testdata/coder_provisioner_jobs_list_--output_json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"completed_at": "====[timestamp]=====",
"status": "succeeded",
"worker_id": "====[workspace build worker ID]=====",
"worker_name": "test-daemon",
"file_id": "=====[workspace build file ID]======",
"tags": {
"owner": "",
Expand Down Expand Up @@ -34,6 +35,7 @@
"completed_at": "====[timestamp]=====",
"status": "succeeded",
"worker_id": "====[workspace build worker ID]=====",
"worker_name": "test-daemon",
"file_id": "=====[workspace build file ID]======",
"tags": {
"owner": "",
Expand Down
4 changes: 2 additions & 2 deletions cli/testdata/coder_provisioner_list.golden
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
CREATED AT LAST SEEN AT KEY NAME NAME VERSION STATUS TAGS
====[timestamp]===== ====[timestamp]===== built-in test v0.0.0-devel idle map[owner: scope:organization]
CREATED AT LAST SEEN AT KEY NAME NAME VERSION STATUS TAGS
====[timestamp]===== ====[timestamp]===== built-in test-daemon v0.0.0-devel idle map[owner: scope:organization]
2 changes: 1 addition & 1 deletion cli/testdata/coder_provisioner_list_--output_json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"key_id": "00000000-0000-0000-0000-000000000001",
"created_at": "====[timestamp]=====",
"last_seen_at": "====[timestamp]=====",
"name": "test",
"name": "test-daemon",
"version": "v0.0.0-devel",
"api_version": "1.6",
"provisioners": [
Expand Down
3 changes: 3 additions & 0 deletions coderd/apidoc/docs.go

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

3 changes: 3 additions & 0 deletions coderd/apidoc/swagger.json

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

6 changes: 4 additions & 2 deletions coderd/coderdtest/coderdtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ import (
"github.com/coder/coder/v2/testutil"
)

const defaultTestDaemonName = "test-daemon"

type Options struct {
// AccessURL denotes a custom access URL. By default we use the httptest
// server's URL. Setting this may result in unexpected behavior (especially
Expand Down Expand Up @@ -602,7 +604,7 @@ func NewWithAPI(t testing.TB, options *Options) (*codersdk.Client, io.Closer, *c
setHandler(rootHandler)
var provisionerCloser io.Closer = nopcloser{}
if options.IncludeProvisionerDaemon {
provisionerCloser = NewTaggedProvisionerDaemon(t, coderAPI, "test", options.ProvisionerDaemonTags, coderd.MemoryProvisionerWithVersionOverride(options.ProvisionerDaemonVersion))
provisionerCloser = NewTaggedProvisionerDaemon(t, coderAPI, defaultTestDaemonName, options.ProvisionerDaemonTags, coderd.MemoryProvisionerWithVersionOverride(options.ProvisionerDaemonVersion))
}
client := codersdk.New(serverURL)
t.Cleanup(func() {
Expand Down Expand Up @@ -646,7 +648,7 @@ func (c *ProvisionerdCloser) Close() error {
// well with coderd testing. It registers the "echo" provisioner for
// quick testing.
func NewProvisionerDaemon(t testing.TB, coderAPI *coderd.API) io.Closer {
return NewTaggedProvisionerDaemon(t, coderAPI, "test", nil)
return NewTaggedProvisionerDaemon(t, coderAPI, defaultTestDaemonName, nil)
}

func NewTaggedProvisionerDaemon(t testing.TB, coderAPI *coderd.API, name string, provisionerTags map[string]string, opts ...coderd.MemoryProvisionerDaemonOption) io.Closer {
Expand Down
7 changes: 7 additions & 0 deletions coderd/database/dbmem/dbmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -4848,6 +4848,13 @@ func (q *FakeQuerier) GetProvisionerJobsByOrganizationAndStatusWithQueuePosition
row.AvailableWorkers = append(row.AvailableWorkers, worker.ID)
}
}

// Add daemon name to provisioner job
for _, daemon := range q.provisionerDaemons {
if job.WorkerID.Valid && job.WorkerID.UUID == daemon.ID {
row.WorkerName = daemon.Name
}
}
rows = append(rows, row)
}

Expand Down
12 changes: 10 additions & 2 deletions coderd/database/queries.sql.go

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

10 changes: 8 additions & 2 deletions coderd/database/queries/provisionerjobs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ SELECT
COALESCE(t.display_name, '') AS template_display_name,
COALESCE(t.icon, '') AS template_icon,
w.id AS workspace_id,
COALESCE(w.name, '') AS workspace_name
COALESCE(w.name, '') AS workspace_name,
-- Include the name of the provisioner_daemon associated to the job
COALESCE(pd.name, '') AS worker_name
FROM
provisioner_jobs pj
LEFT JOIN
Expand All @@ -185,6 +187,9 @@ LEFT JOIN
t.id = tv.template_id
AND t.organization_id = pj.organization_id
)
LEFT JOIN
-- Join to get the daemon name corresponding to the job's worker_id
provisioner_daemons pd ON pd.id = pj.worker_id
WHERE
pj.organization_id = @organization_id::uuid
AND (COALESCE(array_length(@ids::uuid[], 1), 0) = 0 OR pj.id = ANY(@ids::uuid[]))
Expand All @@ -200,7 +205,8 @@ GROUP BY
t.display_name,
t.icon,
w.id,
w.name
w.name,
pd.name
ORDER BY
pj.created_at DESC
LIMIT
Expand Down
1 change: 1 addition & 0 deletions coderd/provisionerjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ func convertProvisionerJobWithQueuePosition(pj database.GetProvisionerJobsByOrga
QueuePosition: pj.QueuePosition,
QueueSize: pj.QueueSize,
})
job.WorkerName = pj.WorkerName
job.AvailableWorkers = pj.AvailableWorkers
job.Metadata = codersdk.ProvisionerJobMetadata{
TemplateVersionName: pj.TemplateVersionName,
Expand Down
Loading
Loading