Skip to content

Commit 92c6b65

Browse files
committed
Merge branch 'main' into dean/integration-test-ns
2 parents 85bb13d + 7779c0a commit 92c6b65

Some content is hidden

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

43 files changed

+771
-529
lines changed

.github/actions/setup-go/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ runs:
99
using: "composite"
1010
steps:
1111
- name: Setup Go
12-
uses: buildjet/setup-go@v4
12+
uses: buildjet/setup-go@v5
1313
with:
1414
go-version: ${{ inputs.version }}
1515

.github/actions/setup-node/action.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ runs:
1111
using: "composite"
1212
steps:
1313
- name: Install pnpm
14-
uses: pnpm/action-setup@v2
14+
uses: pnpm/action-setup@v3
1515
with:
1616
version: 8
1717
- name: Setup Node
18-
uses: buildjet/setup-node@v3
18+
uses: buildjet/setup-node@v4.0.1
1919
with:
2020
node-version: 18.19.0
2121
# See https://github.com/actions/setup-node#caching-global-packages-data

.github/codecov.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

.github/workflows/ci.yaml

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,6 @@ jobs:
269269
id: test
270270
shell: bash
271271
run: |
272-
# Code coverage is more computationally expensive and also
273-
# prevents test caching, so we disable it on alternate operating
274-
# systems.
275-
if [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
276-
echo "cover=true" >> $GITHUB_OUTPUT
277-
export COVERAGE_FLAGS='-covermode=atomic -coverprofile="gotests.coverage" -coverpkg=./...'
278-
else
279-
echo "cover=false" >> $GITHUB_OUTPUT
280-
fi
281-
282272
# if macOS, install google-chrome for scaletests. As another concern,
283273
# should we really have this kind of external dependency requirement
284274
# on standard CI?
@@ -297,7 +287,7 @@ jobs:
297287
fi
298288
export TS_DEBUG_DISCO=true
299289
gotestsum --junitfile="gotests.xml" --jsonfile="gotests.json" \
300-
--packages="./..." -- $PARALLEL_FLAG -short -failfast $COVERAGE_FLAGS
290+
--packages="./..." -- $PARALLEL_FLAG -short -failfast
301291
302292
- name: Upload test stats to Datadog
303293
timeout-minutes: 1
@@ -307,19 +297,6 @@ jobs:
307297
with:
308298
api-key: ${{ secrets.DATADOG_API_KEY }}
309299

310-
- name: Check code coverage
311-
uses: codecov/codecov-action@v4
312-
# This action has a tendency to error out unexpectedly, it has
313-
# the `fail_ci_if_error` option that defaults to `false`, but
314-
# that is no guarantee, see:
315-
# https://github.com/codecov/codecov-action/issues/788
316-
continue-on-error: true
317-
if: steps.test.outputs.cover && github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
318-
with:
319-
token: ${{ secrets.CODECOV_TOKEN }}
320-
files: ./gotests.coverage
321-
flags: unittest-go-${{ matrix.os }}
322-
323300
test-go-pg:
324301
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
325302
needs:
@@ -355,19 +332,6 @@ jobs:
355332
with:
356333
api-key: ${{ secrets.DATADOG_API_KEY }}
357334

358-
- name: Check code coverage
359-
uses: codecov/codecov-action@v4
360-
# This action has a tendency to error out unexpectedly, it has
361-
# the `fail_ci_if_error` option that defaults to `false`, but
362-
# that is no guarantee, see:
363-
# https://github.com/codecov/codecov-action/issues/788
364-
continue-on-error: true
365-
if: github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
366-
with:
367-
token: ${{ secrets.CODECOV_TOKEN }}
368-
files: ./gotests.coverage
369-
flags: unittest-go-postgres-linux
370-
371335
test-go-race:
372336
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
373337
needs: changes
@@ -414,19 +378,6 @@ jobs:
414378
- run: pnpm test:ci --max-workers $(nproc)
415379
working-directory: site
416380

417-
- name: Check code coverage
418-
uses: codecov/codecov-action@v4
419-
# This action has a tendency to error out unexpectedly, it has
420-
# the `fail_ci_if_error` option that defaults to `false`, but
421-
# that is no guarantee, see:
422-
# https://github.com/codecov/codecov-action/issues/788
423-
continue-on-error: true
424-
if: github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
425-
with:
426-
token: ${{ secrets.CODECOV_TOKEN }}
427-
files: ./site/coverage/lcov.info
428-
flags: unittest-js
429-
430381
test-e2e:
431382
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-16vcpu-ubuntu-2204' || 'ubuntu-latest' }}
432383
needs: changes

cli/speedtest.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,22 @@ func (r *RootCmd) speedtest() *serpent.Command {
6060
if r.disableDirect {
6161
_, _ = fmt.Fprintln(inv.Stderr, "Direct connections disabled.")
6262
}
63+
opts := &workspacesdk.DialAgentOptions{
64+
Logger: logger,
65+
}
66+
if pcapFile != "" {
67+
s := capture.New()
68+
opts.CaptureHook = s.LogPacket
69+
f, err := os.OpenFile(pcapFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
70+
if err != nil {
71+
return err
72+
}
73+
defer f.Close()
74+
unregister := s.RegisterOutput(f)
75+
defer unregister()
76+
}
6377
conn, err := workspacesdk.New(client).
64-
DialAgent(ctx, workspaceAgent.ID, &workspacesdk.DialAgentOptions{
65-
Logger: logger,
66-
})
78+
DialAgent(ctx, workspaceAgent.ID, opts)
6779
if err != nil {
6880
return err
6981
}
@@ -102,18 +114,6 @@ func (r *RootCmd) speedtest() *serpent.Command {
102114
conn.AwaitReachable(ctx)
103115
}
104116

105-
if pcapFile != "" {
106-
s := capture.New()
107-
conn.InstallCaptureHook(s.LogPacket)
108-
f, err := os.OpenFile(pcapFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
109-
if err != nil {
110-
return err
111-
}
112-
defer f.Close()
113-
unregister := s.RegisterOutput(f)
114-
defer unregister()
115-
}
116-
117117
var tsDir tsspeedtest.Direction
118118
switch direction {
119119
case "up":

coderd/agentapi/stats.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313

1414
"cdr.dev/slog"
1515
agentproto "github.com/coder/coder/v2/agent/proto"
16-
"github.com/coder/coder/v2/coderd/autobuild"
1716
"github.com/coder/coder/v2/coderd/database"
1817
"github.com/coder/coder/v2/coderd/database/dbtime"
1918
"github.com/coder/coder/v2/coderd/database/pubsub"
@@ -84,7 +83,7 @@ func (a *StatsAPI) UpdateStats(ctx context.Context, req *agentproto.UpdateStatsR
8483
slog.Error(err),
8584
)
8685
} else {
87-
next, allowed := autobuild.NextAutostartSchedule(now, workspace.AutostartSchedule.String, templateSchedule)
86+
next, allowed := schedule.NextAutostart(now, workspace.AutostartSchedule.String, templateSchedule)
8887
if allowed {
8988
nextAutostart = next
9089
}

coderd/apidoc/docs.go

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

coderd/autobuild/lifecycle_executor.go

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/coder/coder/v2/coderd/database/provisionerjobs"
2121
"github.com/coder/coder/v2/coderd/database/pubsub"
2222
"github.com/coder/coder/v2/coderd/schedule"
23-
"github.com/coder/coder/v2/coderd/schedule/cron"
2423
"github.com/coder/coder/v2/coderd/wsbuilder"
2524
)
2625

@@ -368,7 +367,7 @@ func isEligibleForAutostart(user database.User, ws database.Workspace, build dat
368367
return false
369368
}
370369

371-
nextTransition, allowed := NextAutostartSchedule(build.CreatedAt, ws.AutostartSchedule.String, templateSchedule)
370+
nextTransition, allowed := schedule.NextAutostart(build.CreatedAt, ws.AutostartSchedule.String, templateSchedule)
372371
if !allowed {
373372
return false
374373
}
@@ -377,29 +376,6 @@ func isEligibleForAutostart(user database.User, ws database.Workspace, build dat
377376
return !currentTick.Before(nextTransition)
378377
}
379378

380-
// NextAutostartSchedule takes the workspace and template schedule and returns the next autostart schedule
381-
// after "at". The boolean returned is if the autostart should be allowed to start based on the template
382-
// schedule.
383-
func NextAutostartSchedule(at time.Time, wsSchedule string, templateSchedule schedule.TemplateScheduleOptions) (time.Time, bool) {
384-
sched, err := cron.Weekly(wsSchedule)
385-
if err != nil {
386-
return time.Time{}, false
387-
}
388-
389-
// Round down to the nearest minute, as this is the finest granularity cron supports.
390-
// Truncate is probably not necessary here, but doing it anyway to be sure.
391-
nextTransition := sched.Next(at).Truncate(time.Minute)
392-
393-
// The nextTransition is when the auto start should kick off. If it lands on a
394-
// forbidden day, do not allow the auto start. We use the time location of the
395-
// schedule to determine the weekday. So if "Saturday" is disallowed, the
396-
// definition of "Saturday" depends on the location of the schedule.
397-
zonedTransition := nextTransition.In(sched.Location())
398-
allowed := templateSchedule.AutostartRequirement.DaysMap()[zonedTransition.Weekday()]
399-
400-
return zonedTransition, allowed
401-
}
402-
403379
// isEligibleForAutostart returns true if the workspace should be autostopped.
404380
func isEligibleForAutostop(ws database.Workspace, build database.WorkspaceBuild, job database.ProvisionerJob, currentTick time.Time) bool {
405381
if job.JobStatus == database.ProvisionerJobStatusFailed {

coderd/coderd.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,9 +1055,6 @@ func New(options *Options) *API {
10551055
r.Put("/autoupdates", api.putWorkspaceAutoupdates)
10561056
r.Get("/resolve-autostart", api.resolveAutostart)
10571057
r.Route("/port-share", func(r chi.Router) {
1058-
r.Use(
1059-
httpmw.RequireExperiment(api.Experiments, codersdk.ExperimentSharedPorts),
1060-
)
10611058
r.Get("/", api.workspaceAgentPortShares)
10621059
r.Post("/", api.postWorkspaceAgentPortShare)
10631060
r.Delete("/", api.deleteWorkspaceAgentPortShare)

coderd/prometheusmetrics/prometheusmetrics_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,23 +511,29 @@ func TestAgentStats(t *testing.T) {
511511
func TestExperimentsMetric(t *testing.T) {
512512
t.Parallel()
513513

514+
if len(codersdk.ExperimentsAll) == 0 {
515+
t.Skip("No experiments are currently defined; skipping test.")
516+
}
517+
514518
tests := []struct {
515519
name string
516520
experiments codersdk.Experiments
517521
expected map[codersdk.Experiment]float64
518522
}{
519523
{
520-
name: "Enabled experiment is exported in metrics",
521-
experiments: codersdk.Experiments{codersdk.ExperimentSharedPorts},
524+
name: "Enabled experiment is exported in metrics",
525+
experiments: codersdk.Experiments{
526+
codersdk.ExperimentsAll[0],
527+
},
522528
expected: map[codersdk.Experiment]float64{
523-
codersdk.ExperimentSharedPorts: 1,
529+
codersdk.ExperimentsAll[0]: 1,
524530
},
525531
},
526532
{
527533
name: "Disabled experiment is exported in metrics",
528534
experiments: codersdk.Experiments{},
529535
expected: map[codersdk.Experiment]float64{
530-
codersdk.ExperimentSharedPorts: 0,
536+
codersdk.ExperimentsAll[0]: 0,
531537
},
532538
},
533539
{

coderd/provisionerdserver/provisionerdserver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,8 @@ func (s *server) CompleteJob(ctx context.Context, completed *proto.CompletedJob)
12571257
UserQuietHoursScheduleStore: *s.UserQuietHoursScheduleStore.Load(),
12581258
Now: now,
12591259
Workspace: workspace,
1260+
// Allowed to be the empty string.
1261+
WorkspaceAutostart: workspace.AutostartSchedule.String,
12601262
})
12611263
if err != nil {
12621264
return xerrors.Errorf("calculate auto stop: %w", err)

coderd/schedule/autostart.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package schedule
2+
3+
import (
4+
"time"
5+
6+
"github.com/coder/coder/v2/coderd/schedule/cron"
7+
)
8+
9+
// NextAutostart takes the workspace and template schedule and returns the next autostart schedule
10+
// after "at". The boolean returned is if the autostart should be allowed to start based on the template
11+
// schedule.
12+
func NextAutostart(at time.Time, wsSchedule string, templateSchedule TemplateScheduleOptions) (time.Time, bool) {
13+
sched, err := cron.Weekly(wsSchedule)
14+
if err != nil {
15+
return time.Time{}, false
16+
}
17+
18+
// Round down to the nearest minute, as this is the finest granularity cron supports.
19+
// Truncate is probably not necessary here, but doing it anyway to be sure.
20+
nextTransition := sched.Next(at).Truncate(time.Minute)
21+
22+
// The nextTransition is when the auto start should kick off. If it lands on a
23+
// forbidden day, do not allow the auto start. We use the time location of the
24+
// schedule to determine the weekday. So if "Saturday" is disallowed, the
25+
// definition of "Saturday" depends on the location of the schedule.
26+
zonedTransition := nextTransition.In(sched.Location())
27+
allowed := templateSchedule.AutostartRequirement.DaysMap()[zonedTransition.Weekday()]
28+
29+
return zonedTransition, allowed
30+
}

0 commit comments

Comments
 (0)