feat: add codersdk constructor that uses an independent transport (#22282)

This is useful at least in the case of scaletests but potentially in
other places as well. I noticed that scaletest workspace creation
hammers a single coderd replica.
---------

Signed-off-by: Callum Styan <callumstyan@gmail.com>
This commit is contained in:
Callum Styan
2026-03-10 10:33:49 -07:00
committed by GitHub
parent da71a09ab6
commit c2534c19f6
2 changed files with 15 additions and 2 deletions

View File

@@ -76,7 +76,13 @@ func (r *Runner) RunReturningUser(ctx context.Context, id string, logs io.Writer
r.user = user
_, _ = fmt.Fprintln(logs, "\nLogging in as new user...")
client := codersdk.New(r.client.URL)
// Duplicate the client with an independent transport to ensure each user
// login gets its own HTTP connection pool, preventing connection sharing
// during load testing.
client, err := loadtestutil.DupClientCopyingHeaders(r.client, nil)
if err != nil {
return User{}, xerrors.Errorf("duplicate client: %w", err)
}
loginRes, err := client.LoginWithPassword(ctx, codersdk.LoginWithPasswordRequest{
Email: r.cfg.Email,
Password: password,

View File

@@ -77,7 +77,14 @@ func (r *Runner) Run(ctx context.Context, id string, logs io.Writer) error {
return xerrors.Errorf("create user: %w", err)
}
user = newUser.User
client = codersdk.New(r.client.URL)
// Duplicate the client with an independent transport to ensure each
// workspace creation gets its own HTTP connection pool. This prevents
// HTTP/2 connection multiplexing from causing all workspace GET requests
// to route to a single backend pod during load testing.
client, err = loadtestutil.DupClientCopyingHeaders(r.client, nil)
if err != nil {
return xerrors.Errorf("duplicate client: %w", err)
}
client.SetSessionToken(newUser.SessionToken)
}