Skip to content

Commit 95e43ac

Browse files
committed
Merge remote-tracking branch 'origin/main' into inactivity-modal/kira-pilot
2 parents c1c3040 + cdba074 commit 95e43ac

File tree

190 files changed

+4592
-10764
lines changed

Some content is hidden

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

190 files changed

+4592
-10764
lines changed

.github/CODEOWNERS

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

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ runs:
88
with:
99
cache: true
1010
go-version: "~1.20"
11+
- name: Install gotestsum
12+
uses: jaxxstorm/action-install-gh-release@v1.10.0
13+
with:
14+
repo: gotestyourself/gotestsum
15+
tag: v1.9.0
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Upload tests to datadog
2+
if: always()
3+
inputs:
4+
api-key:
5+
description: "Datadog API key"
6+
required: true
7+
runs:
8+
using: "composite"
9+
steps:
10+
- shell: bash
11+
run: |
12+
owner=${{ github.repository_owner }}
13+
echo "owner: $owner"
14+
if [[ $owner != "coder" ]]; then
15+
echo "Not a pull request from the main repo, skipping..."
16+
exit 0
17+
fi
18+
if [[ -z "${{ inputs.api-key }}" ]]; then
19+
# This can happen for dependabot.
20+
echo "No API key provided, skipping..."
21+
exit 0
22+
fi
23+
npm install -g @datadog/datadog-ci
24+
datadog-ci junit upload --service coder ./gotests.xml \
25+
--tags os:${{runner.os}} --tags runner_name:${{runner.name}}
26+
env:
27+
DATADOG_API_KEY: ${{ inputs.api-key }}

.github/dependabot.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ updates:
5858
interval: "monthly"
5959
time: "06:00"
6060
timezone: "America/Chicago"
61+
reviewers:
62+
- "coder/ts"
6163
commit-message:
6264
prefix: "chore"
6365
labels: []

.github/workflows/ci.yaml

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737

3838
# Check for any typos!
3939
- name: Check for typos
40-
uses: crate-ci/typos@v1.14.11
40+
uses: crate-ci/typos@v1.14.12
4141
with:
4242
config: .github/workflows/typos.toml
4343
- name: Fix the typos
@@ -49,7 +49,7 @@ jobs:
4949
5050
# Check for Go linting errors!
5151
- name: Lint Go
52-
uses: golangci/golangci-lint-action@v3.3.1
52+
uses: golangci/golangci-lint-action@v3.5.0
5353
with:
5454
version: v1.52.2
5555

@@ -199,14 +199,6 @@ jobs:
199199

200200
- uses: ./.github/actions/setup-go
201201

202-
- name: Install gotestsum
203-
uses: jaxxstorm/action-install-gh-release@v1.10.0
204-
env:
205-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
206-
with:
207-
repo: gotestyourself/gotestsum
208-
tag: v1.9.0
209-
210202
- uses: hashicorp/setup-terraform@v2
211203
with:
212204
terraform_version: 1.1.9
@@ -243,6 +235,11 @@ jobs:
243235
path: ./gotests.xml
244236
retention-days: 30
245237

238+
- uses: ./.github/actions/upload-datadog
239+
if: always()
240+
with:
241+
api-key: ${{ secrets.DATADOG_API_KEY }}
242+
246243
- uses: codecov/codecov-action@v3
247244
# This action has a tendency to error out unexpectedly, it has
248245
# the `fail_ci_if_error` option that defaults to `false`, but
@@ -267,14 +264,6 @@ jobs:
267264

268265
- uses: ./.github/actions/setup-go
269266

270-
- name: Install gotestsum
271-
uses: jaxxstorm/action-install-gh-release@v1.10.0
272-
env:
273-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
274-
with:
275-
repo: gotestyourself/gotestsum
276-
tag: v1.9.0
277-
278267
- uses: hashicorp/setup-terraform@v2
279268
with:
280269
terraform_version: 1.1.9
@@ -299,6 +288,11 @@ jobs:
299288
path: ./gotests.xml
300289
retention-days: 30
301290

291+
- uses: ./.github/actions/upload-datadog
292+
if: always()
293+
with:
294+
api-key: ${{ secrets.DATADOG_API_KEY }}
295+
302296
- uses: codecov/codecov-action@v3
303297
# This action has a tendency to error out unexpectedly, it has
304298
# the `fail_ci_if_error` option that defaults to `false`, but
@@ -326,7 +320,12 @@ jobs:
326320

