Skip to content

Commit 3ef469a

Browse files
fix: limit prebuild failure cost
1 parent 6b4d3f8 commit 3ef469a

File tree

19 files changed

+611
-18
lines changed

19 files changed

+611
-18
lines changed

coderd/apidoc/docs.go

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

coderd/apidoc/swagger.json

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

coderd/database/dbauthz/dbauthz.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,6 +2234,15 @@ func (q *querier) GetPresetParametersByTemplateVersionID(ctx context.Context, ar
22342234
return q.db.GetPresetParametersByTemplateVersionID(ctx, args)
22352235
}
22362236

2237+
func (q *querier) GetPresetsAtFailureLimit(ctx context.Context, hardLimit int64) ([]database.GetPresetsAtFailureLimitRow, error) {
2238+
// GetPresetsAtFailureLimit returns a list of template version presets that have reached the hard failure limit.
2239+
// Request the same authorization permissions as GetPresetsBackoff, since the methods are similar.
2240+
if err := q.authorizeContext(ctx, policy.ActionViewInsights, rbac.ResourceTemplate.All()); err != nil {
2241+
return nil, err
2242+
}
2243+
return q.db.GetPresetsAtFailureLimit(ctx, hardLimit)
2244+
}
2245+
22372246
func (q *querier) GetPresetsBackoff(ctx context.Context, lookback time.Time) ([]database.GetPresetsBackoffRow, error) {
22382247
// GetPresetsBackoff returns a list of template version presets along with metadata such as the number of failed prebuilds.
22392248
if err := q.authorizeContext(ctx, policy.ActionViewInsights, rbac.ResourceTemplate.All()); err != nil {

coderd/database/dbauthz/dbauthz_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4857,6 +4857,11 @@ func (s *MethodTestSuite) TestPrebuilds() {
48574857
Asserts(rbac.ResourceWorkspace.All(), policy.ActionRead).
48584858
ErrorsWithInMemDB(dbmem.ErrUnimplemented)
48594859
}))
4860+
s.Run("GetPresetsAtFailureLimit", s.Subtest(func(_ database.Store, check *expects) {
4861+
check.Args(int64(0)).
4862+
Asserts(rbac.ResourceTemplate.All(), policy.ActionViewInsights).
4863+
ErrorsWithInMemDB(dbmem.ErrUnimplemented)
4864+
}))
48604865
s.Run("GetPresetsBackoff", s.Subtest(func(_ database.Store, check *expects) {
48614866
check.Args(time.Time{}).
48624867
Asserts(rbac.ResourceTemplate.All(), policy.ActionViewInsights).

coderd/database/dbmem/dbmem.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4362,6 +4362,10 @@ func (q *FakeQuerier) GetPresetParametersByTemplateVersionID(_ context.Context,
43624362
return parameters, nil
43634363
}
43644364

4365+
func (q *FakeQuerier) GetPresetsAtFailureLimit(ctx context.Context, hardLimit int64) ([]database.GetPresetsAtFailureLimitRow, error) {
4366+
return nil, ErrUnimplemented
4367+
}
4368+
43654369
func (*FakeQuerier) GetPresetsBackoff(_ context.Context, _ time.Time) ([]database.GetPresetsBackoffRow, error) {
43664370
return nil, ErrUnimplemented
43674371
}

coderd/database/dbmetrics/querymetrics.go

Lines changed: 7 additions & 0 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: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/querier.go

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

0 commit comments

Comments
 (0)