Skip to content

Commit 1c3881a

Browse files
authored
Merge branch 'main' into patch-3
2 parents 6afc3a6 + 17adfd1 commit 1c3881a

File tree

204 files changed

+4985
-4043
lines changed

Some content is hidden

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

204 files changed

+4985
-4043
lines changed

.github/workflows/ci.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ jobs:
506506
507507
- uses: actions/setup-node@v3
508508
with:
509-
node-version: "14"
509+
node-version: "16.16.0"
510510

511511
- name: Install node_modules
512512
run: ./scripts/yarn_install.sh
@@ -555,7 +555,7 @@ jobs:
555555

556556
- uses: actions/setup-node@v3
557557
with:
558-
node-version: "14"
558+
node-version: "16.16.0"
559559

560560
- name: Echo Go Cache Paths
561561
id: go-cache-paths
@@ -609,6 +609,10 @@ jobs:
609609
# only get 1 commit on shallow checkout.
610610
fetch-depth: 0
611611

612+
- uses: actions/setup-node@v3
613+
with:
614+
node-version: "16.16.0"
615+
612616
- name: Install dependencies
613617
run: cd site && yarn
614618

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
"stretchr",
114114
"STTY",
115115
"stuntest",
116+
"tanstack",
116117
"tailbroker",
117118
"tailcfg",
118119
"tailexchange",

Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ gen: \
424424
provisionerd/proto/provisionerd.pb.go \
425425
site/src/api/typesGenerated.ts \
426426
docs/admin/prometheus.md \
427-
docs/cli/coder.md \
427+
docs/cli.md \
428428
docs/admin/audit-logs.md \
429429
coderd/apidoc/swagger.json \
430430
.prettierignore.include \
@@ -444,7 +444,7 @@ gen/mark-fresh:
444444
provisionerd/proto/provisionerd.pb.go \
445445
site/src/api/typesGenerated.ts \
446446
docs/admin/prometheus.md \
447-
docs/cli/coder.md \
447+
docs/cli.md \
448448
docs/admin/audit-logs.md \
449449
coderd/apidoc/swagger.json \
450450
.prettierignore.include \
@@ -500,10 +500,11 @@ docs/admin/prometheus.md: scripts/metricsdocgen/main.go scripts/metricsdocgen/me
500500
cd site
501501
yarn run format:write:only ../docs/admin/prometheus.md
502502

