Skip to content

feat: add workspace-proxy-url flag to scaletest workspace-traffic #15920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions cli/exp_scaletest.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io"
"math/rand"
"net/http"
"net/url"
"os"
"os/signal"
"strconv"
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions scaletest/workspacetraffic/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

"github.com/google/uuid"
"golang.org/x/xerrors"

"github.com/coder/coder/v2/codersdk"
)

type Config struct {
Expand Down Expand Up @@ -33,6 +35,8 @@ type Config struct {
Echo bool `json:"echo"`

App AppConfig `json:"app"`

WebClient *codersdk.Client
}

func (c Config) Validate() error {
Expand Down
19 changes: 13 additions & 6 deletions scaletest/workspacetraffic/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import (
)

type Runner struct {
client *codersdk.Client
cfg Config
client *codersdk.Client
webClient *codersdk.Client
cfg Config
}

var (
Expand All @@ -34,9 +35,15 @@ var (

// func NewRunner(client *codersdk.Client, cfg Config, metrics *Metrics) *Runner {
func NewRunner(client *codersdk.Client, cfg Config) *Runner {
webClient := client
if cfg.WebClient != nil {
webClient = cfg.WebClient
}

return &Runner{
client: client,
cfg: cfg,
client: client,
webClient: webClient,
cfg: cfg,
}
}

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

default:
logger.Info(ctx, "connecting to workspace agent", slog.F("method", "reconnectingpty"))
conn, err = connectRPTY(ctx, r.client, agentID, reconnect, command)
conn, err = connectRPTY(ctx, r.webClient, agentID, reconnect, command)
if err != nil {
logger.Error(ctx, "connect to workspace agent via reconnectingpty", slog.Error(err))
return xerrors.Errorf("connect to workspace via reconnectingpty: %w", err)
Expand Down
Loading