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
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat(coderd): add provisioner daemon name to provisioner jobs responses
  • Loading branch information
ssncferreira committed May 16, 2025
commit 5fc39a0a69e3ec807150b3858cf0c3fd236fd658
1 change: 1 addition & 0 deletions cli/testdata/coder_list_--output_json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,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
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 @@ -601,7 +603,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)
provisionerCloser = NewTaggedProvisionerDaemon(t, coderAPI, defaultTestDaemonName, options.ProvisionerDaemonTags)
}
client := codersdk.New(serverURL)
t.Cleanup(func() {
Expand Down Expand Up @@ -645,7 +647,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) io.Closer {
Expand Down
16 changes: 16 additions & 0 deletions coderd/database/dbmem/dbmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,14 @@ func (q *FakeQuerier) getProvisionerJobsByIDsWithQueuePositionLockedTagBasedQueu
// Step 6: Compute the final results with minimal checks
var results []database.GetProvisionerJobsByIDsWithQueuePositionRow
for _, job := range filteredJobs {
workerName := ""
// Add daemon name to provisioner job
for _, daemon := range q.provisionerDaemons {
if job.WorkerID.Valid && job.WorkerID.UUID == daemon.ID {
workerName = daemon.Name
}
}

// If the job has a computed rank, use it
if rank, found := jobQueueStats[job.ID]; found {
results = append(results, rank)
Expand All @@ -1278,6 +1286,7 @@ func (q *FakeQuerier) getProvisionerJobsByIDsWithQueuePositionLockedTagBasedQueu
ProvisionerJob: job,
QueuePosition: 0,
QueueSize: 0,
WorkerName: workerName,
})
}
}
Expand Down Expand Up @@ -4848,6 +4857,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
19 changes: 16 additions & 3 deletions coderd/database/queries.sql.go

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

15 changes: 12 additions & 3 deletions coderd/database/queries/provisionerjobs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,15 @@ SELECT
fj.created_at,
sqlc.embed(pj),
fj.queue_position,
fj.queue_size
fj.queue_size,
COALESCE(pd.name, '') AS worker_name
FROM
final_jobs fj
INNER JOIN provisioner_jobs pj
ON fj.id = pj.id -- Ensure we retrieve full details from `provisioner_jobs`.
-- JOIN with pj is required for sqlc.embed(pj) to compile successfully.
LEFT JOIN provisioner_daemons pd -- Join to get the daemon name corresponding to the job's worker_id
ON pj.worker_id = pd.id
ORDER BY
fj.created_at;

Expand Down Expand Up @@ -160,7 +163,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 +190,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 +208,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
2 changes: 2 additions & 0 deletions coderd/provisionerjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ func convertProvisionerJob(pj database.GetProvisionerJobsByIDsWithQueuePositionR
provisionerJob := pj.ProvisionerJob
job := codersdk.ProvisionerJob{
ID: provisionerJob.ID,
WorkerName: pj.WorkerName,
OrganizationID: provisionerJob.OrganizationID,
CreatedAt: provisionerJob.CreatedAt,
Type: codersdk.ProvisionerJobType(provisionerJob.Type),
Expand Down Expand Up @@ -392,6 +393,7 @@ func convertProvisionerJob(pj database.GetProvisionerJobsByIDsWithQueuePositionR
func convertProvisionerJobWithQueuePosition(pj database.GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisionerRow) codersdk.ProvisionerJob {
job := convertProvisionerJob(database.GetProvisionerJobsByIDsWithQueuePositionRow{
ProvisionerJob: pj.ProvisionerJob,
WorkerName: pj.WorkerName,
QueuePosition: pj.QueuePosition,
QueueSize: pj.QueueSize,
})
Expand Down
Loading
Loading