Skip to content

Commit 55e1ec9

Browse files
committed
feat: add workspace-proxy-url flag to scaletest workspace-traffic
1 parent 7be96bb commit 55e1ec9

File tree

3 files changed

+54
-13
lines changed

3 files changed

+54
-13
lines changed

cli/exp_scaletest.go

+37-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"io"
1010
"math/rand"
1111
"net/http"
12+
"net/url"
1213
"os"
1314
"os/signal"
1415
"strconv"
@@ -860,13 +861,14 @@ func (r *RootCmd) scaletestCreateWorkspaces() *serpent.Command {
860861

861862
func (r *RootCmd) scaletestWorkspaceTraffic() *serpent.Command {
862863
var (
863-
tickInterval time.Duration
864-
bytesPerTick int64
865-
ssh bool
866-
useHostLogin bool
867-
app string
868-
template string
869-
targetWorkspaces string
864+
tickInterval time.Duration
865+
bytesPerTick int64
866+
ssh bool
867+
useHostLogin bool
868+
app string
869+
template string
870+
targetWorkspaces string
871+
workspaceProxyURL string
870872

871873
client = &codersdk.Client{}
872874
tracingFlags = &scaletestTracingFlags{}
@@ -1002,6 +1004,23 @@ func (r *RootCmd) scaletestWorkspaceTraffic() *serpent.Command {
10021004
return xerrors.Errorf("configure workspace app: %w", err)
10031005
}
10041006

1007+
var webClient *codersdk.Client
1008+
if workspaceProxyURL != "" {
1009+
u, err := url.Parse(workspaceProxyURL)
1010+
if err != nil {
1011+
return xerrors.Errorf("parse workspace proxy URL: %w", err)
1012+
}
1013+
1014+
webClient = codersdk.New(u)
1015+
webClient.HTTPClient = client.HTTPClient
1016+
webClient.SetSessionToken(client.SessionToken())
1017+
1018+
appConfig, err = createWorkspaceAppConfig(webClient, appHost.Host, app, ws, agent)
1019+
if err != nil {
1020+
return xerrors.Errorf("configure proxy workspace app: %w", err)
1021+
}
1022+
}
1023+
10051024
// Setup our workspace agent connection.
10061025
config := workspacetraffic.Config{
10071026
AgentID: agent.ID,
@@ -1015,6 +1034,10 @@ func (r *RootCmd) scaletestWorkspaceTraffic() *serpent.Command {
10151034
App: appConfig,
10161035
}
10171036

1037+
if webClient != nil {
1038+
config.WebClient = webClient
1039+
}
1040+
10181041
if err := config.Validate(); err != nil {
10191042
return xerrors.Errorf("validate config: %w", err)
10201043
}
@@ -1108,6 +1131,13 @@ func (r *RootCmd) scaletestWorkspaceTraffic() *serpent.Command {
11081131
Description: "Connect as the currently logged in user.",
11091132
Value: serpent.BoolOf(&useHostLogin),
11101133
},
1134+
{
1135+
Flag: "workspace-proxy-url",
1136+
Env: "CODER_SCALETEST_WORKSPACE_PROXY_URL",
1137+
Default: "",
1138+
Description: "URL for workspace proxy to send web traffic to.",
1139+
Value: serpent.StringOf(&workspaceProxyURL),
1140+
},
11111141
}
11121142

11131143
tracingFlags.attach(&cmd.Options)

scaletest/workspacetraffic/config.go

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55

66
"github.com/google/uuid"
77
"golang.org/x/xerrors"
8+
9+
"github.com/coder/coder/v2/codersdk"
810
)
911

1012
type Config struct {
@@ -33,6 +35,8 @@ type Config struct {
3335
Echo bool `json:"echo"`
3436

3537
App AppConfig `json:"app"`
38+
39+
WebClient *codersdk.Client
3640
}
3741

3842
func (c Config) Validate() error {

scaletest/workspacetraffic/run.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ import (
2323
)
2424

2525
type Runner struct {
26-
client *codersdk.Client
27-
cfg Config
26+
client *codersdk.Client
27+
webClient *codersdk.Client
28+
cfg Config
2829
}
2930

3031
var (
@@ -34,9 +35,15 @@ var (
3435

3536
// func NewRunner(client *codersdk.Client, cfg Config, metrics *Metrics) *Runner {
3637
func NewRunner(client *codersdk.Client, cfg Config) *Runner {
38+
webClient := client
39+
if cfg.WebClient != nil {
40+
webClient = cfg.WebClient
41+
}
42+
3743
return &Runner{
38-
client: client,
39-
cfg: cfg,
44+
client: client,
45+
webClient: webClient,
46+
cfg: cfg,
4047
}
4148
}
4249

@@ -94,7 +101,7 @@ func (r *Runner) Run(ctx context.Context, _ string, logs io.Writer) (err error)
94101
switch {
95102
case r.cfg.App.Name != "":
96103
logger.Info(ctx, "sending traffic to workspace app", slog.F("app", r.cfg.App.Name))
97-
conn, err = appClientConn(ctx, r.client, r.cfg.App.URL)
104+
conn, err = appClientConn(ctx, r.webClient, r.cfg.App.URL)
98105
if err != nil {
99106
logger.Error(ctx, "connect to workspace app", slog.Error(err))
100107
return xerrors.Errorf("connect to workspace app: %w", err)
@@ -113,7 +120,7 @@ func (r *Runner) Run(ctx context.Context, _ string, logs io.Writer) (err error)
113120

114121
default:
115122
logger.Info(ctx, "connecting to workspace agent", slog.F("method", "reconnectingpty"))
116-
conn, err = connectRPTY(ctx, r.client, agentID, reconnect, command)
123+
conn, err = connectRPTY(ctx, r.webClient, agentID, reconnect, command)
117124
if err != nil {
118125
logger.Error(ctx, "connect to workspace agent via reconnectingpty", slog.Error(err))
119126
return xerrors.Errorf("connect to workspace via reconnectingpty: %w", err)

0 commit comments

Comments
 (0)