Skip to content

Commit 8f5f3ca

Browse files
committed
Merge remote-tracking branch 'origin/main' into audit-date-filter/kira-pilot
2 parents 0904902 + ddbae4d commit 8f5f3ca

File tree

191 files changed

+3772
-1989
lines changed

Some content is hidden

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

191 files changed

+3772
-1989
lines changed

.github/workflows/coder.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Checkout
3535
uses: actions/checkout@v2
3636
- name: typos-action
37-
uses: crate-ci/typos@v1.12.8
37+
uses: crate-ci/typos@v1.12.12
3838
with:
3939
config: .github/workflows/typos.toml
4040
- name: Fix Helper
@@ -96,7 +96,7 @@ jobs:
9696
with:
9797
go-version: "~1.19"
9898
- name: golangci-lint
99-
uses: golangci/golangci-lint-action@v3.2.0
99+
uses: golangci/golangci-lint-action@v3.3.0
100100
with:
101101
version: v1.48.0
102102

.github/workflows/dogfood.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
steps:
1818
- name: Get branch name
1919
id: branch-name
20-
uses: tj-actions/branch-names@v6.1
20+
uses: tj-actions/branch-names@v6.2
2121

2222
- name: "Branch name to Docker tag name"
2323
id: docker-tag-name

.github/workflows/typos.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ MacOS = "macOS"
77
[default.extend-words]
88
# do as sudo replacement
99
doas = "doas"
10+
darcula = "darcula"
1011