327321
- name: Run Tests
328322
run: |
329-
go test -race ./...
323+
gotestsum --junitfile="gotests.xml" -- -race ./...
324+
325+
- uses: ./.github/actions/upload-datadog
326+
if: always()
327+
with:
328+
api-key: ${{ secrets.DATADOG_API_KEY }}
330329

331330
deploy:
332331
name: "deploy"

.github/workflows/nightly-flake.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: nightly-flake
2+
on:
3+
schedule:
4+
# Every day at midnight
5+
- cron: "0 0 * * *"
6+
workflow_dispatch:
7+
# For testing purposes
8+
# push:
9+
# paths:
10+
# - ".github/workflows/nightly-flake.yaml"
11+
jobs:
12+
test-go-race:
13+
# While GitHub's toaster runners are likelier to flake, we want consistency
14+
# between this environment and the regular test environment for DataDog
15+
# statistics and to only show real workflow threats.
16+
runs-on: "buildjet-8vcpu-ubuntu-2204"
17+
# This runner costs 0.016 USD per minute,
18+
# so 0.016 * 240 = 3.84 USD per run.
19+
timeout-minutes: 240
20+
steps:
21+
- uses: actions/checkout@v3
22+
23+
- uses: ./.github/actions/setup-go
24+
25+
- uses: hashicorp/setup-terraform@v2
26+
with:
27+
terraform_version: 1.1.9
28+
terraform_wrapper: false
29+
30+
- name: Run Tests
31+
run: |
32+
# -race is likeliest to catch flaky tests
33+
# due to correctness detection and its performance
34+
# impact.
35+
gotestsum --junitfile="gotests.xml" -- -timeout=240m -count=10 -race ./...
36+
37+
- uses: ./.github/actions/upload-datadog
38+
if: always()
39+
with:
40+
api-key: ${{ secrets.DATADOG_API_KEY }}

cli/agent.go

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -58,58 +58,64 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
5858
ctx, cancel := context.WithCancel(inv.Context())
5959
defer cancel()
6060

61-
ignorePorts := map[int]string{}
61+
var (
62+
ignorePorts = map[int]string{}
63+
isLinux = runtime.GOOS == "linux"
6264

63-
isLinux := runtime.GOOS == "linux"
65+
sinks = []slog.Sink{}
66+
logClosers = []func() error{}
67+
)
68+
defer func() {
69+
for _, closer := range logClosers {
70+
_ = closer()
71+
}
72+
}()
73+
74+
addSinkIfProvided := func(sinkFn func(io.Writer) slog.Sink, loc string) error {
75+
switch loc {
76+
case "":
77+
// Do nothing.
78+
79+
case "/dev/stderr":
80+
sinks = append(sinks, sinkFn(inv.Stderr))
81+
82+
case "/dev/stdout":
83+
sinks = append(sinks, sinkFn(inv.Stdout))
84+
85+
default:
86+
fi, err := os.OpenFile(loc, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o644)
87+
if err != nil {
88+
return xerrors.Errorf("open log file %q: %w", loc, err)
89+
}
90+
sinks = append(sinks, sinkFn(fi))
91+
logClosers = append(logClosers, fi.Close)
92+
}
93+
return nil
94+
}
95+
96+
if err := addSinkIfProvided(sloghuman.Sink, slogHumanPath); err != nil {
97+
return xerrors.Errorf("add human sink: %w", err)
98+
}
99+
if err := addSinkIfProvided(slogjson.Sink, slogJSONPath); err != nil {
100+
return xerrors.Errorf("add json sink: %w", err)
101+
}
102+
if err := addSinkIfProvided(slogstackdriver.Sink, slogStackdriverPath); err != nil {
103+
return xerrors.Errorf("add stackdriver sink: %w", err)
104+
}
64105

