-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: add prebuild invalidation via last_invalidated_at timestamp #20582
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
Conversation
Implements new approach for prebuild invalidation as discussed in issue #17917. Instead of directly deleting workspaces, this sets a timestamp on presets, and the reconciler automatically marks prebuilds as expired and creates new ones. Implementation: - Add last_invalidated_at column to template_version_presets table - API endpoint: POST /templates/{template}/prebuilds/invalidate - Updates last_invalidated_at = NOW() for all active template version presets - filterExpiredWorkspaces checks if prebuild.created_at < preset.last_invalidated_at - Reconciler automatically deletes expired prebuilds and spawns fresh ones Changes: - Migration 000394: Add last_invalidated_at column - Query: UpdatePresetsLastInvalidatedAt sets timestamp on active presets - API: Returns count and list of invalidated preset names - Logic: filterExpiredWorkspaces prioritizes last_invalidated_at over TTL - SDK: InvalidateTemplatePrebuilds client method with structured response Benefits: - Non-blocking: API doesn't wait for reconciler - Async: Reconciler handles actual deletion - Safe: template_version_presets is no longer write-once Updates #17917
04ba875 to
6019903
Compare
- Use uuid.NullUUID{UUID: template.ID, Valid: true}
- Use sql.NullTime{Time: dbtime.Now(), Valid: true}
96249b9 to
90b75e1
Compare
This reverts commit f8a06c6.
Remove redundant subquery - template_version_id IN (...) AND template_version_id = (...) is unnecessary. Just check template_version_id = active_version_id directly.
|
FYI Chromatic is failing now, but this seems to be unrelated. I didn't touch the frontend side. |
ssncferreira
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM, just some small improvements.
It might be worth documenting that this isn't a real-time operation, the endpoint marks presets as invalidated, but actual prebuild deletion happens asynchronously during the next reconciliation loop. It might also be a good idea to add this info in the UI changes.
Co-authored-by: Susana Ferreira <susana@coder.com>
Co-authored-by: Susana Ferreira <susana@coder.com>
Co-authored-by: Susana Ferreira <susana@coder.com>
Co-authored-by: Susana Ferreira <susana@coder.com>
mtojek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth documenting that this isn't a real-time operation, the endpoint marks presets as invalidated, but actual prebuild deletion happens asynchronously during the next reconciliation loop. It might also be a good idea to add this info in the UI changes.
I want to add this message to docs and possibly in the UI in the follow-up. This PR contains mainly backend changes 👍
ssncferreira
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ![]()
Thanks for addressing the comments 🥇
| @@ -0,0 +1 @@ | |||
| ALTER TABLE template_version_presets ADD COLUMN last_invalidated_at TIMESTAMPTZ; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a reminder to check migration number before merge! 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked 👍 Last in mainline 398.
Thanks for the diligence!
Updates #17917
Implements prebuild invalidation by setting
last_invalidated_attimestamp on presets.The reconciler automatically marks prebuilds as expired if
prebuild.created_at < preset.last_invalidated_atand spawns fresh ones.API:
POST /templates/{template}/prebuilds/invalidateResponse:
{"invalidated_presets": ["preset-1", "preset-2", "preset-3"]}In the follow-up PR, I will expose a dedicated button somewhere in the UI.