- Notifications
You must be signed in to change notification settings - Fork1.1k
feat: implement expiration policy logic for prebuilds#17996
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
ssncferreira merged 15 commits intomainfromssncferreira/feat-prebuilds-cache-invalidationMay 26, 2025
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from1 commit
Commits
Show all changes
15 commits Select commitHold shift + click to select a range
a38ee7c feat: implement cache invalidation logic for prebuilds
ssncferreiraa904d3f chore: add preset_id to log messages in reconciliation cycle
ssncferreirab0abd30 Merge remote-tracking branch 'origin/main' into ssncferreira/feat-pre…
ssncferreiraf43ea2c docs: add documentation regarding cache_invalidation to Prebuilt work…
ssncferreirac7e442c fix: update code according to latest terraform schema expiration_poli…
ssncferreira28a6274 fix: proto comment
ssncferreira7482bfb fix: preset_snapshot_test to create Preset with TTL via options
ssncferreira04c0e7c chore: update Actual state count to include both expired and non-expi…
ssncferreira8e5caae chore: update terraform-provider-coder to version v2.5.0
ssncferreira4b1fbb5 fix: run terraform generate.sh to update preset files
ssncferreira30771cf fix: update resources_test to include ApiKeyScope parameter
ssncferreira266c445 Merge remote-tracking branch 'origin/main' into ssncferreira/feat-pre…
ssncferreira14be03f chore: update Provisioner API version 1.6 with prebuilds' expiration …
ssncferreira7a24eea chore: update preset snapshot tests test data for consistency
ssncferreira7666090 Merge remote-tracking branch 'origin/main' into ssncferreira/feat-pre…
ssncferreiraFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
fix: preset_snapshot_test to create Preset with TTL via options
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit7482bfb8902452ab4cc16c91af8990ecb940844f
There are no files selected for viewing
73 changes: 29 additions & 44 deletionscoderd/prebuilds/preset_snapshot_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -23,6 +23,7 @@ type options struct { | ||
| presetName string | ||
| prebuiltWorkspaceID uuid.UUID | ||
| workspaceName string | ||
| ttl int32 | ||
| } | ||
| // templateID is common across all option sets. | ||
| @@ -34,6 +35,7 @@ const ( | ||
| optionSet0 = iota | ||
| optionSet1 | ||
| optionSet2 | ||
| optionSet3 | ||
| ) | ||
| var opts = map[uint]options{ | ||
| @@ -61,6 +63,15 @@ var opts = map[uint]options{ | ||
| prebuiltWorkspaceID: uuid.UUID{33}, | ||
| workspaceName: "prebuilds2", | ||
| }, | ||
| optionSet3: { | ||
ssncferreira marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| templateID: templateID, | ||
| templateVersionID: uuid.UUID{31}, | ||
| presetID: uuid.UUID{32}, | ||
| presetName: "my-preset", | ||
| prebuiltWorkspaceID: uuid.UUID{33}, | ||
| workspaceName: "prebuilds2", | ||
| ttl: 5, // seconds | ||
| }, | ||
| } | ||
| // A new template version with a preset without prebuilds configured should result in no prebuilds being created. | ||
| @@ -249,11 +260,7 @@ func TestInProgressActions(t *testing.T) { | ||
| inProgress: 1, | ||
| checkFn: func(state prebuilds.ReconciliationState, actions []*prebuilds.ReconciliationActions) { | ||
| validateState(t, prebuilds.ReconciliationState{Desired: 1, Starting: 1}, state) | ||
| validateActions(t, nil, actions) | ||
| }, | ||
| }, | ||
| // With one running prebuild and one starting, no creations/deletions should occur since we're approaching the correct state. | ||
| @@ -265,11 +272,7 @@ func TestInProgressActions(t *testing.T) { | ||
| inProgress: 1, | ||
| checkFn: func(state prebuilds.ReconciliationState, actions []*prebuilds.ReconciliationActions) { | ||
| validateState(t, prebuilds.ReconciliationState{Actual: 1, Desired: 2, Starting: 1}, state) | ||
| validateActions(t, nil, actions) | ||
| }, | ||
| }, | ||
| // With one running prebuild and one starting, no creations/deletions should occur | ||
| @@ -282,11 +285,7 @@ func TestInProgressActions(t *testing.T) { | ||
| inProgress: 1, | ||
| checkFn: func(state prebuilds.ReconciliationState, actions []*prebuilds.ReconciliationActions) { | ||
| validateState(t, prebuilds.ReconciliationState{Actual: 2, Desired: 2, Starting: 1}, state) | ||
| validateActions(t, nil, actions) | ||
| }, | ||
| }, | ||
| // With one prebuild desired and one stopping, a new prebuild will be created. | ||
| @@ -332,11 +331,7 @@ func TestInProgressActions(t *testing.T) { | ||
| inProgress: 1, | ||
| checkFn: func(state prebuilds.ReconciliationState, actions []*prebuilds.ReconciliationActions) { | ||
| validateState(t, prebuilds.ReconciliationState{Actual: 3, Desired: 3, Stopping: 1}, state) | ||
| validateActions(t, nil, actions) | ||
| }, | ||
| }, | ||
| // With one prebuild desired and one deleting, a new prebuild will be created. | ||
| @@ -382,11 +377,7 @@ func TestInProgressActions(t *testing.T) { | ||
| inProgress: 1, | ||
| checkFn: func(state prebuilds.ReconciliationState, actions []*prebuilds.ReconciliationActions) { | ||
| validateState(t, prebuilds.ReconciliationState{Actual: 2, Desired: 2, Deleting: 1}, state) | ||
| validateActions(t, nil, actions) | ||
| }, | ||
| }, | ||
| // With 3 prebuilds desired, 1 running, and 2 starting, no creations should occur since the builds are in progress. | ||
| @@ -534,7 +525,7 @@ func TestExtraneous(t *testing.T) { | ||
| // specified in the preset's cache invalidation invalidate_after_secs parameter. | ||
| func TestExpiredPrebuilds(t *testing.T) { | ||
| t.Parallel() | ||
| current := opts[optionSet3] | ||
| clock := quartz.NewMock(t) | ||
| cases := []struct { | ||
| @@ -676,8 +667,8 @@ func TestExpiredPrebuilds(t *testing.T) { | ||
| require.NoError(t, err) | ||
| prebuildCreateAt := time.Now() | ||
| if int(tc.expired) > expiredCount { | ||
| // Update the prebuild workspace createdAt to exceed its TTL (5 seconds) | ||
| prebuildCreateAt = prebuildCreateAt.Add(-ttlDuration -10*time.Second) | ||
| expiredCount++ | ||
| } | ||
| running = append(running, database.GetRunningPrebuiltWorkspacesRow{ | ||
| @@ -810,12 +801,7 @@ func TestLatestBuildFailed(t *testing.T) { | ||
| validateState(t, prebuilds.ReconciliationState{ | ||
| Actual: 1, Desired: 1, Eligible: 1, | ||
| }, *state) | ||
| validateActions(t, nil, actions) | ||
| // WHEN: the clock is advanced a backoff interval. | ||
| clock.Advance(backoffInterval + time.Microsecond) | ||
| @@ -894,12 +880,7 @@ func TestMultiplePresetsPerTemplateVersion(t *testing.T) { | ||
| Starting: 1, | ||
| Desired: 1, | ||
| }, *state) | ||
| validateActions(t, nil, actions) | ||
| } | ||
| // One prebuild has to be created for preset 2. Make sure preset 1 doesn't block preset 2. | ||
| @@ -925,6 +906,13 @@ func TestMultiplePresetsPerTemplateVersion(t *testing.T) { | ||
| } | ||
| func preset(active bool, instances int32, opts options, muts ...func(row database.GetTemplatePresetsWithPrebuildsRow) database.GetTemplatePresetsWithPrebuildsRow) database.GetTemplatePresetsWithPrebuildsRow { | ||
| ttl := sql.NullInt32{} | ||
| if opts.ttl > 0 { | ||
| ttl = sql.NullInt32{ | ||
| Valid: true, | ||
| Int32: opts.ttl, | ||
| } | ||
| } | ||
| entry := database.GetTemplatePresetsWithPrebuildsRow{ | ||
| TemplateID: opts.templateID, | ||
| TemplateVersionID: opts.templateVersionID, | ||
| @@ -937,10 +925,7 @@ func preset(active bool, instances int32, opts options, muts ...func(row databas | ||
| }, | ||
| Deleted: false, | ||
| Deprecated: false, | ||
| Ttl: ttl, | ||
| } | ||
| for _, mut := range muts { | ||
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.