Skip to content

Commit f721f3d

Browse files
chore: add --disable-direct to coder exp scaletest workspace-traffic --ssh (coder#19632)
Relates to coder/internal#888 As part of our renewed connection scaletesting efforts, we want to scaletest coder in a scenario where direct connections aren't available (relatively common for our customers), and all concurrent connections are relayed via DERP. This PR adds a flag, `--disable-direct` that can be included on the existing`coder exp scaletest workspace-traffic -ssh` to disable direct connections.
1 parent 71ea919 commit f721f3d

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

cli/exp_scaletest.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@ func (r *RootCmd) scaletestWorkspaceTraffic() *serpent.Command {
864864
tickInterval time.Duration
865865
bytesPerTick int64
866866
ssh bool
867+
disableDirect bool
867868
useHostLogin bool
868869
app string
869870
template string
@@ -1023,15 +1024,16 @@ func (r *RootCmd) scaletestWorkspaceTraffic() *serpent.Command {
10231024

10241025
// Setup our workspace agent connection.
10251026
config := workspacetraffic.Config{
1026-
AgentID: agent.ID,
1027-
BytesPerTick: bytesPerTick,
1028-
Duration: strategy.timeout,
1029-
TickInterval: tickInterval,
1030-
ReadMetrics: metrics.ReadMetrics(ws.OwnerName, ws.Name, agent.Name),
1031-
WriteMetrics: metrics.WriteMetrics(ws.OwnerName, ws.Name, agent.Name),
1032-
SSH: ssh,
1033-
Echo: ssh,
1034-
App: appConfig,
1027+
AgentID: agent.ID,
1028+
BytesPerTick: bytesPerTick,
1029+
Duration: strategy.timeout,
1030+
TickInterval: tickInterval,
1031+
ReadMetrics: metrics.ReadMetrics(ws.OwnerName, ws.Name, agent.Name),
1032+
WriteMetrics: metrics.WriteMetrics(ws.OwnerName, ws.Name, agent.Name),
1033+
SSH: ssh,
1034+
DisableDirect: disableDirect,
1035+
Echo: ssh,
1036+
App: appConfig,
10351037
}
10361038

10371039
if webClient != nil {
@@ -1117,6 +1119,13 @@ func (r *RootCmd) scaletestWorkspaceTraffic() *serpent.Command {
11171119
Description: "Send traffic over SSH, cannot be used with --app.",
11181120
Value: serpent.BoolOf(&ssh),
11191121
},
1122+
{
1123+
Flag: "disable-direct",
1124+
Env: "CODER_SCALETEST_WORKSPACE_TRAFFIC_DISABLE_DIRECT_CONNECTIONS",
1125+
Default: "false",
1126+
Description: "Disable direct connections for SSH traffic to workspaces. Does nothing if `--ssh` is not also set.",
1127+
Value: serpent.BoolOf(&disableDirect),
1128+
},
11201129
{
11211130
Flag: "app",
11221131
Env: "CODER_SCALETEST_WORKSPACE_TRAFFIC_APP",

scaletest/workspacetraffic/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ type Config struct {
2828

2929
SSH bool `json:"ssh"`
3030

31+
// Ignored unless SSH is true.
32+
DisableDirect bool `json:"ssh_disable_direct"`
33+
3134
// Echo controls whether the agent should echo the data it receives.
3235
// If false, the agent will discard the data. Note that setting this
3336
// to true will double the amount of data read from the agent for

scaletest/workspacetraffic/conn.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (c *rptyConn) Close() (err error) {
144144
}
145145

146146
//nolint:revive // Ignore requestPTY control flag.
147-
func connectSSH(ctx context.Context, client *codersdk.Client, agentID uuid.UUID, cmd string, requestPTY bool) (rwc *countReadWriteCloser, err error) {
147+
func connectSSH(ctx context.Context, client *codersdk.Client, agentID uuid.UUID, cmd string, requestPTY bool, blockEndpoints bool) (rwc *countReadWriteCloser, err error) {
148148
var closers []func() error
149149
defer func() {
150150
if err != nil {
@@ -156,7 +156,9 @@ func connectSSH(ctx context.Context, client *codersdk.Client, agentID uuid.UUID,
156156
}
157157
}()
158158

159-
agentConn, err := workspacesdk.New(client).DialAgent(ctx, agentID, &workspacesdk.DialAgentOptions{})
159+
agentConn, err := workspacesdk.New(client).DialAgent(ctx, agentID, &workspacesdk.DialAgentOptions{
160+
BlockEndpoints: blockEndpoints,
161+
})
160162
if err != nil {
161163
return nil, xerrors.Errorf("dial workspace agent: %w", err)
162164
}

scaletest/workspacetraffic/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (r *Runner) Run(ctx context.Context, _ string, logs io.Writer) (err error)
111111
// If echo is enabled, disable PTY to avoid double echo and
112112
// reduce CPU usage.
113113
requestPTY := !r.cfg.Echo
114-
conn, err = connectSSH(ctx, r.client, agentID, command, requestPTY)
114+
conn, err = connectSSH(ctx, r.client, agentID, command, requestPTY, r.cfg.DisableDirect)
115115
if err != nil {
116116
logger.Error(ctx, "connect to workspace agent via ssh", slog.Error(err))
117117
return xerrors.Errorf("connect to workspace via ssh: %w", err)

0 commit comments

Comments
 (0)