Skip to content

Commit ba5f7c6

Browse files
committed
Merge branch 'main' of github.com:/coder/coder into dk/system-notifications-lib
2 parents 337997d + e5268e4 commit ba5f7c6

File tree

110 files changed

+2555
-3394
lines changed

Some content is hidden

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

110 files changed

+2555
-3394
lines changed

.github/workflows/release.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ jobs:
180180

181181
- name: Test migrations from current ref to main
182182
run: |
183-
make test-migrations
183+
POSTGRES_VERSION=13 make test-migrations
184184
185185
# Setup GCloud for signing Windows binaries.
186186
- name: Authenticate to Google Cloud
@@ -297,7 +297,7 @@ jobs:
297297
298298
# build Docker images for each architecture
299299
version="$(./scripts/version.sh)"
300-
make -j build/coder_"$version"_linux_{amd64,arm64,armv7}.tag
300+
make build/coder_"$version"_linux_{amd64,arm64,armv7}.tag
301301
302302
# we can't build multi-arch if the images aren't pushed, so quit now
303303
# if dry-running
@@ -308,7 +308,7 @@ jobs:
308308
309309
# build and push multi-arch manifest, this depends on the other images
310310
# being pushed so will automatically push them.
311-
make -j push/build/coder_"$version"_linux.tag
311+
make push/build/coder_"$version"_linux.tag
312312
313313
# if the current version is equal to the highest (according to semver)
314314
# version in the repo, also create a multi-arch image as ":latest" and

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ gen/mark-fresh:
518518
$(DB_GEN_FILES) \
519519
site/src/api/typesGenerated.ts \
520520
coderd/rbac/object_gen.go \
521+
codersdk/rbacresources_gen.go \
521522
docs/admin/prometheus.md \
522523
docs/cli.md \
523524
docs/admin/audit-logs.md \
@@ -616,10 +617,10 @@ site/src/theme/icons.json: $(wildcard scripts/gensite/*) $(wildcard site/static/
616617
examples/examples.gen.json: scripts/examplegen/main.go examples/examples.go $(shell find ./examples/templates)
617618
go run ./scripts/examplegen/main.go > examples/examples.gen.json
618619

619-
coderd/rbac/object_gen.go: scripts/rbacgen/rbacobject.gotmpl scripts/rbacgen/main.go coderd/rbac/object.go
620+
coderd/rbac/object_gen.go: scripts/rbacgen/rbacobject.gotmpl scripts/rbacgen/main.go coderd/rbac/object.go coderd/rbac/policy/policy.go
620621
go run scripts/rbacgen/main.go rbac > coderd/rbac/object_gen.go
621622

622-
codersdk/rbacresources_gen.go: scripts/rbacgen/codersdk.gotmpl scripts/rbacgen/main.go coderd/rbac/object.go
623+
codersdk/rbacresources_gen.go: scripts/rbacgen/codersdk.gotmpl scripts/rbacgen/main.go coderd/rbac/object.go coderd/rbac/policy/policy.go
623624
go run scripts/rbacgen/main.go codersdk > codersdk/rbacresources_gen.go
624625

625626
docs/admin/prometheus.md: scripts/metricsdocgen/main.go scripts/metricsdocgen/metrics

agent/apphealth.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"golang.org/x/xerrors"
1111

1212
"cdr.dev/slog"
13-
"github.com/coder/coder/v2/clock"
1413
"github.com/coder/coder/v2/codersdk"
1514
"github.com/coder/coder/v2/codersdk/agentsdk"
15+
"github.com/coder/quartz"
1616
)
1717

1818
// PostWorkspaceAgentAppHealth updates the workspace app health.
@@ -23,7 +23,7 @@ type WorkspaceAppHealthReporter func(ctx context.Context)
2323

2424
// NewWorkspaceAppHealthReporter creates a WorkspaceAppHealthReporter that reports app health to coderd.
2525
func NewWorkspaceAppHealthReporter(logger slog.Logger, apps []codersdk.WorkspaceApp, postWorkspaceAgentAppHealth PostWorkspaceAgentAppHealth) WorkspaceAppHealthReporter {
26-
return NewAppHealthReporterWithClock(logger, apps, postWorkspaceAgentAppHealth, clock.NewReal())
26+
return NewAppHealthReporterWithClock(logger, apps, postWorkspaceAgentAppHealth, quartz.NewReal())
2727
}
2828

2929
// NewAppHealthReporterWithClock is only called directly by test code. Product code should call
@@ -32,7 +32,7 @@ func NewAppHealthReporterWithClock(
3232
logger slog.Logger,
3333
apps []codersdk.WorkspaceApp,
3434
postWorkspaceAgentAppHealth PostWorkspaceAgentAppHealth,
35-
clk clock.Clock,
35+
clk quartz.Clock,
3636
) WorkspaceAppHealthReporter {
3737
logger = logger.Named("apphealth")
3838

agent/apphealth_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import (
1717
"github.com/coder/coder/v2/agent"
1818
"github.com/coder/coder/v2/agent/agenttest"
1919
"github.com/coder/coder/v2/agent/proto"
20-
"github.com/coder/coder/v2/clock"
2120
"github.com/coder/coder/v2/coderd/httpapi"
2221
"github.com/coder/coder/v2/codersdk"
2322
"github.com/coder/coder/v2/codersdk/agentsdk"
2423
"github.com/coder/coder/v2/testutil"
24+
"github.com/coder/quartz"
2525
)
2626

2727
func TestAppHealth_Healthy(t *testing.T) {
@@ -69,7 +69,7 @@ func TestAppHealth_Healthy(t *testing.T) {
6969
httpapi.Write(r.Context(), w, http.StatusOK, nil)
7070
}),
7171
}
72-
mClock := clock.NewMock(t)
72+
mClock := quartz.NewMock(t)
7373
healthcheckTrap := mClock.Trap().TickerFunc("healthcheck")
7474
defer healthcheckTrap.Close()
7575
reportTrap := mClock.Trap().TickerFunc("report")
@@ -137,7 +137,7 @@ func TestAppHealth_500(t *testing.T) {
137137
}),
138138
}
139139

140-
mClock := clock.NewMock(t)
140+
mClock := quartz.NewMock(t)
141141
healthcheckTrap := mClock.Trap().TickerFunc("healthcheck")
142142
defer healthcheckTrap.Close()
143143
reportTrap := mClock.Trap().TickerFunc("report")
@@ -187,7 +187,7 @@ func TestAppHealth_Timeout(t *testing.T) {
187187
<-r.Context().Done()
188188
}),
189189
}
190-
mClock := clock.NewMock(t)
190+
mClock := quartz.NewMock(t)
191191
start := mClock.Now()
192192

193193
// for this test, it's easier to think in the number of milliseconds elapsed
@@ -235,7 +235,7 @@ func setupAppReporter(
235235
ctx context.Context, t *testing.T,
236236
apps []codersdk.WorkspaceApp,
237237
handlers []http.Handler,
238-
clk clock.Clock,
238+
clk quartz.Clock,
239239
) (*agenttest.FakeAgentAPI, func()) {
240240
closers := []func(){}
241241
for _, app := range apps {

cli/list.go

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strconv"
77
"time"
88

9+
"github.com/google/uuid"
910
"golang.org/x/xerrors"
1011

1112
"github.com/coder/coder/v2/cli/cliui"
@@ -22,19 +23,21 @@ type workspaceListRow struct {
2223
codersdk.Workspace `table:"-"`
2324

2425
// For table format:
25-
Favorite bool `json:"-" table:"favorite"`
26-
WorkspaceName string `json:"-" table:"workspace,default_sort"`
27-
Template string `json:"-" table:"template"`
28-
Status string `json:"-" table:"status"`
29-
Healthy string `json:"-" table:"healthy"`
30-
LastBuilt string `json:"-" table:"last built"`
31-
CurrentVersion string `json:"-" table:"current version"`
32-
Outdated bool `json:"-" table:"outdated"`
33-
StartsAt string `json:"-" table:"starts at"`
34-
StartsNext string `json:"-" table:"starts next"`
35-
StopsAfter string `json:"-" table:"stops after"`
36-
StopsNext string `json:"-" table:"stops next"`
37-
DailyCost string `json:"-" table:"daily cost"`
26+
Favorite bool `json:"-" table:"favorite"`
27+
WorkspaceName string `json:"-" table:"workspace,default_sort"`
28+
OrganizationID uuid.UUID `json:"-" table:"organization id"`
29+
OrganizationName string `json:"-" table:"organization name"`
30+
Template string `json:"-" table:"template"`
31+
Status string `json:"-" table:"status"`
32+
Healthy string `json:"-" table:"healthy"`
33+
LastBuilt string `json:"-" table:"last built"`
34+
CurrentVersion string `json:"-" table:"current version"`
35+
Outdated bool `json:"-" table:"outdated"`
36+
StartsAt string `json:"-" table:"starts at"`
37+
StartsNext string `json:"-" table:"starts next"`
38+
StopsAfter string `json:"-" table:"stops after"`
39+
StopsNext string `json:"-" table:"stops next"`
40+
DailyCost string `json:"-" table:"daily cost"`
3841
}
3942

4043
func workspaceListRowFromWorkspace(now time.Time, workspace codersdk.Workspace) workspaceListRow {
@@ -53,20 +56,22 @@ func workspaceListRowFromWorkspace(now time.Time, workspace codersdk.Workspace)
5356
}
5457
workspaceName := favIco + " " + workspace.OwnerName + "/" + workspace.Name
5558
return workspaceListRow{
56-
Favorite: workspace.Favorite,
57-
Workspace: workspace,
58-
WorkspaceName: workspaceName,
59-
Template: workspace.TemplateName,
60-
Status: status,
61-
Healthy: healthy,
62-
LastBuilt: durationDisplay(lastBuilt),
63-
CurrentVersion: workspace.LatestBuild.TemplateVersionName,
64-
Outdated: workspace.Outdated,
65-
StartsAt: schedRow.StartsAt,
66-
StartsNext: schedRow.StartsNext,
67-
StopsAfter: schedRow.StopsAfter,
68-
StopsNext: schedRow.StopsNext,
69-
DailyCost: strconv.Itoa(int(workspace.LatestBuild.DailyCost)),
59+
Favorite: workspace.Favorite,
60+
Workspace: workspace,
61+
WorkspaceName: workspaceName,
62+
OrganizationID: workspace.OrganizationID,
63+
OrganizationName: workspace.OrganizationName,
64+
Template: workspace.TemplateName,
65+
Status: status,
66+
Healthy: healthy,
67+
LastBuilt: durationDisplay(lastBuilt),
68+
CurrentVersion: workspace.LatestBuild.TemplateVersionName,
69+
Outdated: workspace.Outdated,
70+
StartsAt: schedRow.StartsAt,
71+
StartsNext: schedRow.StartsNext,
72+
StopsAfter: schedRow.StopsAfter,
73+
StopsNext: schedRow.StopsNext,
74+
DailyCost: strconv.Itoa(int(workspace.LatestBuild.DailyCost)),
7075
}
7176
}
7277

cli/ping.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ func (r *RootCmd) ping() *serpent.Command {
5858
_, _ = fmt.Fprintln(inv.Stderr, "Direct connections disabled.")
5959
opts.BlockEndpoints = true
6060
}
61+
if !r.disableNetworkTelemetry {
62+
opts.EnableTelemetry = true
63+
}
6164
conn, err := workspacesdk.New(client).DialAgent(ctx, workspaceAgent.ID, opts)
6265
if err != nil {
6366
return err

cli/portforward.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ func (r *RootCmd) portForward() *serpent.Command {
106106
_, _ = fmt.Fprintln(inv.Stderr, "Direct connections disabled.")
107107
opts.BlockEndpoints = true
108108
}
109+
if !r.disableNetworkTelemetry {
110+
opts.EnableTelemetry = true
111+
}
109112
conn, err := workspacesdk.New(client).DialAgent(ctx, workspaceAgent.ID, opts)
110113
if err != nil {
111114
return err

cli/root.go

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,20 @@ var (
5252
)
5353

5454
const (
55-
varURL = "url"
56-
varToken = "token"
57-
varAgentToken = "agent-token"
58-
varAgentTokenFile = "agent-token-file"
59-
varAgentURL = "agent-url"
60-
varHeader = "header"
61-
varHeaderCommand = "header-command"
62-
varNoOpen = "no-open"
63-
varNoVersionCheck = "no-version-warning"
64-
varNoFeatureWarning = "no-feature-warning"
65-
varForceTty = "force-tty"
66-
varVerbose = "verbose"
67-
varDisableDirect = "disable-direct-connections"
55+
varURL = "url"
56+
varToken = "token"
57+
varAgentToken = "agent-token"
58+
varAgentTokenFile = "agent-token-file"
59+
varAgentURL = "agent-url"
60+
varHeader = "header"
61+
varHeaderCommand = "header-command"
62+
varNoOpen = "no-open"
63+
varNoVersionCheck = "no-version-warning"
64+
varNoFeatureWarning = "no-feature-warning"
65+
varForceTty = "force-tty"
66+
varVerbose = "verbose"
67+
varDisableDirect = "disable-direct-connections"
68+
varDisableNetworkTelemetry = "disable-network-telemetry"
6869

6970
notLoggedInMessage = "You are not logged in. Try logging in using 'coder login <url>'."
7071

@@ -435,6 +436,13 @@ func (r *RootCmd) Command(subcommands []*serpent.Command) (*serpent.Command, err
435436
Value: serpent.BoolOf(&r.disableDirect),
436437
Group: globalGroup,
437438
},
439+
{
440+
Flag: varDisableNetworkTelemetry,
441+
Env: "CODER_DISABLE_NETWORK_TELEMETRY",
442+
Description: "Disable network telemetry. Network telemetry is collected when connecting to workspaces using the CLI, and is forwarded to the server. If telemetry is also enabled on the server, it may be sent to Coder. Network telemetry is used to measure network quality and detect regressions.",
443+
Value: serpent.BoolOf(&r.disableNetworkTelemetry),
444+
Group: globalGroup,
445+
},
438446
{
439447
Flag: "debug-http",
440448
Description: "Debug codersdk HTTP requests.",
@@ -481,8 +489,9 @@ type RootCmd struct {
481489
disableDirect bool
482490
debugHTTP bool
483491

484-
noVersionCheck bool
485-
noFeatureWarning bool
492+
disableNetworkTelemetry bool
493+
noVersionCheck bool
494+
noFeatureWarning bool
486495
}
487496

488497
// InitClient authenticates the client with files from disk

cli/speedtest.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ func (r *RootCmd) speedtest() *serpent.Command {
102102
_, _ = fmt.Fprintln(inv.Stderr, "Direct connections disabled.")
103103
opts.BlockEndpoints = true
104104
}
105+
if !r.disableNetworkTelemetry {
106+
opts.EnableTelemetry = true
107+
}
105108
if pcapFile != "" {
106109
s := capture.New()
107110
opts.CaptureHook = s.LogPacket
@@ -183,6 +186,7 @@ func (r *RootCmd) speedtest() *serpent.Command {
183186
outputResult.Intervals[i] = interval
184187
}
185188
}
189+
conn.Conn.SendSpeedtestTelemetry(outputResult.Overall.ThroughputMbits)
186190
out, err := formatter.Format(inv.Context(), outputResult)
187191
if err != nil {
188192
return err

cli/ssh.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,9 @@ func (r *RootCmd) ssh() *serpent.Command {
243243
}
244244
conn, err := workspacesdk.New(client).
245245
DialAgent(ctx, workspaceAgent.ID, &workspacesdk.DialAgentOptions{
246-
Logger: logger,
247-
BlockEndpoints: r.disableDirect,
246+
Logger: logger,
247+
BlockEndpoints: r.disableDirect,
248+
EnableTelemetry: !r.disableNetworkTelemetry,
248249
})
249250
if err != nil {
250251
return xerrors.Errorf("dial agent: %w", err)
@@ -436,6 +437,7 @@ func (r *RootCmd) ssh() *serpent.Command {
436437
}
437438

438439
err = sshSession.Wait()
440+
conn.SendDisconnectedTelemetry("ssh")
439441
if err != nil {
440442
if exitErr := (&gossh.ExitError{}); errors.As(err, &exitErr) {
441443
// Clear the error since it's not useful beyond

cli/templatelist.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
func (r *RootCmd) templateList() *serpent.Command {
1414
orgContext := NewOrganizationContext()
1515
formatter := cliui.NewOutputFormatter(
16-
cliui.TableFormat([]templateTableRow{}, []string{"name", "last updated", "used by"}),
16+
cliui.TableFormat([]templateTableRow{}, []string{"name", "organization name", "last updated", "used by"}),
1717
cliui.JSONFormat(),
1818
)
1919

cli/templates.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,15 @@ type templateTableRow struct {
8383
Template codersdk.Template
8484

8585
// Used by table format:
86-
Name string `json:"-" table:"name,default_sort"`
87-
CreatedAt string `json:"-" table:"created at"`
88-
LastUpdated string `json:"-" table:"last updated"`
89-
OrganizationID uuid.UUID `json:"-" table:"organization id"`
90-
Provisioner codersdk.ProvisionerType `json:"-" table:"provisioner"`
91-
ActiveVersionID uuid.UUID `json:"-" table:"active version id"`
92-
UsedBy string `json:"-" table:"used by"`
93-
DefaultTTL time.Duration `json:"-" table:"default ttl"`
86+
Name string `json:"-" table:"name,default_sort"`
87+
CreatedAt string `json:"-" table:"created at"`
88+
LastUpdated string `json:"-" table:"last updated"`
89+
OrganizationID uuid.UUID `json:"-" table:"organization id"`
90+
OrganizationName string `json:"-" table:"organization name"`
91+
Provisioner codersdk.ProvisionerType `json:"-" table:"provisioner"`
92+
ActiveVersionID uuid.UUID `json:"-" table:"active version id"`
93+
UsedBy string `json:"-" table:"used by"`
94+
DefaultTTL time.Duration `json:"-" table:"default ttl"`
9495
}
9596

9697
// templateToRows converts a list of templates to a list of templateTableRow for
@@ -99,15 +100,16 @@ func templatesToRows(templates ...codersdk.Template) []templateTableRow {
99100
rows := make([]templateTableRow, len(templates))
100101
for i, template := range templates {
101102
rows[i] = templateTableRow{
102-
Template: template,
103-
Name: template.Name,
104-
CreatedAt: template.CreatedAt.Format("January 2, 2006"),
105-
LastUpdated: template.UpdatedAt.Format("January 2, 2006"),
106-
OrganizationID: template.OrganizationID,
107-
Provisioner: template.Provisioner,
108-
ActiveVersionID: template.ActiveVersionID,
109-
UsedBy: pretty.Sprint(cliui.DefaultStyles.Fuchsia, formatActiveDevelopers(template.ActiveUserCount)),
110-
DefaultTTL: (time.Duration(template.DefaultTTLMillis) * time.Millisecond),
103+
Template: template,
104+
Name: template.Name,
105+
CreatedAt: template.CreatedAt.Format("January 2, 2006"),
106+
LastUpdated: template.UpdatedAt.Format("January 2, 2006"),
107+
OrganizationID: template.OrganizationID,
108+
OrganizationName: template.OrganizationName,
109+
Provisioner: template.Provisioner,
110+
ActiveVersionID: template.ActiveVersionID,
111+
UsedBy: pretty.Sprint(cliui.DefaultStyles.Fuchsia, formatActiveDevelopers(template.ActiveUserCount)),
112+
DefaultTTL: (time.Duration(template.DefaultTTLMillis) * time.Millisecond),
111113
}
112114
}
113115

cli/testdata/coder_--help.golden

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ variables or flags.
6666
--disable-direct-connections bool, $CODER_DISABLE_DIRECT_CONNECTIONS
6767
Disable direct (P2P) connections to workspaces.
6868

69+
--disable-network-telemetry bool, $CODER_DISABLE_NETWORK_TELEMETRY
70+
Disable network telemetry. Network telemetry is collected when
71+
connecting to workspaces using the CLI, and is forwarded to the
72+
server. If telemetry is also enabled on the server, it may be sent to
73+
Coder. Network telemetry is used to measure network quality and detect
74+
regressions.
75+
6976
--global-config string, $CODER_CONFIG_DIR (default: ~/.config/coderv2)
7077
Path to the global `coder` config directory.
7178

0 commit comments

Comments
 (0)