1112
[files]
1213
extend-exclude = [

agent/agent.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,11 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (*t
242242
if err != nil {
243243
return nil, xerrors.Errorf("listen on the ssh port: %w", err)
244244
}
245+
a.closeMutex.Lock()
246+
a.connCloseWait.Add(1)
247+
a.closeMutex.Unlock()
245248
go func() {
249+
defer a.connCloseWait.Done()
246250
for {
247251
conn, err := sshListener.Accept()
248252
if err != nil {
@@ -256,7 +260,11 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (*t
256260
if err != nil {
257261
return nil, xerrors.Errorf("listen for reconnecting pty: %w", err)
258262
}
263+
a.closeMutex.Lock()
264+
a.connCloseWait.Add(1)
265+
a.closeMutex.Unlock()
259266
go func() {
267+
defer a.connCloseWait.Done()
260268
for {
261269
conn, err := reconnectingPTYListener.Accept()
262270
if err != nil {
@@ -290,7 +298,11 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (*t
290298
if err != nil {
291299
return nil, xerrors.Errorf("listen for speedtest: %w", err)
292300
}
301+
a.closeMutex.Lock()
302+
a.connCloseWait.Add(1)
303+
a.closeMutex.Unlock()
293304
go func() {
305+
defer a.connCloseWait.Done()
294306
for {
295307
conn, err := speedtestListener.Accept()
296308
if err != nil {
@@ -311,7 +323,11 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (*t
311323
if err != nil {
312324
return nil, xerrors.Errorf("listen for statistics: %w", err)
313325
}
326+
a.closeMutex.Lock()
327+
a.connCloseWait.Add(1)
328+
a.closeMutex.Unlock()
314329
go func() {
330+
defer a.connCloseWait.Done()
315331
defer statisticsListener.Close()
316332
server := &http.Server{
317333
Handler: a.statisticsHandler(),

agent/apphealth.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func NewWorkspaceAppHealthReporter(logger slog.Logger, apps []codersdk.Workspace
3333
hasHealthchecksEnabled := false
3434
health := make(map[string]codersdk.WorkspaceAppHealth, 0)
3535
for _, app := range apps {
36-
health[app.Name] = app.Health
36+
health[app.DisplayName] = app.Health
3737
if !hasHealthchecksEnabled && app.Health != codersdk.WorkspaceAppHealthDisabled {
3838
hasHealthchecksEnabled = true
3939
}
@@ -85,21 +85,21 @@ func NewWorkspaceAppHealthReporter(logger slog.Logger, apps []codersdk.Workspace
8585
}()
8686
if err != nil {
8787
mu.Lock()
88-
if failures[app.Name] < int(app.Healthcheck.Threshold) {
88+
if failures[app.DisplayName] < int(app.Healthcheck.Threshold) {
8989
// increment the failure count and keep status the same.
9090
// we will change it when we hit the threshold.
91-
failures[app.Name]++
91+
failures[app.DisplayName]++
9292
} else {
9393
// set to unhealthy if we hit the failure threshold.
9494
// we stop incrementing at the threshold to prevent the failure value from increasing forever.
95-
health[app.Name] = codersdk.WorkspaceAppHealthUnhealthy
95+
health[app.DisplayName] = codersdk.WorkspaceAppHealthUnhealthy
9696
}
9797
mu.Unlock()
9898
} else {
9999
mu.Lock()
100100
// we only need one successful health check to be considered healthy.
101-
health[app.Name] = codersdk.WorkspaceAppHealthHealthy
102-
failures[app.Name] = 0
101+
health[app.DisplayName] = codersdk.WorkspaceAppHealthHealthy
102+
failures[app.DisplayName] = 0
103103
mu.Unlock()
104104
}
105105

agent/apphealth_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ func TestAppHealth(t *testing.T) {
2727
defer cancel()
2828
apps := []codersdk.WorkspaceApp{
2929
{
30-
Name: "app1",
30+
DisplayName: "app1",
3131
Healthcheck: codersdk.Healthcheck{},
3232
Health: codersdk.WorkspaceAppHealthDisabled,
3333
},
3434
{
35-
Name: "app2",
35+
DisplayName: "app2",
3636
Healthcheck: codersdk.Healthcheck{
3737
// URL: We don't set the URL for this test because the setup will
3838
// create a httptest server for us and set it for us.
@@ -69,7 +69,7 @@ func TestAppHealth(t *testing.T) {
6969
defer cancel()
7070
apps := []codersdk.WorkspaceApp{
7171
{
72-
Name: "app2",
72+
DisplayName: "app2",
7373
Healthcheck: codersdk.Healthcheck{
7474
// URL: We don't set the URL for this test because the setup will
7575
// create a httptest server for us and set it for us.
@@ -102,7 +102,7 @@ func TestAppHealth(t *testing.T) {
102102
defer cancel()
103103
apps := []codersdk.WorkspaceApp{
104104
{
105-
Name: "app2",
105+
DisplayName: "app2",
106106
Healthcheck: codersdk.Healthcheck{
107107
// URL: We don't set the URL for this test because the setup will
108108
// create a httptest server for us and set it for us.
@@ -137,7 +137,7 @@ func TestAppHealth(t *testing.T) {
137137
defer cancel()
138138
apps := []codersdk.WorkspaceApp{
139139
{
140-
Name: "app2",
140+
DisplayName: "app2",
141141
Healthcheck: codersdk.Healthcheck{
142142
// URL: We don't set the URL for this test because the setup will
143143
// create a httptest server for us and set it for us.
@@ -187,7 +187,7 @@ func setupAppReporter(ctx context.Context, t *testing.T, apps []codersdk.Workspa
187187
mu.Lock()
188188
for name, health := range req.Healths {
189189
for i, app := range apps {
190-
if app.Name != name {
190+
if app.DisplayName != name {
191191
continue
192192
}
193193
app.Health = health

cli/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func create() *cobra.Command {
3333
return err
3434
}
3535

36-
organization, err := currentOrganization(cmd, client)
36+
organization, err := CurrentOrganization(cmd, client)
3737
if err != nil {
3838
return err
3939
}

cli/deployment/config.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func newConfig() *codersdk.DeploymentConfig {
132132
ProxyTrustedHeaders: &codersdk.DeploymentConfigField[[]string]{
133133
Name: "Proxy Trusted Headers",
134134
Flag: "proxy-trusted-headers",
135-
Usage: "Headers to trust for forwarding IP addresses. e.g. Cf-Connecting-IP True-Client-Ip, X-Forwarded-for",
135+
Usage: "Headers to trust for forwarding IP addresses. e.g. Cf-Connecting-Ip, True-Client-Ip, X-Forwarded-For",
136136
},
137137
ProxyTrustedOrigins: &codersdk.DeploymentConfigField[[]string]{
138138
Name: "Proxy Trusted Origins",
@@ -289,10 +289,18 @@ func newConfig() *codersdk.DeploymentConfig {
289289
Default: "tls12",
290290
},
291291
},
292-
TraceEnable: &codersdk.DeploymentConfigField[bool]{
293-
Name: "Trace Enable",
294-
Usage: "Whether application tracing data is collected.",
295-
Flag: "trace",
292+
Trace: &codersdk.TraceConfig{
293+
Enable: &codersdk.DeploymentConfigField[bool]{
294+
Name: "Trace Enable",
295+
Usage: "Whether application tracing data is collected. It exports to a backend configured by environment variables. See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md",
296+
Flag: "trace",
297+
},
298+
HoneycombAPIKey: &codersdk.DeploymentConfigField[string]{
299+
Name: "Trace Honeycomb API Key",
300+
Usage: "Enables trace exporting to Honeycomb.io using the provided API Key.",
301+
Flag: "trace-honeycomb-api-key",
302+
Secret: true,
303+
},
296304
},
297305
SecureAuthCookie: &codersdk.DeploymentConfigField[bool]{
298306
Name: "Secure Auth Cookie",
@@ -462,14 +470,20 @@ func readSliceFromViper[T any](vip *viper.Viper, key string, value any) []T {
462470
if prop == "-" {
463471
prop = fve.Tag.Get("yaml")
464472
}
465-
value := vip.Get(fmt.Sprintf("%s.%d.%s", key, entry, prop))
473+
configKey := fmt.Sprintf("%s.%d.%s", key, entry, prop)
474+
value := vip.Get(configKey)
466475
if value == nil {
467476
continue
468477
}
469478
if instance == nil {
470479
newType := reflect.Indirect(reflect.New(elementType))
471480
instance = &newType
472481
}
482+
switch instance.Field(i).Type().String() {
483+
case "[]string":
484+
value = vip.GetStringSlice(configKey)
485+
default:
486+
}
473487
instance.Field(i).Set(reflect.ValueOf(value))
474488
}
475489
if instance == nil {

cli/deployment/config_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ func TestConfig(t *testing.T) {
114114
require.Equal(t, config.TLS.Enable.Value, true)
115115
require.Equal(t, config.TLS.MinVersion.Value, "tls10")
116116
},
117+
}, {
118+
Name: "Trace",
119+
Env: map[string]string{
120+
"CODER_TRACE_ENABLE": "true",
121+
"CODER_TRACE_HONEYCOMB_API_KEY": "my-honeycomb-key",
122+
},
123+
Valid: func(config *codersdk.DeploymentConfig) {
124+
require.Equal(t, config.Trace.Enable.Value, true)
125+
require.Equal(t, config.Trace.HoneycombAPIKey.Value, "my-honeycomb-key")
126+
},
117127
}, {
118128
Name: "OIDC",
119129
Env: map[string]string{
@@ -158,6 +168,7 @@ func TestConfig(t *testing.T) {
158168
"CODER_GITAUTH_0_AUTH_URL": "https://auth.com",
159169
"CODER_GITAUTH_0_TOKEN_URL": "https://token.com",
160170
"CODER_GITAUTH_0_REGEX": "github.com",
171+
"CODER_GITAUTH_0_SCOPES": "read write",
161172

162173
"CODER_GITAUTH_1_ID": "another",
163174
"CODER_GITAUTH_1_TYPE": "gitlab",
@@ -177,6 +188,7 @@ func TestConfig(t *testing.T) {
177188
AuthURL: "https://auth.com",
178189
TokenURL: "https://token.com",
179190
Regex: "github.com",
191+
Scopes: []string{"read", "write"},
180192
}, {
181193
ID: "another",
182194
Type: "gitlab",
@@ -190,6 +202,7 @@ func TestConfig(t *testing.T) {
190202
}} {
191203
tc := tc
192204
t.Run(tc.Name, func(t *testing.T) {
205+
t.Helper()
193206
for key, value := range tc.Env {
194207
t.Setenv(key, value)
195208
}

cli/login.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func login() *cobra.Command {
8686
return xerrors.Errorf("Failed to check server %q for first user, is the URL correct and is coder accessible from your browser? Error - has initial user: %w", serverURL.String(), err)
8787
}
8888
if !hasInitialUser {
89-
_, _ = fmt.Fprintf(cmd.OutOrStdout(), caret+"Your Coder deployment hasn't been set up!\n")
89+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), Caret+"Your Coder deployment hasn't been set up!\n")
9090

9191
if username == "" {
9292
if !isTTY(cmd) {
@@ -244,7 +244,7 @@ func login() *cobra.Command {
244244
return xerrors.Errorf("write server url: %w", err)
245245
}
246246

247-
_, _ = fmt.Fprintf(cmd.OutOrStdout(), caret+"Welcome to Coder, %s! You're authenticated.\n", cliui.Styles.Keyword.Render(resp.Username))
247+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), Caret+"Welcome to Coder, %s! You're authenticated.\n", cliui.Styles.Keyword.Render(resp.Username))
248248
return nil
249249
},
250250
}

cli/logout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func logout() *cobra.Command {
6767
errorString := strings.TrimRight(errorStringBuilder.String(), "\n")
6868
return xerrors.New("Failed to log out.\n" + errorString)
6969
}
70-
_, _ = fmt.Fprintf(cmd.OutOrStdout(), caret+"You are no longer logged in. You can log in using 'coder login <url>'.\n")
70+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), Caret+"You are no longer logged in. You can log in using 'coder login <url>'.\n")
7171
return nil
7272
},
7373
}

cli/parameterslist.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func parameterList() *cobra.Command {
2727
return err
2828
}
2929

30-
organization, err := currentOrganization(cmd, client)
30+
organization, err := CurrentOrganization(cmd, client)
3131
if err != nil {
3232
return xerrors.Errorf("get current organization: %w", err)
3333
}

cli/resetpassword_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestResetPassword(t *testing.T) {
4141
serverCmd, cfg := clitest.New(t,
4242
"server",
4343
"--address", ":0",
44-
"--access-url", "example.com",
44+
"--access-url", "http://example.com",
4545
"--postgres-url", connectionURL,
4646
"--cache-dir", t.TempDir(),
4747
)

cli/root.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
)
3131

3232
var (
33-
caret = cliui.Styles.Prompt.String()
33+
Caret = cliui.Styles.Prompt.String()
3434

3535
// Applied as annotations to workspace commands
3636
// so they display in a separated "help" section.
@@ -352,8 +352,8 @@ func createAgentClient(cmd *cobra.Command) (*codersdk.Client, error) {
352352
return client, nil
353353
}
354354

355-
// currentOrganization returns the currently active organization for the authenticated user.
356-
func currentOrganization(cmd *cobra.Command, client *codersdk.Client) (codersdk.Organization, error) {
355+
// CurrentOrganization returns the currently active organization for the authenticated user.
356+
func CurrentOrganization(cmd *cobra.Command, client *codersdk.Client) (codersdk.Organization, error) {
357357
orgs, err := client.OrganizationsByUser(cmd.Context(), codersdk.Me)
358358
if err != nil {
359359
return codersdk.Organization{}, nil

cli/schedule_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ func TestScheduleShow(t *testing.T) {
5151
lines := strings.Split(strings.TrimSpace(stdoutBuf.String()), "\n")
5252
if assert.Len(t, lines, 4) {
5353
assert.Contains(t, lines[0], "Starts at 7:30AM Mon-Fri (Europe/Dublin)")
54-
assert.Contains(t, lines[1], "Starts next 7:30AM IST on ")
54+
assert.Contains(t, lines[1], "Starts next 7:30AM")
55+
// it should have either IST or GMT
56+
if !strings.Contains(lines[1], "IST") && !strings.Contains(lines[1], "GMT") {
57+
t.Error("expected either IST or GMT")
58+
}
5559
assert.Contains(t, lines[2], "Stops at 8h after start")
5660
assert.NotContains(t, lines[3], "Stops next -")
5761
}
@@ -137,7 +141,11 @@ func TestScheduleStart(t *testing.T) {
137141
lines := strings.Split(strings.TrimSpace(stdoutBuf.String()), "\n")
138142
if assert.Len(t, lines, 4) {
139143
assert.Contains(t, lines[0], "Starts at 9:30AM Mon-Fri (Europe/Dublin)")
140-
assert.Contains(t, lines[1], "Starts next 9:30AM IST on")
144+
assert.Contains(t, lines[1], "Starts next 9:30AM")
145+
// it should have either IST or GMT
146+
if !strings.Contains(lines[1], "IST") && !strings.Contains(lines[1], "GMT") {
147+
t.Error("expected either IST or GMT")
148+
}
141149
}
142150

143151
// Ensure autostart schedule updated

0 commit comments

Comments
 (0)