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
Prev Previous commit
Next Next commit
fix: limit worker_name addition to GetProvisionerJobsByOrganizationAn…
…dStatusWithQueuePositionAndProvisioner query
  • Loading branch information
ssncferreira committed May 16, 2025
commit 58d023409251a9ccf686116ed2a53682b43b654a
1 change: 0 additions & 1 deletion cli/testdata/coder_list_--output_json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"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
9 changes: 0 additions & 9 deletions coderd/database/dbmem/dbmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -1267,14 +1267,6 @@ 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 @@ -1286,7 +1278,6 @@ func (q *FakeQuerier) getProvisionerJobsByIDsWithQueuePositionLockedTagBasedQueu
ProvisionerJob: job,
QueuePosition: 0,
QueueSize: 0,
WorkerName: workerName,
})
}
}
Expand Down
7 changes: 1 addition & 6 deletions coderd/database/queries.sql.go

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

5 changes: 1 addition & 4 deletions coderd/database/queries/provisionerjobs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,12 @@ SELECT
fj.created_at,
sqlc.embed(pj),
fj.queue_position,
fj.queue_size,
COALESCE(pd.name, '') AS worker_name
fj.queue_size
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
3 changes: 1 addition & 2 deletions coderd/provisionerjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ 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 @@ -393,10 +392,10 @@ 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,
})
job.WorkerName = pj.WorkerName
job.AvailableWorkers = pj.AvailableWorkers
job.Metadata = codersdk.ProvisionerJobMetadata{
TemplateVersionName: pj.TemplateVersionName,
Expand Down
Loading