mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
36665e17b2
This PR adds a `WatchAllWorkspaces` function with `watch-all-workspaces` endpoint, which can be used to listen on a single global pubsub channel for _all_ workspace build updates, and makes use of it in the autostart scaletest. This negates the need to use a workspace watch pubsub channel _per_ workspace, which has auth overhead associated with each call. This is especially relevant in situations such as the autostart scaletest, where we need to start/stop a set of workspaces before we can configure their autostart config. The overhead associated with all the watch requests skews the scaletest results and makes it harder to reason about the performance of the autostart feature itself. The autostart scaletest also no longer generates its own metrics nor does it wait for all the workspaces to actually start via autostart. We should update the scaletest dashboard after both PRs are merged to measure autostart performance via the new metrics. The new function/endpoint and its usage in the autostart scaletest are gated behind an experiment feature flag, this is something we should discuss whether we want to enable the endpoint in prod by default or not. If so, we can remove the experiment. --------- Signed-off-by: Callum Styan <callumstyan@gmail.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Callum Styan <callum@coder.com>
65 lines
2.1 KiB
Go
65 lines
2.1 KiB
Go
package loadtestutil
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/coder/coder/v2/cryptorand"
|
|
)
|
|
|
|
const (
|
|
// Prefix for all scaletest resources (users and workspaces)
|
|
ScaleTestPrefix = "scaletest"
|
|
|
|
// Email domain for scaletest users
|
|
EmailDomain = "@scaletest.local"
|
|
|
|
DefaultRandLength = 8
|
|
)
|
|
|
|
// GenerateUserIdentifier generates a username and email for scale testing.
|
|
// The username follows the pattern: scaletest-<random>-<id>
|
|
// The email follows the pattern: <random>-<id>@scaletest.local
|
|
func GenerateUserIdentifier(id string) (username, email string, err error) {
|
|
randStr, err := cryptorand.String(DefaultRandLength)
|
|
if err != nil {
|
|
return "", "", err
|
|
}
|
|
|
|
username = fmt.Sprintf("%s-%s-%s", ScaleTestPrefix, randStr, id)
|
|
email = fmt.Sprintf("%s-%s%s", randStr, id, EmailDomain)
|
|
return username, email, nil
|
|
}
|
|
|
|
// GenerateWorkspaceName generates a workspace name for scale testing.
|
|
// The workspace name follows the pattern: scaletest-<random>-<id>
|
|
func GenerateWorkspaceName(id string) (name string, err error) {
|
|
randStr, err := cryptorand.String(DefaultRandLength)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return fmt.Sprintf("%s-%s-%s", ScaleTestPrefix, randStr, id), nil
|
|
}
|
|
|
|
// GenerateDeterministicWorkspaceName generates a deterministic workspace name
|
|
// for scale testing without a random component. This is useful when the
|
|
// workspace name needs to be known before the workspace is created, such as
|
|
// for pre-creating channels keyed by workspace name.
|
|
// The workspace name follows the pattern: scaletest-<id>
|
|
func GenerateDeterministicWorkspaceName(id string) string {
|
|
return fmt.Sprintf("%s-%s", ScaleTestPrefix, id)
|
|
}
|
|
|
|
// IsScaleTestUser checks if a username indicates it was created for scale testing.
|
|
func IsScaleTestUser(username, email string) bool {
|
|
return strings.HasPrefix(username, ScaleTestPrefix+"-") ||
|
|
strings.HasSuffix(email, EmailDomain)
|
|
}
|
|
|
|
// IsScaleTestWorkspace checks if a workspace name indicates it was created for scale testing.
|
|
func IsScaleTestWorkspace(workspaceName, ownerName string) bool {
|
|
return strings.HasPrefix(workspaceName, ScaleTestPrefix+"-") ||
|
|
strings.HasPrefix(ownerName, ScaleTestPrefix+"-")
|
|
}
|