Skip to content

Commit d8db119

Browse files
committed
WIP
1 parent 96fee51 commit d8db119

File tree

12 files changed

+194
-282
lines changed

12 files changed

+194
-282
lines changed

cli/testdata/server-config.yaml.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ networking:
183183
# Interval to poll for scheduled workspace builds.
184184
# (default: 1m0s, type: duration)
185185
autobuildPollInterval: 1m0s
186-
# Interval to poll for hung jobs and automatically terminate them.
186+
# Interval to poll for hung and pending jobs and automatically terminate them.
187187
# (default: 1m0s, type: duration)
188188
jobHangDetectorInterval: 1m0s
189189
introspection:

coderd/database/dbauthz/dbauthz.go

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ var (
170170
Identifier: rbac.RoleIdentifier{Name: "provisionerd"},
171171
DisplayName: "Provisioner Daemon",
172172
Site: rbac.Permissions(map[string][]policy.Action{
173-
rbac.ResourceProvisionerJobs.Type: {policy.ActionRead, policy.ActionUpdate},
173+
rbac.ResourceProvisionerJobs.Type: {policy.ActionRead, policy.ActionUpdate, policy.ActionCreate},
174174
rbac.ResourceFile.Type: {policy.ActionRead},
175175
rbac.ResourceSystem.Type: {policy.WildcardSymbol},
176176
rbac.ResourceTemplate.Type: {policy.ActionRead, policy.ActionUpdate},
@@ -1075,13 +1075,6 @@ func (q *querier) customRoleCheck(ctx context.Context, role database.CustomRole)
10751075
return nil
10761076
}
10771077

1078-
func (q *querier) GetPendingProvisionerJobs(ctx context.Context, lastUpdatedSince time.Time) ([]database.ProvisionerJob, error) {
1079-
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceProvisionerJobs); err != nil {
1080-
return nil, err
1081-
}
1082-
return q.db.GetPendingProvisionerJobs(ctx, lastUpdatedSince)
1083-
}
1084-
10851078
func (q *querier) AcquireLock(ctx context.Context, id int64) error {
10861079
return q.db.AcquireLock(ctx, id)
10871080
}
@@ -1919,13 +1912,6 @@ func (q *querier) GetHealthSettings(ctx context.Context) (string, error) {
19191912
return q.db.GetHealthSettings(ctx)
19201913
}
19211914

1922-
func (q *querier) GetHungProvisionerJobs(ctx context.Context, hungSince time.Time) ([]database.ProvisionerJob, error) {
1923-
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceProvisionerJobs); err != nil {
1924-
return nil, err
1925-
}
1926-
return q.db.GetHungProvisionerJobs(ctx, hungSince)
1927-
}
1928-
19291915
func (q *querier) GetInboxNotificationByID(ctx context.Context, id uuid.UUID) (database.InboxNotification, error) {
19301916
return fetchWithAction(q.log, q.auth, policy.ActionRead, q.db.GetInboxNotificationByID)(ctx, id)
19311917
}
@@ -2336,6 +2322,9 @@ func (q *querier) GetProvisionerJobsByIDsWithQueuePosition(ctx context.Context,
23362322
}
23372323

23382324
func (q *querier) GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisioner(ctx context.Context, arg database.GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisionerParams) ([]database.GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisionerRow, error) {
2325+
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceProvisionerJobs); err != nil {
2326+
return nil, err
2327+
}
23392328
return fetchWithPostFilter(q.auth, policy.ActionRead, q.db.GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisioner)(ctx, arg)
23402329
}
23412330

@@ -2346,6 +2335,13 @@ func (q *querier) GetProvisionerJobsCreatedAfter(ctx context.Context, createdAt
23462335
return q.db.GetProvisionerJobsCreatedAfter(ctx, createdAt)
23472336
}
23482337

2338+
func (q *querier) GetProvisionerJobsToBeReaped(ctx context.Context, arg database.GetProvisionerJobsToBeReapedParams) ([]database.ProvisionerJob, error) {
2339+
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceProvisionerJobs); err != nil {
2340+
return nil, err
2341+
}
2342+
return q.db.GetProvisionerJobsToBeReaped(ctx, arg)
2343+
}
2344+
23492345
func (q *querier) GetProvisionerKeyByHashedSecret(ctx context.Context, hashedSecret []byte) (database.ProvisionerKey, error) {
23502346
return fetch(q.log, q.auth, q.db.GetProvisionerKeyByHashedSecret)(ctx, hashedSecret)
23512347
}
@@ -3538,14 +3534,14 @@ func (q *querier) InsertProvisionerJob(ctx context.Context, arg database.InsertP
35383534
}
35393535