503-
docs/cli/coder.md: scripts/clidocgen/main.go $(GO_SRC_FILES) docs/manifest.json
504-
BASE_PATH="." go run scripts/clidocgen/main.go
503+
docs/cli.md: scripts/clidocgen/main.go $(GO_SRC_FILES) docs/manifest.json
504+
rm -rf ./docs/cli/*.md
505+
BASE_PATH="." go run ./scripts/clidocgen
505506
cd site
506-
yarn run format:write:only ../docs/cli/*.md ../docs/manifest.json
507+
yarn run format:write:only ../docs/cli.md ../docs/cli/*.md ../docs/manifest.json
507508

508509
docs/admin/audit-logs.md: scripts/auditdocgen/main.go enterprise/audit/table.go
509510
go run scripts/auditdocgen/main.go

agent/agent.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,9 @@ func (a *agent) runCoordinator(ctx context.Context, network *tailnet.Conn) error
601601
}
602602
defer coordinator.Close()
603603
a.logger.Info(ctx, "connected to coordination server")
604-
sendNodes, errChan := tailnet.ServeCoordinator(coordinator, network.UpdateNodes)
604+
sendNodes, errChan := tailnet.ServeCoordinator(coordinator, func(nodes []*tailnet.Node) error {
605+
return network.UpdateNodes(nodes, false)
606+
})
605607
network.SetNodeCallback(sendNodes)
606608
select {
607609
case <-ctx.Done():

agent/agent_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,12 +1179,21 @@ func setupAgent(t *testing.T, metadata agentsdk.Metadata, ptyTimeout time.Durati
11791179
coordinator.ServeClient(serverConn, uuid.New(), agentID)
11801180
}()
11811181
sendNode, _ := tailnet.ServeCoordinator(clientConn, func(node []*tailnet.Node) error {
1182-
return conn.UpdateNodes(node)
1182+
return conn.UpdateNodes(node, false)
11831183
})
11841184
conn.SetNodeCallback(sendNode)
1185-
return &codersdk.WorkspaceAgentConn{
1185+
agentConn := &codersdk.WorkspaceAgentConn{
11861186
Conn: conn,
1187-
}, c, statsCh, fs
1187+
}
1188+
t.Cleanup(func() {
1189+
_ = agentConn.Close()
1190+
})
1191+
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
1192+
defer cancel()
1193+
if !agentConn.AwaitReachable(ctx) {
1194+
t.Fatal("agent not reachable")
1195+
}
1196+
return agentConn, c, statsCh, fs
11881197
}
11891198

11901199
var dialTestPayload = []byte("dean-was-here123")

cli/root.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919

2020
"golang.org/x/xerrors"
2121

22+
"cdr.dev/slog"
23+
2224
"github.com/charmbracelet/lipgloss"
2325
"github.com/kirsle/configdir"
2426
"github.com/mattn/go-isatty"
@@ -179,6 +181,21 @@ func Root(subcommands []*cobra.Command) *cobra.Command {
179181
return cmd
180182
}
181183

184+
type contextKey int
185+
186+
const (
187+
contextKeyLogger contextKey = iota
188+
)
189+
190+
func ContextWithLogger(ctx context.Context, l slog.Logger) context.Context {
191+
return context.WithValue(ctx, contextKeyLogger, l)
192+
}
193+
194+
func LoggerFromContext(ctx context.Context) (slog.Logger, bool) {
195+
l, ok := ctx.Value(contextKeyLogger).(slog.Logger)
196+
return l, ok
197+
}
198+
182199
// fixUnknownSubcommandError modifies the provided commands so that the
183200
// ones with subcommands output the correct error message when an
184201
// unknown subcommand is invoked.

cli/speedtest.go

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ import (
1919

2020
func speedtest() *cobra.Command {
2121
var (
22-
direct bool
23-
duration time.Duration
24-
reverse bool
22+
direct bool
23+
duration time.Duration
24+
direction string
2525
)
2626
cmd := &cobra.Command{
2727
Annotations: workspaceCommand,
@@ -48,10 +48,13 @@ func speedtest() *cobra.Command {
4848
return client.WorkspaceAgent(ctx, workspaceAgent.ID)
4949
},
5050
})
51-
if err != nil {
51+
if err != nil && !xerrors.Is(err, cliui.AgentStartError) {
5252
return xerrors.Errorf("await agent: %w", err)
5353
}
54-
logger := slog.Make(sloghuman.Sink(cmd.ErrOrStderr()))
54+
logger, ok := LoggerFromContext(ctx)
55+
if !ok {
56+
logger = slog.Make(sloghuman.Sink(cmd.ErrOrStderr()))
57+
}
5558
if cliflag.IsSetBool(cmd, varVerbose) {
5659
logger = logger.Leveled(slog.LevelDebug)
5760
}
@@ -94,25 +97,29 @@ func speedtest() *cobra.Command {
9497
} else {
9598
conn.AwaitReachable(ctx)
9699
}
97-
dir := tsspeedtest.Download
98-
if reverse {
99-
dir = tsspeedtest.Upload
100+
var tsDir tsspeedtest.Direction
101+
switch direction {
102+
case "up":
103+
tsDir = tsspeedtest.Upload
104+
case "down":
105+
tsDir = tsspeedtest.Download
106+
default:
107+
return xerrors.Errorf("invalid direction: %q", direction)
100108
}
101-
cmd.Printf("Starting a %ds %s test...\n", int(duration.Seconds()), dir)
102-
results, err := conn.Speedtest(ctx, dir, duration)
109+
cmd.Printf("Starting a %ds %s test...\n", int(duration.Seconds()), tsDir)
110+
results, err := conn.Speedtest(ctx, tsDir, duration)
103111
if err != nil {
104112
return err
105113
}
106114
tableWriter := cliui.Table()
107-
tableWriter.AppendHeader(table.Row{"Interval", "Transfer", "Bandwidth"})
115+
tableWriter.AppendHeader(table.Row{"Interval", "Throughput"})
108116
startTime := results[0].IntervalStart
109117
for _, r := range results {
110118
if r.Total {
111119
tableWriter.AppendSeparator()
112120
}
113121
tableWriter.AppendRow(table.Row{
114122
fmt.Sprintf("%.2f-%.2f sec", r.IntervalStart.Sub(startTime).Seconds(), r.IntervalEnd.Sub(startTime).Seconds()),
115-
fmt.Sprintf("%.4f MBits", r.MegaBits()),
116123
fmt.Sprintf("%.4f Mbits/sec", r.MBitsPerSecond()),
117124
})
118125
}
@@ -122,8 +129,9 @@ func speedtest() *cobra.Command {
122129
}
123130
cliflag.BoolVarP(cmd.Flags(), &direct, "direct", "d", "", false,
124131
"Specifies whether to wait for a direct connection before testing speed.")
125-
cliflag.BoolVarP(cmd.Flags(), &reverse, "reverse", "r", "", false,
126-
"Specifies whether to run in reverse mode where the client receives and the server sends.")
132+
cliflag.StringVarP(cmd.Flags(), &direction, "direction", "", "", "down",
133+
"Specifies whether to run in reverse mode where the client receives and the server sends. (up|down)",
134+
)
127135
cmd.Flags().DurationVarP(&duration, "time", "t", tsspeedtest.DefaultDuration,
128136
"Specifies the duration to monitor traffic.")
129137
return cmd

cli/speedtest_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import (
77
"github.com/stretchr/testify/assert"
88
"github.com/stretchr/testify/require"
99

10+
"cdr.dev/slog"
1011
"cdr.dev/slog/sloggers/slogtest"
1112
"github.com/coder/coder/agent"
13+
"github.com/coder/coder/cli"
1214
"github.com/coder/coder/cli/clitest"
1315
"github.com/coder/coder/coderd/coderdtest"
1416
"github.com/coder/coder/codersdk"
@@ -19,6 +21,7 @@ import (
1921

2022
func TestSpeedtest(t *testing.T) {
2123
t.Parallel()
24+
t.Skip("Flaky test - see https://github.com/coder/coder/issues/6321")
2225
if testing.Short() {
2326
t.Skip("This test takes a minimum of 5ms per a hardcoded value in Tailscale!")
2427
}
@@ -27,7 +30,7 @@ func TestSpeedtest(t *testing.T) {
2730
agentClient.SetSessionToken(agentToken)
2831
agentCloser := agent.New(agent.Options{
2932
Client: agentClient,
30-
Logger: slogtest.Make(t, nil).Named("agent"),
33+
Logger: slogtest.Make(t, nil).Named("agent").Leveled(slog.LevelDebug),
3134
})
3235
defer agentCloser.Close()
3336
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
@@ -49,10 +52,12 @@ func TestSpeedtest(t *testing.T) {
4952
clitest.SetupConfig(t, client, root)
5053
pty := ptytest.New(t)
5154
cmd.SetOut(pty.Output())
55+
cmd.SetErr(pty.Output())
5256

5357
ctx, cancel = context.WithTimeout(context.Background(), testutil.WaitLong)
5458
defer cancel()
5559

60+
ctx = cli.ContextWithLogger(ctx, slogtest.Make(t, nil).Named("speedtest").Leveled(slog.LevelDebug))
5661
cmdDone := tGo(t, func() {
5762
err := cmd.ExecuteContext(ctx)
5863
assert.NoError(t, err)

cli/ssh_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"golang.org/x/crypto/ssh"
2525
gosshagent "golang.org/x/crypto/ssh/agent"
2626

27+
"cdr.dev/slog"
2728
"cdr.dev/slog/sloggers/slogtest"
2829

2930
"github.com/coder/coder/agent"
@@ -47,6 +48,7 @@ func setupWorkspaceForAgent(t *testing.T, mutate func([]*proto.Agent) []*proto.A
4748
}
4849
}
4950
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
51+
client.Logger = slogtest.Make(t, nil).Named("client").Leveled(slog.LevelDebug)
5052
user := coderdtest.CreateFirstUser(t, client)
5153
agentToken := uuid.NewString()
5254
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{

cli/state.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ func state() *cobra.Command {
2727
func statePull() *cobra.Command {
2828
var buildNumber int
2929
cmd := &cobra.Command{
30-
Use: "pull <workspace> [file]",
31-
Args: cobra.MinimumNArgs(1),
30+
Use: "pull <workspace> [file]",
31+
Short: "Pull a Terraform state file from a workspace.",
32+
Args: cobra.MinimumNArgs(1),
3233
RunE: func(cmd *cobra.Command, args []string) error {
3334
client, err := CreateClient(cmd)
3435
if err != nil {
@@ -68,8 +69,9 @@ func statePull() *cobra.Command {
6869
func statePush() *cobra.Command {
6970
var buildNumber int
7071
cmd := &cobra.Command{
71-
Use: "push <workspace> <file>",
72-
Args: cobra.ExactArgs(2),
72+
Use: "push <workspace> <file>",
73+
Args: cobra.ExactArgs(2),
74+
Short: "Push a Terraform state file to a workspace.",
7375
RunE: func(cmd *cobra.Command, args []string) error {
7476
client, err := CreateClient(cmd)
7577
if err != nil {

0 commit comments

Comments
 (0)