Skip to content

Commit 5551ed3

Browse files
committed
Adding test for prebuild failure backoff
Signed-off-by: Danny Kopping <dannykopping@gmail.com>
1 parent d9cd468 commit 5551ed3

File tree

11 files changed

+137
-56
lines changed

11 files changed

+137
-56
lines changed

coderd/database/dbauthz/dbauthz.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,11 +2056,11 @@ func (q *querier) GetPresetParametersByTemplateVersionID(ctx context.Context, te
20562056
return q.db.GetPresetParametersByTemplateVersionID(ctx, templateVersionID)
20572057
}
20582058

2059-
func (q *querier) GetPresetsBackoff(ctx context.Context, period int64) ([]database.GetPresetsBackoffRow, error) {
2059+
func (q *querier) GetPresetsBackoff(ctx context.Context, lookback time.Time) ([]database.GetPresetsBackoffRow, error) {
20602060
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceTemplate); err != nil {
20612061
return nil, err
20622062
}
2063-
return q.db.GetPresetsBackoff(ctx, period)
2063+
return q.db.GetPresetsBackoff(ctx, lookback)
20642064
}
20652065

20662066
func (q *querier) GetPresetsByTemplateVersionID(ctx context.Context, templateVersionID uuid.UUID) ([]database.TemplateVersionPreset, error) {

coderd/database/dbmem/dbmem.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4066,7 +4066,7 @@ func (q *FakeQuerier) GetPresetParametersByTemplateVersionID(_ context.Context,
40664066
return parameters, nil
40674067
}
40684068

4069-
func (q *FakeQuerier) GetPresetsBackoff(ctx context.Context, period int64) ([]database.GetPresetsBackoffRow, error) {
4069+
func (q *FakeQuerier) GetPresetsBackoff(ctx context.Context, period time.Time) ([]database.GetPresetsBackoffRow, error) {
40704070
panic("not implemented")
40714071
}
40724072

coderd/database/dbmetrics/querymetrics.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbmock/dbmock.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/querier.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/prebuilds.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ WITH filtered_builds AS (
6565
SELECT preset_id, COUNT(*) AS num_failed
6666
FROM filtered_builds
6767
WHERE job_status = 'failed'::provisioner_job_status
68-
AND created_at >= NOW() - (sqlc.arg('lookback')::bigint * INTERVAL '1 microsecond') -- microsecond is the smallest unit in PG, bigint is used because Go deals with time as int64
68+
AND created_at >= @lookback::timestamptz
6969
GROUP BY preset_id)
7070
SELECT lb.template_version_id,
7171
lb.preset_id,

coderd/prebuilds/util.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/base32"
66
"fmt"
77
"strings"
8-
"time"
98
)
109

1110
// GenerateName generates a 20-byte prebuild name which should safe to use without truncation in most situations.
@@ -25,9 +24,3 @@ func GenerateName() (string, error) {
2524
// Encode the bytes to Base32 (A-Z2-7), strip any '=' padding
2625
return fmt.Sprintf("prebuild-%s", strings.ToLower(base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(b))), nil
2726
}
28-
29-
// DurationToInterval converts a given duration to microseconds, which is the unit PG represents intervals in.
30-
func DurationToInterval(d time.Duration) int64 {
31-
// Convert duration to seconds (as an example)
32-
return d.Microseconds()
33-
}

coderd/workspaces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ func createWorkspace(
679679
initiatorID = prebuilds.Initiator()
680680
agents, err := api.Database.GetWorkspaceAgentsInLatestBuildByWorkspaceID(ctx, claimedWorkspace.ID)
681681
if err != nil {
682+
// TODO: comment about best-effort, workspace can be restarted if this fails...
682683
api.Logger.Error(ctx, "failed to retrieve running agents of claimed prebuilt workspace",
683684
slog.F("workspace_id", claimedWorkspace.ID), slog.Error(err))
684685
}

enterprise/coderd/prebuilds/reconcile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func (c *StoreReconciler) SnapshotState(ctx context.Context, store database.Stor
255255
return xerrors.Errorf("failed to get prebuilds in progress: %w", err)
256256
}
257257

258-
presetsBackoff, err := db.GetPresetsBackoff(ctx, prebuilds.DurationToInterval(c.cfg.ReconciliationBackoffLookback.Value()))
258+
presetsBackoff, err := db.GetPresetsBackoff(ctx, c.clock.Now().Add(-c.cfg.ReconciliationBackoffLookback.Value()))
259259
if err != nil {
260260
return xerrors.Errorf("failed to get backoffs for presets: %w", err)
261261
}

0 commit comments

Comments
 (0)