35403536
func (q *querier) InsertProvisionerJobLogs(ctx context.Context, arg database.InsertProvisionerJobLogsParams) ([]database.ProvisionerJobLog, error) {
3541-
if err := q.authorizeContext(ctx, policy.ActionCreate, rbac.ResourceProvisionerJobs); err != nil {
3537+
if err := q.authorizeContext(ctx, policy.ActionUpdate, rbac.ResourceProvisionerJobs); err != nil {
35423538
return nil, err
35433539
}
35443540
return q.db.InsertProvisionerJobLogs(ctx, arg)
35453541
}
35463542

35473543
func (q *querier) InsertProvisionerJobTimings(ctx context.Context, arg database.InsertProvisionerJobTimingsParams) ([]database.ProvisionerJobTiming, error) {
3548-
if err := q.authorizeContext(ctx, policy.ActionCreate, rbac.ResourceProvisionerJobs); err != nil {
3544+
if err := q.authorizeContext(ctx, policy.ActionUpdate, rbac.ResourceProvisionerJobs); err != nil {
35493545
return nil, err
35503546
}
35513547
return q.db.InsertProvisionerJobTimings(ctx, arg)

coderd/database/dbmem/dbmem.go

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,10 +1386,6 @@ func isDeprecated(template database.Template) bool {
13861386
return template.Deprecated != ""
13871387
}
13881388

1389-
func (q *FakeQuerier) GetProvisionerJobsToBeReaped(ctx context.Context, updatedAt time.Time) ([]database.ProvisionerJob, error) {
1390-
panic("not implemented")
1391-
}
1392-
13931389
func (*FakeQuerier) AcquireLock(_ context.Context, _ int64) error {
13941390
return xerrors.New("AcquireLock must only be called within a transaction")
13951391
}
@@ -3711,23 +3707,6 @@ func (q *FakeQuerier) GetHealthSettings(_ context.Context) (string, error) {
37113707
return string(q.healthSettings), nil
37123708
}
37133709

3714-
func (q *FakeQuerier) GetHungProvisionerJobs(_ context.Context, hungSince time.Time) ([]database.ProvisionerJob, error) {
3715-
q.mutex.RLock()
3716-
defer q.mutex.RUnlock()
3717-
3718-
hungJobs := []database.ProvisionerJob{}
3719-
for _, provisionerJob := range q.provisionerJobs {
3720-
if provisionerJob.StartedAt.Valid && !provisionerJob.CompletedAt.Valid && provisionerJob.UpdatedAt.Before(hungSince) {
3721-
// clone the Tags before appending, since maps are reference types and
3722-
// we don't want the caller to be able to mutate the map we have inside
3723-
// dbmem!
3724-
provisionerJob.Tags = maps.Clone(provisionerJob.Tags)
3725-
hungJobs = append(hungJobs, provisionerJob)
3726-
}
3727-
}
3728-
return hungJobs, nil
3729-
}
3730-
37313710
func (q *FakeQuerier) GetInboxNotificationByID(_ context.Context, id uuid.UUID) (database.InboxNotification, error) {
37323711
q.mutex.RLock()
37333712
defer q.mutex.RUnlock()
@@ -4278,23 +4257,6 @@ func (q *FakeQuerier) GetParameterSchemasByJobID(_ context.Context, jobID uuid.U
42784257
return parameters, nil
42794258
}
42804259

4281-
func (q *FakeQuerier) GetPendingProvisionerJobs(_ context.Context, lastUpdatedSince time.Time) ([]database.ProvisionerJob, error) {
4282-
q.mutex.RLock()
4283-
defer q.mutex.RUnlock()
4284-
4285-
pendingJobs := []database.ProvisionerJob{}
4286-
for _, provisionerJob := range q.provisionerJobs {
4287-
if !provisionerJob.StartedAt.Valid && !provisionerJob.CompletedAt.Valid && provisionerJob.UpdatedAt.Before(lastUpdatedSince) {
4288-
// clone the Tags before appending, since maps are reference types and
4289-
// we don't want the caller to be able to mutate the map we have inside
4290-
// dbmem!
4291-
provisionerJob.Tags = maps.Clone(provisionerJob.Tags)
4292-
pendingJobs = append(pendingJobs, provisionerJob)
4293-
}
4294-
}
4295-
return pendingJobs, nil
4296-
}
4297-
42984260
func (*FakeQuerier) GetPrebuildMetrics(_ context.Context) ([]database.GetPrebuildMetricsRow, error) {
42994261
return nil, ErrUnimplemented
43004262
}
@@ -4898,6 +4860,30 @@ func (q *FakeQuerier) GetProvisionerJobsCreatedAfter(_ context.Context, after ti
48984860
return jobs, nil
48994861
}
49004862

4863+
func (q *FakeQuerier) GetProvisionerJobsToBeReaped(_ context.Context, arg database.GetProvisionerJobsToBeReapedParams) ([]database.ProvisionerJob, error) {
4864+
q.mutex.RLock()
4865+
defer q.mutex.RUnlock()
4866+
maxJobs := arg.MaxJobs
4867+
4868+
hungJobs := []database.ProvisionerJob{}
4869+
for _, provisionerJob := range q.provisionerJobs {
4870+
if !provisionerJob.CompletedAt.Valid {
4871+
if (provisionerJob.StartedAt.Valid && provisionerJob.UpdatedAt.Before(arg.HungSince)) ||
4872+
(!provisionerJob.StartedAt.Valid && provisionerJob.UpdatedAt.Before(arg.PendingSince)) {
4873+
// clone the Tags before appending, since maps are reference types and
4874+
// we don't want the caller to be able to mutate the map we have inside
4875+
// dbmem!
4876+
provisionerJob.Tags = maps.Clone(provisionerJob.Tags)
4877+
hungJobs = append(hungJobs, provisionerJob)
4878+
if len(hungJobs) >= int(maxJobs) {
4879+
return hungJobs, nil
4880+
}
4881+
}
4882+
}
4883+
}
4884+
return hungJobs, nil
4885+
}
4886+
49014887
func (q *FakeQuerier) GetProvisionerKeyByHashedSecret(_ context.Context, hashedSecret []byte) (database.ProvisionerKey, error) {
49024888
q.mutex.RLock()
49034889
defer q.mutex.RUnlock()

coderd/database/dbmetrics/querymetrics.go

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy