- Notifications
You must be signed in to change notification settings - Fork1.2k
feat: add migrations and queries to support prebuilds#16891
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
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
300e80fb7882378122595bfb7c286639167769ae1de7e9c2739360478bdcafb412d19851773ec23773c2bc3ff44baa3076ed14fb33cc74fbfc32154d7b4ec4e8b53f79df6554ccc309eee1f16ad040ddd83a6722cd7071097cc4ff4d59039205d6afe489e1b1b2968620470e47b9c8cee189a0b692c0e5f747db03166a42aa6b490bc4e7d2f167b928fd34ab7a8ec49a64d661c787cd2bd38603097f9c34cfdd6f4a34d528d9cd45f870d7e18ad9314667171a26c0946ed41212312f415150a5cbff34eaef462b6dc451659c8a352eb809190b2bbee3a97bf62eeb88473f99e8113e12b217cae0b0bf220ff72a00a007d4aea9c53b66d44ed29e121ff64754f7e0239755d9827866454b4fa959aFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4032,6 +4032,33 @@ func TestGetPresetsBackoff(t *testing.T) { | ||
| require.Equal(t, 0, now.Compare(backoff.LastBuildAt.(time.Time))) | ||
| } | ||
| }) | ||
| t.Run("failed job outside lookback period", func(t *testing.T) { | ||
| t.Parallel() | ||
| db, _ := dbtestutil.NewDB(t) | ||
| ctx := testutil.Context(t, testutil.WaitShort) | ||
| dbgen.Organization(t, db, database.Organization{ | ||
| ID: orgID, | ||
| }) | ||
| dbgen.User(t, db, database.User{ | ||
| ID: userID, | ||
| }) | ||
| lookbackPeriod := time.Hour | ||
| tmpl1 := createTemplate(db) | ||
| tmpl1V1 := createTmplVersion(db, tmpl1, tmpl1.ActiveVersionID, &tmplVersionOpts{ | ||
| DesiredInstances: 1, | ||
| }) | ||
| createWorkspaceBuild(db, tmpl1, tmpl1V1, &workspaceBuildOpts{ | ||
| successfulJob: false, | ||
| createdAt: now.Add(-lookbackPeriod - time.Minute), // earlier than lookback period - skipped | ||
| }) | ||
| backoffs, err := db.GetPresetsBackoff(ctx, now.Add(-lookbackPeriod)) | ||
| require.NoError(t, err) | ||
| require.Len(t, backoffs, 0) | ||
| }) | ||
spikecurtis marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| } | ||
| func requireUsersMatch(t testing.TB, expected []database.User, found []database.GetUsersRow, msg string) { | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -43,22 +43,20 @@ FROM workspace_latest_builds wlb | ||
| WHERE pj.job_status IN ('pending'::provisioner_job_status, 'running'::provisioner_job_status) | ||
| GROUP BY t.id, wpb.template_version_id, wpb.transition; | ||
| -- GetPresetsBackoff groups workspace builds by template version ID. | ||
| -- For each group, the query checks up to N of the most recent jobs that occurred within the | ||
| -- lookback period, where N equals the number of desired instances for the corresponding preset. | ||
| -- If at least one of the job within a group has failed, we should backoff on the corresponding template version ID. | ||
| -- Query returns a list of template version IDs for which we should backoff. | ||
| -- Only active template versions with configured presets are considered. | ||
| -- We also return the number of failed workspace builds that occurred during the lookback period. | ||
| -- | ||
| -- NOTE: | ||
| -- - To **decide whether to back off**, we look at up to the N most recent builds (within the defined lookback period). | ||
| -- - To **calculate the number of failed builds**, we consider all builds within the defined lookback period. | ||
| -- | ||
| -- The number of failed builds is used downstream to determine the backoff duration. | ||
spikecurtis marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| -- name: GetPresetsBackoff :many | ||
SasSwart marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| WITH filtered_builds AS ( | ||
| -- Only select builds which are for prebuild creations | ||
| SELECT wlb.*, tvp.id AS preset_id, pj.job_status, tvp.desired_instances | ||
| @@ -92,6 +90,7 @@ FROM time_sorted_builds tsb | ||
| LEFT JOIN failed_count fc ON fc.preset_id = tsb.preset_id | ||
| WHERE tsb.rn <= tsb.desired_instances -- Fetch the last N builds, where N is the number of desired instances; if any fail, we backoff | ||
| AND tsb.job_status = 'failed'::provisioner_job_status | ||
| AND created_at >= @lookback::timestamptz | ||
| GROUP BY tsb.template_version_id, tsb.preset_id, fc.num_failed; | ||
evgeniy-scherbina marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| -- name: ClaimPrebuild :one | ||