mirror of
https://github.com/coder/coder.git
synced 2026-09-22 05:05:20 +08:00
feat: add workspace-proxy-url flag to scaletest workspace-traffic (#15920)
This allows the command to target a workspace proxy when appropriate. Part of https://github.com/coder/internal/issues/149 So far I've verified the correct url being used with logs: ``` ➜ coder git:(f0ssel/workspace-traffic-proxy) ✗ go run ./cmd/coder/main.go exp scaletest workspace-traffic --job-timeout=60s --workspace-proxy-url="https://paris.fly.dev.coder.com" Running load test... web url: https://paris.fly.dev.coder.com ... ➜ coder git:(f0ssel/workspace-traffic-proxy) ✗ go run ./cmd/coder/main.go exp scaletest workspace-traffic --job-timeout=60s --workspace-proxy-url="https://paris.fly.dev.coder.com" --app="code-server" Running load test... app url: https://paris.fly.dev.coder.com/@f0ssel/scaletest-1.dev/apps/code-server ```
This commit is contained in:
+37
-7
@@ -9,6 +9,7 @@ import (
|
||||
"io"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
@@ -860,13 +861,14 @@ func (r *RootCmd) scaletestCreateWorkspaces() *serpent.Command {
|
||||
|
||||
func (r *RootCmd) scaletestWorkspaceTraffic() *serpent.Command {
|
||||
var (
|
||||
tickInterval time.Duration
|
||||
bytesPerTick int64
|
||||
ssh bool
|
||||
useHostLogin bool
|
||||
app string
|
||||
template string
|
||||
targetWorkspaces string
|
||||
tickInterval time.Duration
|
||||
bytesPerTick int64
|
||||
ssh bool
|
||||
useHostLogin bool
|
||||
app string
|
||||
template string
|
||||
targetWorkspaces string
|
||||
workspaceProxyURL string
|
||||
|
||||
client = &codersdk.Client{}
|
||||
tracingFlags = &scaletestTracingFlags{}
|
||||
@@ -1002,6 +1004,23 @@ func (r *RootCmd) scaletestWorkspaceTraffic() *serpent.Command {
|
||||
return xerrors.Errorf("configure workspace app: %w", err)
|
||||
}
|
||||
|
||||
var webClient *codersdk.Client
|
||||
if workspaceProxyURL != "" {
|
||||
u, err := url.Parse(workspaceProxyURL)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("parse workspace proxy URL: %w", err)
|
||||
}
|
||||
|
||||
webClient = codersdk.New(u)
|
||||
webClient.HTTPClient = client.HTTPClient
|
||||
webClient.SetSessionToken(client.SessionToken())
|
||||
|
||||
appConfig, err = createWorkspaceAppConfig(webClient, appHost.Host, app, ws, agent)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("configure proxy workspace app: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Setup our workspace agent connection.
|
||||
config := workspacetraffic.Config{
|
||||
AgentID: agent.ID,
|
||||
@@ -1015,6 +1034,10 @@ func (r *RootCmd) scaletestWorkspaceTraffic() *serpent.Command {
|
||||
App: appConfig,
|
||||
}
|
||||
|
||||
if webClient != nil {
|
||||
config.WebClient = webClient
|
||||
}
|
||||
|
||||
if err := config.Validate(); err != nil {
|
||||
return xerrors.Errorf("validate config: %w", err)
|
||||
}
|
||||
@@ -1108,6 +1131,13 @@ func (r *RootCmd) scaletestWorkspaceTraffic() *serpent.Command {
|
||||
Description: "Connect as the currently logged in user.",
|
||||
Value: serpent.BoolOf(&useHostLogin),
|
||||
},
|
||||
{
|
||||
Flag: "workspace-proxy-url",
|
||||
Env: "CODER_SCALETEST_WORKSPACE_PROXY_URL",
|
||||
Default: "",
|
||||
Description: "URL for workspace proxy to send web traffic to.",
|
||||
Value: serpent.StringOf(&workspaceProxyURL),
|
||||
},
|
||||
}
|
||||
|
||||
tracingFlags.attach(&cmd.Options)
|
||||
|
||||
Reference in New Issue
Block a user