Skip to content

Commit 81a0399

Browse files
committed
Merge branch 'main' into 9495-support-interval-week
2 parents 01a1ad8 + b358e3d commit 81a0399

File tree

84 files changed

+3022
-2064
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+3022
-2064
lines changed

.github/dependabot.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ updates:
9292
- dependency-name: "@types/node"
9393
update-types:
9494
- version-update:semver-major
95+
open-pull-requests-limit: 15
9596
groups:
9697
react:
9798
patterns:

.github/workflows/ci.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ jobs:
5353
docs:
5454
- "docs/**"
5555
- "README.md"
56-
- "examples/templates/**"
5756
- "examples/web-server/**"
5857
- "examples/monitoring/**"
5958
- "examples/lima/**"
@@ -741,7 +740,7 @@ jobs:
741740
uses: ./.github/actions/setup-sqlc
742741

743742
- name: GHCR Login
744-
uses: docker/login-action@v2
743+
uses: docker/login-action@v3
745744
with:
746745
registry: ghcr.io
747746
username: ${{ github.actor }}

.github/workflows/contrib.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
steps:
3535
- name: cla
3636
if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target'
37-
uses: contributor-assistant/github-action@v2.3.0
37+
uses: contributor-assistant/github-action@v2.3.1
3838
env:
3939
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4040
# the below token should have repo scope and must be manually added by you in the repository's secret

.github/workflows/docker-base.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
uses: actions/checkout@v4
3636

3737
- name: Docker login
38-
uses: docker/login-action@v2
38+
uses: docker/login-action@v3
3939
with:
4040
registry: ghcr.io
4141
username: ${{ github.actor }}

.github/workflows/dogfood.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
- run: nix build .#devEnvImage && ./result | docker load
4747

4848
- name: Login to DockerHub
49-
uses: docker/login-action@v2
49+
uses: docker/login-action@v3
5050
with:
5151
username: ${{ secrets.DOCKERHUB_USERNAME }}
5252
password: ${{ secrets.DOCKERHUB_PASSWORD }}

.github/workflows/pr-deploy.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ jobs:
110110
set -euo pipefail
111111
mkdir -p ~/.kube
112112
echo "${{ secrets.PR_DEPLOYMENTS_KUBECONFIG }}" > ~/.kube/config
113+
chmod 644 ~/.kube/config
113114
export KUBECONFIG=~/.kube/config
114115
115116
- name: Check if the helm deployment already exists
@@ -216,7 +217,7 @@ jobs:
216217
uses: ./.github/actions/setup-sqlc
217218

218219
- name: GHCR Login
219-
uses: docker/login-action@v2
220+
uses: docker/login-action@v3
220221
with:
221222
registry: ghcr.io
222223
username: ${{ github.actor }}
@@ -257,6 +258,7 @@ jobs:
257258
set -euo pipefail
258259
mkdir -p ~/.kube
259260
echo "${{ secrets.PR_DEPLOYMENTS_KUBECONFIG }}" > ~/.kube/config
261+
chmod 644 ~/.kube/config
260262
export KUBECONFIG=~/.kube/config
261263
262264
- name: Check if image exists

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585
cat "$CODER_RELEASE_NOTES_FILE"
8686
8787
- name: Docker Login
88-
uses: docker/login-action@v2
88+
uses: docker/login-action@v3
8989
with:
9090
registry: ghcr.io
9191
username: ${{ github.actor }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,6 @@ scaletest/terraform/secrets.tfvars
6464

6565
# Nix
6666
result
67+
68+
# Data dumps from unit tests
69+
**/*.test.sql

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ scaletest/terraform/secrets.tfvars
6767

6868
# Nix
6969
result
70+
71+
# Data dumps from unit tests
72+
**/*.test.sql
7073
# .prettierignore.include:
7174
# Helm templates contain variables that are invalid YAML and can't be formatted
7275
# by Prettier.

cli/exp_scaletest_test.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77

88
"github.com/stretchr/testify/require"
99

10+
"cdr.dev/slog/sloggers/slogtest"
11+
1012
"github.com/coder/coder/v2/cli/clitest"
1113
"github.com/coder/coder/v2/coderd/coderdtest"
1214
"github.com/coder/coder/v2/pty/ptytest"
@@ -21,7 +23,12 @@ func TestScaleTestCreateWorkspaces(t *testing.T) {
2123
ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitLong)
2224
defer cancelFunc()
2325

24-
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
26+
log := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
27+
client := coderdtest.New(t, &coderdtest.Options{
28+
// We are not including any provisioner daemons because we do not actually
29+
// build any workspaces here.
30+
Logger: &log,
31+
})
2532
_ = coderdtest.CreateFirstUser(t, client)
2633

2734
// Write a parameters file.
@@ -59,7 +66,10 @@ func TestScaleTestWorkspaceTraffic(t *testing.T) {
5966
ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitMedium)
6067
defer cancelFunc()
6168

62-
client := coderdtest.New(t, nil)
69+
log := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
70+
client := coderdtest.New(t, &coderdtest.Options{
71+
Logger: &log,
72+
})
6373
_ = coderdtest.CreateFirstUser(t, client)
6474

6575
inv, root := clitest.New(t, "exp", "scaletest", "workspace-traffic",
@@ -82,21 +92,20 @@ func TestScaleTestWorkspaceTraffic(t *testing.T) {
8292
// This test just validates that the CLI command accepts its known arguments.
8393
func TestScaleTestDashboard(t *testing.T) {
8494
t.Parallel()
85-
if testutil.RaceEnabled() {
86-
t.Skip("Flakes under race detector, see https://github.com/coder/coder/issues/9168")
87-
}
88-
8995
ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitMedium)
9096
defer cancelFunc()
9197

92-
client := coderdtest.New(t, nil)
98+
log := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
99+
client := coderdtest.New(t, &coderdtest.Options{
100+
Logger: &log,
101+
})
93102
_ = coderdtest.CreateFirstUser(t, client)
94103

95104
inv, root := clitest.New(t, "exp", "scaletest", "dashboard",
96105
"--count", "1",
97106
"--min-wait", "100ms",
98107
"--max-wait", "1s",
99-
"--timeout", "1s",
108+
"--timeout", "5s",
100109
"--scaletest-prometheus-address", "127.0.0.1:0",
101110
"--scaletest-prometheus-wait", "0s",
102111
)

cli/server.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,8 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
10121012

10131013
autobuildTicker := time.NewTicker(vals.AutobuildPollInterval.Value())
10141014
defer autobuildTicker.Stop()
1015-
autobuildExecutor := autobuild.NewExecutor(ctx, options.Database, coderAPI.TemplateScheduleStore, logger, autobuildTicker.C)
1015+
autobuildExecutor := autobuild.NewExecutor(
1016+
ctx, options.Database, options.Pubsub, coderAPI.TemplateScheduleStore, logger, autobuildTicker.C)
10161017
autobuildExecutor.Run()
10171018

10181019
hangDetectorTicker := time.NewTicker(vals.JobHangDetectorInterval.Value())
@@ -1378,16 +1379,12 @@ func newProvisionerDaemon(
13781379
connector[string(database.ProvisionerTypeTerraform)] = sdkproto.NewDRPCProvisionerClient(terraformClient)
13791380
}
13801381

1381-
debounce := time.Second
13821382
return provisionerd.New(func(ctx context.Context) (proto.DRPCProvisionerDaemonClient, error) {
13831383
// This debounces calls to listen every second. Read the comment
13841384
// in provisionerdserver.go to learn more!
1385-
return coderAPI.CreateInMemoryProvisionerDaemon(ctx, debounce)
1385+
return coderAPI.CreateInMemoryProvisionerDaemon(ctx)
13861386
}, &provisionerd.Options{
13871387
Logger: logger.Named("provisionerd"),
1388-
JobPollInterval: cfg.Provisioner.DaemonPollInterval.Value(),
1389-
JobPollJitter: cfg.Provisioner.DaemonPollJitter.Value(),
1390-
JobPollDebounce: debounce,
13911388
UpdateInterval: time.Second,
13921389
ForceCancelInterval: cfg.Provisioner.ForceCancelInterval.Value(),
13931390
Connector: connector,

cli/testdata/coder_server_--help.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,10 @@ updating, and deleting workspace resources.
393393
Time to force cancel provisioning tasks that are stuck.
394394

395395
--provisioner-daemon-poll-interval duration, $CODER_PROVISIONER_DAEMON_POLL_INTERVAL (default: 1s)
396-
Time to wait before polling for a new job.
396+
Deprecated and ignored.
397397

398398
--provisioner-daemon-poll-jitter duration, $CODER_PROVISIONER_DAEMON_POLL_JITTER (default: 100ms)
399-
Random jitter added to the poll interval.
399+
Deprecated and ignored.
400400

401401
--provisioner-daemon-psk string, $CODER_PROVISIONER_DAEMON_PSK
402402
Pre-shared key to authenticate external provisioner daemons to Coder

cli/testdata/server-config.yaml.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,10 @@ provisioning:
348348
# tests.
349349
# (default: false, type: bool)
350350
daemonsEcho: false
351-
# Time to wait before polling for a new job.
351+
# Deprecated and ignored.
352352
# (default: 1s, type: duration)
353353
daemonPollInterval: 1s
354-
# Random jitter added to the poll interval.
354+
# Deprecated and ignored.
355355
# (default: 100ms, type: duration)
356356
daemonPollJitter: 100ms
357357
# Time to force cancel provisioning tasks that are stuck.

coderd/activitybump_internal_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
134134
TemplateID: template.ID,
135135
Ttl: sql.NullInt64{Valid: true, Int64: int64(tt.workspaceTTL)},
136136
})
137-
job = dbgen.ProvisionerJob(t, db, database.ProvisionerJob{
137+
job = dbgen.ProvisionerJob(t, db, nil, database.ProvisionerJob{
138138
OrganizationID: org.ID,
139139
CompletedAt: tt.jobCompletedAt,
140140
})
@@ -225,7 +225,7 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
225225
func insertPrevWorkspaceBuild(t *testing.T, db database.Store, orgID, tvID, workspaceID uuid.UUID, transition database.WorkspaceTransition, buildNumber int32) {
226226
t.Helper()
227227

228-
job := dbgen.ProvisionerJob(t, db, database.ProvisionerJob{
228+
job := dbgen.ProvisionerJob(t, db, nil, database.ProvisionerJob{
229229
OrganizationID: orgID,
230230
})
231231
_ = dbgen.WorkspaceResource(t, db, database.WorkspaceResource{

coderd/autobuild/lifecycle_executor.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"github.com/coder/coder/v2/coderd/database/db2sdk"
1717
"github.com/coder/coder/v2/coderd/database/dbauthz"
1818
"github.com/coder/coder/v2/coderd/database/dbtime"
19+
"github.com/coder/coder/v2/coderd/database/provisionerjobs"
20+
"github.com/coder/coder/v2/coderd/database/pubsub"
1921
"github.com/coder/coder/v2/coderd/schedule"
2022
"github.com/coder/coder/v2/coderd/schedule/cron"
2123
"github.com/coder/coder/v2/coderd/wsbuilder"
@@ -26,6 +28,7 @@ import (
2628
type Executor struct {
2729
ctx context.Context
2830
db database.Store
31+
ps pubsub.Pubsub
2932
templateScheduleStore *atomic.Pointer[schedule.TemplateScheduleStore]
3033
log slog.Logger
3134
tick <-chan time.Time
@@ -40,11 +43,12 @@ type Stats struct {
4043
}
4144

4245
// New returns a new wsactions executor.
43-
func NewExecutor(ctx context.Context, db database.Store, tss *atomic.Pointer[schedule.TemplateScheduleStore], log slog.Logger, tick <-chan time.Time) *Executor {
46+
func NewExecutor(ctx context.Context, db database.Store, ps pubsub.Pubsub, tss *atomic.Pointer[schedule.TemplateScheduleStore], log slog.Logger, tick <-chan time.Time) *Executor {
4447
le := &Executor{
4548
//nolint:gocritic // Autostart has a limited set of permissions.
4649
ctx: dbauthz.AsAutostart(ctx),
4750
db: db,
51+
ps: ps,
4852
templateScheduleStore: tss,
4953
tick: tick,
5054
log: log.Named("autobuild"),
@@ -129,6 +133,7 @@ func (e *Executor) runOnce(t time.Time) Stats {
129133
log := e.log.With(slog.F("workspace_id", wsID))
130134

131135
eg.Go(func() error {
136+
var job *database.ProvisionerJob
132137
err := e.db.InTx(func(tx database.Store) error {
133138
// Re-check eligibility since the first check was outside the
134139
// transaction and the workspace settings may have changed.
@@ -168,7 +173,8 @@ func (e *Executor) runOnce(t time.Time) Stats {
168173
SetLastWorkspaceBuildJobInTx(&latestJob).
169174
Reason(reason)
170175

171-
if _, _, err := builder.Build(e.ctx, tx, nil); err != nil {
176+
_, job, err = builder.Build(e.ctx, tx, nil)
177+
if err != nil {
172178
log.Error(e.ctx, "unable to transition workspace",
173179
slog.F("transition", nextTransition),
174180
slog.Error(err),
@@ -230,6 +236,17 @@ func (e *Executor) runOnce(t time.Time) Stats {
230236
if err != nil {
231237
log.Error(e.ctx, "workspace scheduling failed", slog.Error(err))
232238
}
239+
if job != nil && err == nil {
240+
// Note that we can't refactor such that posting the job happens inside wsbuilder because it's called
241+
// with an outer transaction like this, and we need to make sure the outer transaction commits before
242+
// posting the job. If we post before the transaction commits, provisionerd might try to acquire the
243+
// job, fail, and then sit idle instead of picking up the job.
244+
err = provisionerjobs.PostJob(e.ps, *job)
245+
if err != nil {
246+
// Client probably doesn't care about this error, so just log it.
247+
log.Error(e.ctx, "failed to post provisioner job to pubsub", slog.Error(err))
248+
}
249+
}
233250
return nil
234251
})
235252
}

coderd/batchstats/batcher_internal_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/coder/coder/v2/coderd/database/dbgen"
1515
"github.com/coder/coder/v2/coderd/database/dbtestutil"
1616
"github.com/coder/coder/v2/coderd/database/dbtime"
17+
"github.com/coder/coder/v2/coderd/database/pubsub"
1718
"github.com/coder/coder/v2/coderd/rbac"
1819
"github.com/coder/coder/v2/codersdk/agentsdk"
1920
"github.com/coder/coder/v2/cryptorand"
@@ -26,11 +27,11 @@ func TestBatchStats(t *testing.T) {
2627
ctx, cancel := context.WithCancel(context.Background())
2728
t.Cleanup(cancel)
2829
log := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug)
29-
store, _ := dbtestutil.NewDB(t)
30+
store, ps := dbtestutil.NewDB(t)
3031

3132
// Set up some test dependencies.
32-
deps1 := setupDeps(t, store)
33-
deps2 := setupDeps(t, store)
33+
deps1 := setupDeps(t, store, ps)
34+
deps2 := setupDeps(t, store, ps)
3435
tick := make(chan time.Time)
3536
flushed := make(chan int, 1)
3637

@@ -168,7 +169,7 @@ type deps struct {
168169
// It creates an organization, user, template, workspace, and agent
169170
// along with all the other miscellaneous plumbing required to link
170171
// them together.
171-
func setupDeps(t *testing.T, store database.Store) deps {
172+
func setupDeps(t *testing.T, store database.Store, ps pubsub.Pubsub) deps {
172173
t.Helper()
173174

174175
org := dbgen.Organization(t, store, database.Organization{})
@@ -194,7 +195,7 @@ func setupDeps(t *testing.T, store database.Store) deps {
194195
OrganizationID: org.ID,
195196
LastUsedAt: time.Now().Add(-time.Hour),
196197
})
197-
pj := dbgen.ProvisionerJob(t, store, database.ProvisionerJob{
198+
pj := dbgen.ProvisionerJob(t, store, ps, database.ProvisionerJob{
198199
InitiatorID: user.ID,
199200
OrganizationID: org.ID,
200201
})

0 commit comments

Comments
 (0)