65106
// Spawn a reaper so that we don't accumulate a ton
66107
// of zombie processes.
67108
if reaper.IsInitProcess() && !noReap && isLinux {
68109
logWriter := &lumberjack.Logger{
69110
Filename: filepath.Join(logDir, "coder-agent-init.log"),
70111
MaxSize: 5, // MB
112+
// Without this, rotated logs will never be deleted.
113+
MaxBackups: 1,
71114
}
72115
defer logWriter.Close()
73116

74-
sinks := []slog.Sink{sloghuman.Sink(logWriter)}
75-
closers := []func() error{}
76-
addSinkIfProvided := func(sinkFn func(io.Writer) slog.Sink, loc string) error {
77-
switch loc {
78-
case "":
79-
80-
case "/dev/stdout":
81-
sinks = append(sinks, sinkFn(inv.Stdout))
82-
83-
case "/dev/stderr":
84-
sinks = append(sinks, sinkFn(inv.Stderr))
85-
86-
default:
87-
fi, err := os.OpenFile(loc, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o644)
88-
if err != nil {
89-
return xerrors.Errorf("open log file %q: %w", loc, err)
90-
}
91-
closers = append(closers, fi.Close)
92-
sinks = append(sinks, sinkFn(fi))
93-
}
94-
return nil
95-
}
96-
97-
if err := addSinkIfProvided(sloghuman.Sink, slogHumanPath); err != nil {
98-
return xerrors.Errorf("add human sink: %w", err)
99-
}
100-
if err := addSinkIfProvided(slogjson.Sink, slogJSONPath); err != nil {
101-
return xerrors.Errorf("add json sink: %w", err)
102-
}
103-
if err := addSinkIfProvided(slogstackdriver.Sink, slogStackdriverPath); err != nil {
104-
return xerrors.Errorf("add stackdriver sink: %w", err)
105-
}
106-
117+
sinks = append(sinks, sloghuman.Sink(logWriter))
107118
logger := slog.Make(sinks...).Leveled(slog.LevelDebug)
108-
defer func() {
109-
for _, closer := range closers {
110-
_ = closer()
111-
}
112-
}()
113119

114120
logger.Info(ctx, "spawning reaper process")
115121
// Do not start a reaper on the child process. It's important
@@ -146,12 +152,15 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
146152
ljLogger := &lumberjack.Logger{
147153
Filename: filepath.Join(logDir, "coder-agent.log"),
148154
MaxSize: 5, // MB
155+
// Without this, rotated logs will never be deleted.
156+
MaxBackups: 1,
149157
}
150158
defer ljLogger.Close()
151159
logWriter := &closeWriter{w: ljLogger}
152160
defer logWriter.Close()
153161

154-
logger := slog.Make(sloghuman.Sink(inv.Stderr), sloghuman.Sink(logWriter)).Leveled(slog.LevelDebug)
162+
sinks = append(sinks, sloghuman.Sink(logWriter))
163+
logger := slog.Make(sinks...).Leveled(slog.LevelDebug)
155164

156165
version := buildinfo.Version()
157166
logger.Info(ctx, "starting agent",

cli/clitest/clitest.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"github.com/stretchr/testify/assert"
1919
"github.com/stretchr/testify/require"
2020

21+
"cdr.dev/slog"
22+
"cdr.dev/slog/sloggers/slogtest"
2123
"github.com/coder/coder/cli"
2224
"github.com/coder/coder/cli/clibase"
2325
"github.com/coder/coder/cli/config"
@@ -39,16 +41,17 @@ func New(t *testing.T, args ...string) (*clibase.Invocation, config.Root) {
3941

4042
type logWriter struct {
4143
prefix string
42-
t *testing.T
44+
log slog.Logger
4345
}
4446

4547
func (l *logWriter) Write(p []byte) (n int, err error) {
4648
trimmed := strings.TrimSpace(string(p))
4749
if trimmed == "" {
4850
return len(p), nil
4951
}
50-
l.t.Log(
51-
l.prefix + ": " + trimmed,
52+
l.log.Info(
53+
context.Background(),
54+
l.prefix+": "+trimmed,
5255
)
5356
return len(p), nil
5457
}
@@ -57,12 +60,13 @@ func NewWithCommand(
5760
t *testing.T, cmd *clibase.Cmd, args ...string,
5861
) (*clibase.Invocation, config.Root) {
5962
configDir := config.Root(t.TempDir())
63+
logger := slogtest.Make(t, nil)
6064
i := &clibase.Invocation{
6165
Command: cmd,
6266
Args: append([]string{"--global-config", string(configDir)}, args...),
6367
Stdin: io.LimitReader(nil, 0),
64-
Stdout: (&logWriter{prefix: "stdout", t: t}),
65-
Stderr: (&logWriter{prefix: "stderr", t: t}),
68+
Stdout: (&logWriter{prefix: "stdout", log: logger}),
69+
Stderr: (&logWriter{prefix: "stderr", log: logger}),
6670
}
6771
t.Logf("invoking command: %s %s", cmd.Name(), strings.Join(i.Args, " "))
6872

0 commit comments

Comments
 (0)