Skip to content

feat: claim prebuilds based on workspace parameters instead of preset id #19279

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 10 commits into from
Aug 20, 2025

Conversation

SasSwart
Copy link
Contributor

@SasSwart SasSwart commented Aug 11, 2025

Closes #18356.

This change finds and selects a matching preset if one was not chosen during workspace creation. This solidifies the relationship between presets and parameters.

When a workspace is created without in explicitly chosen preset, it will now still be eligible to claim a prebuilt workspace if one is available.

@SasSwart SasSwart changed the title Jjs/18356 feat: claim prebuilds based on workspace parameters instead of preset id Aug 11, 2025
@SasSwart SasSwart force-pushed the jjs/18356 branch 3 times, most recently from e999a58 to f07cccc Compare August 15, 2025 09:18
Copy link
Contributor Author

@SasSwart SasSwart left a comment

Choose a reason for hiding this comment

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

Self Review

@@ -1810,6 +1810,14 @@ func (q *querier) FetchVolumesResourceMonitorsUpdatedAfter(ctx context.Context,
return q.db.FetchVolumesResourceMonitorsUpdatedAfter(ctx, updatedAt)
}

func (q *querier) FindMatchingPresetID(ctx context.Context, arg database.FindMatchingPresetIDParams) (uuid.UUID, error) {
_, err := q.GetTemplateVersionByID(ctx, arg.TemplateVersionID)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't like this, but I can't find a better way and there is precedent for this approach. Open to alternatives.

Copy link
Member

Choose a reason for hiding this comment

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

The alternative is to essentially duplicate the logic in GetTemplateVersionByID, which I'm less a fan of.

return err
}

if b.templateVersionPresetID == uuid.Nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not strictly necessary for when a prebuilt workspace is claimed, but it ensures that a workspace build always has a preset ID set if one matches.

@SasSwart SasSwart requested a review from mafredri August 15, 2025 12:12
@SasSwart SasSwart marked this pull request as ready for review August 15, 2025 12:14
@SasSwart SasSwart requested a review from johnstcn August 15, 2025 12:24
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.

Tests look good to me, I'm just slightly worried about the current policy returning the prebuild with the most specific set of parameters.

@@ -1810,6 +1810,14 @@ func (q *querier) FetchVolumesResourceMonitorsUpdatedAfter(ctx context.Context,
return q.db.FetchVolumesResourceMonitorsUpdatedAfter(ctx, updatedAt)
}

func (q *querier) FindMatchingPresetID(ctx context.Context, arg database.FindMatchingPresetIDParams) (uuid.UUID, error) {
_, err := q.GetTemplateVersionByID(ctx, arg.TemplateVersionID)
Copy link
Member

Choose a reason for hiding this comment

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

The alternative is to essentially duplicate the logic in GetTemplateVersionByID, which I'm less a fan of.

Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

Minor nits on the query side, otherwise LGTM.

Comment on lines 255 to 256
SELECT unnest(@parameter_names::text[]) AS name,
unnest(@parameter_values::text[]) AS value
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
SELECT unnest(@parameter_names::text[]) AS name,
unnest(@parameter_values::text[]) AS value
SELECT
unnest(@parameter_names::text[]) AS name,
unnest(@parameter_values::text[]) AS value

I suggest avoiding alignment, and if needed, line-break so indentation can be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

COALESCE(COUNT(tvpp.name), 0) AS total_preset_params,
COALESCE(COUNT(pp.name), 0) AS matching_params
FROM template_version_presets tvp
LEFT JOIN template_version_preset_parameters tvpp ON tvpp.template_version_preset_id = tvp.id
Copy link
Member

Choose a reason for hiding this comment

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

These left join suggests there is merit in including presets with no parameters as well as zero matches with provided params, why would we want this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Presets that define 0 parameters are valid. They're used in more trivial templates, usually docker based, where there really isn't much to change but one still wants prebuilds. In this case one would define a preset with no parameters that desires n prebuilt workspaces. This form of the query allows a workspace in such a template to still match a preset and therefore claim a prebuilt workspace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is useful for simpler parameters where one wants prebuilds without specifying any parameters. You could define a preset that sets no parameters. If such a preset exists, it would be selected automatically by this.

if err != nil {
return BuildError{http.StatusInternalServerError, "find matching preset", err}
}
b.templateVersionPresetID = presetID
Copy link
Member

Choose a reason for hiding this comment

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

This code path could suggest to the reader that there will always be a match, a comment mentioning it will be nil if none is found may be beneficial to avoid wrong assumptions (since we're not returning error from find).

@SasSwart SasSwart merged commit f9a6adc into main Aug 20, 2025
33 checks passed
@SasSwart SasSwart deleted the jjs/18356 branch August 20, 2025 09:02
@github-actions github-actions bot locked and limited conversation to collaborators Aug 20, 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.

Prebuilt workspaces should be claimed based on the set of chosen parameters
3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy