Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: add provisioner job metadata #16454

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 5 commits into from
Feb 6, 2025

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented Feb 5, 2025

This change adds metadata to provisioner jobs to help with rendering
related tempaltes and workspaces in the UI.

Updates #15084

This change adds metadata to provisioner jobs to help with rendering
related tempaltes and workspaces in the UI.
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments below, but nothing blocking 👍 Thanks @mafredri !

}
templateVersionID := input.TemplateVersionID
if input.WorkspaceBuildID != nil {
workspabeBuild, err := q.getWorkspaceBuildByIDNoLock(ctx, *input.WorkspaceBuildID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: workspaceBuild

Comment on lines +152 to +153
-- We should always have a template version, either explicitly or implicitly via workspace build.
template_versions tv ON tv.id = CASE WHEN pj.input ? 'template_version_id' THEN (pj.input->>'template_version_id')::uuid ELSE wb.template_version_id END
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the issue here that either input.template_version_id or wb.workspace_build_id can be null, so we're trying to account for both possibilities?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite. Both could be null in the future, all we need to do is add a new provisioner job type/input.

What we do get currently though, assuming correct input, is that there always exists a template version either directly (id) or indirectly (workspace build). This makes sure we join the template version (and thus, template) in both cases.

And in the case that neither exists in input, the template and template version info will be null.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. It might be good to add some querier tests for these eventualities just to make sure we're not surprised in the future.

Comment on lines +149 to +150
LEFT JOIN
workspaces w ON wb.workspace_id = w.id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that wb.workspace_id will be NULL here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if the job is a template version import.

Comment on lines 85 to 92
assert.Equal(t, job2.Metadata, &codersdk.ProvisionerJobMetadata{
TemplateVersionName: version.Name,
TemplateID: template.ID,
TemplateName: template.Name,
TemplateDisplayName: template.DisplayName,
WorkspaceID: &w.ID,
WorkspaceName: w.Name,
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be useful to assert the provisioner job metadata:

  • on template import
  • on template version create
  • on workspace build

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a case for template import, I don't know of any distinction for "version create" so I skipped that.

@@ -39,6 +45,14 @@
"workspace_build_id": "========[workspace build ID]========"
},
"type": "workspace_build",
"metadata": {
"template_version_name": "===========[version name]===========",
"template_id": "===========[template ID]============",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which party will consume the metadata later? I mean, is it human or machine?

If human, perhaps we can remove template_id and workspace_id?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either machine or human. For now, this is needed in the UI to show and link relevant workspace/template. I'll defer to @BrunoQuaresma as to what's needed, but I don't see any harm in keeping the IDs in? If I was an admin debugging provisioner jobs, I'd imagine it could come in handy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would agree with leaving this information available in the JSON output. This is my general experience with other CLI tooling as well (e.g. kubectl or docker) -- if you need all the info, dump the JSON or YAML and read it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why I raised this comment is my concern about the response size. IMHO we could always add these properties later, but if you find these could be useful for debugging then leave them as is. I understand that admins don't use them for troubleshooting but rather default to template/template version/workspace names, and IDs seem to be internal references.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Response size is a valid concern @mtojek, especially considering we didn't limit the response of this endpoint previously. In the regular response size (say 50 entries), these UUIDs are quite harmless and the endpoint isn't going to be very actively used. I haven't personally needed to debug provisioner jobs so I went for more rather than less, but happy to go either way here (assuming @BrunoQuaresma doesn't need the IDs).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW @BrunoQuaresma is out today, and since it is not a huge issue I don't have anything against merging it as is 👍

@mafredri mafredri merged commit b04d883 into main Feb 6, 2025
35 checks passed
@mafredri mafredri deleted the mafredri/feat-add-provisioner-job-metadata branch February 6, 2025 14:19
@github-actions github-actions bot locked and limited conversation to collaborators Feb 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants