Skip to content

Commit b90650d

Browse files
committed
add experiments to wsbuilder
1 parent 0c648fb commit b90650d

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

cli/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
11241124
autobuildTicker := time.NewTicker(vals.AutobuildPollInterval.Value())
11251125
defer autobuildTicker.Stop()
11261126
autobuildExecutor := autobuild.NewExecutor(
1127-
ctx, options.Database, options.Pubsub, options.PrometheusRegistry, coderAPI.TemplateScheduleStore, &coderAPI.Auditor, coderAPI.AccessControlStore, logger, autobuildTicker.C, options.NotificationsEnqueuer)
1127+
ctx, options.Database, options.Pubsub, options.PrometheusRegistry, coderAPI.TemplateScheduleStore, &coderAPI.Auditor, coderAPI.AccessControlStore, logger, autobuildTicker.C, options.NotificationsEnqueuer, coderAPI.Experiments)
11281128
autobuildExecutor.Run()
11291129

11301130
hangDetectorTicker := time.NewTicker(vals.JobHangDetectorInterval.Value())

coderd/autobuild/lifecycle_executor.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/coder/coder/v2/coderd/notifications"
2828
"github.com/coder/coder/v2/coderd/schedule"
2929
"github.com/coder/coder/v2/coderd/wsbuilder"
30+
"github.com/coder/coder/v2/codersdk"
3031
)
3132

3233
// Executor automatically starts or stops workspaces.
@@ -43,6 +44,7 @@ type Executor struct {
4344
// NotificationsEnqueuer handles enqueueing notifications for delivery by SMTP, webhook, etc.
4445
notificationsEnqueuer notifications.Enqueuer
4546
reg prometheus.Registerer
47+
experiments codersdk.Experiments
4648

4749
metrics executorMetrics
4850
}
@@ -59,7 +61,7 @@ type Stats struct {
5961
}
6062

6163
// New returns a new wsactions executor.
62-
func NewExecutor(ctx context.Context, db database.Store, ps pubsub.Pubsub, reg prometheus.Registerer, tss *atomic.Pointer[schedule.TemplateScheduleStore], auditor *atomic.Pointer[audit.Auditor], acs *atomic.Pointer[dbauthz.AccessControlStore], log slog.Logger, tick <-chan time.Time, enqueuer notifications.Enqueuer) *Executor {
64+
func NewExecutor(ctx context.Context, db database.Store, ps pubsub.Pubsub, reg prometheus.Registerer, tss *atomic.Pointer[schedule.TemplateScheduleStore], auditor *atomic.Pointer[audit.Auditor], acs *atomic.Pointer[dbauthz.AccessControlStore], log slog.Logger, tick <-chan time.Time, enqueuer notifications.Enqueuer, exp codersdk.Experiments) *Executor {
6365
factory := promauto.With(reg)
6466
le := &Executor{
6567
//nolint:gocritic // Autostart has a limited set of permissions.
@@ -73,6 +75,7 @@ func NewExecutor(ctx context.Context, db database.Store, ps pubsub.Pubsub, reg p
7375
accessControlStore: acs,
7476
notificationsEnqueuer: enqueuer,
7577
reg: reg,
78+
experiments: exp,
7679
metrics: executorMetrics{
7780
autobuildExecutionDuration: factory.NewHistogram(prometheus.HistogramOpts{
7881
Namespace: "coderd",
@@ -258,6 +261,7 @@ func (e *Executor) runOnce(t time.Time) Stats {
258261
builder := wsbuilder.New(ws, nextTransition).
259262
SetLastWorkspaceBuildInTx(&latestBuild).
260263
SetLastWorkspaceBuildJobInTx(&latestJob).
264+
Experiments(e.experiments).
261265
Reason(reason)
262266
log.Debug(e.ctx, "auto building workspace", slog.F("transition", nextTransition))
263267
if nextTransition == database.WorkspaceTransitionStart &&

coderd/coderdtest/coderdtest.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.Can
354354
auditor.Store(&options.Auditor)
355355

356356
ctx, cancelFunc := context.WithCancel(context.Background())
357+
experiments := coderd.ReadExperiments(*options.Logger, options.DeploymentValues.Experiments)
357358
lifecycleExecutor := autobuild.NewExecutor(
358359
ctx,
359360
options.Database,
@@ -365,6 +366,7 @@ func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.Can
365366
*options.Logger,
366367
options.AutobuildTicker,
367368
options.NotificationsEnqueuer,
369+
experiments,
368370
).WithStatsChannel(options.AutobuildStats)
369371
lifecycleExecutor.Run()
370372

coderd/wsbuilder/wsbuilder.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ func (b Builder) DeploymentValues(dv *codersdk.DeploymentValues) Builder {
158158
return b
159159
}
160160

161+
func (b Builder) Experiments(exp codersdk.Experiments) Builder {
162+
// nolint: revive
163+
b.experiments = exp
164+
return b
165+
}
166+
161167
func (b Builder) Initiator(u uuid.UUID) Builder {
162168
// nolint: revive
163169
b.initiator = u

0 commit comments

Comments
 (0)