Skip to content

feat: add load testing harness, coder loadtest command #4853

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 7 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
chore: pr comments
  • Loading branch information
deansheather committed Nov 2, 2022
commit e5d2f97bfb2119962d14a60dcf73eb18470497f0
16 changes: 6 additions & 10 deletions cli/loadtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,21 @@ func loadtest() *cobra.Command {
}

var (
configReader io.Reader
configCloser io.Closer
configReader io.ReadCloser
)
if configPath == "-" {
configReader = cmd.InOrStdin()
configReader = io.NopCloser(cmd.InOrStdin())
} else {
f, err := os.Open(configPath)
if err != nil {
return xerrors.Errorf("open config file %q: %w", configPath, err)
}
configReader = f
configCloser = f
}

var config LoadTestConfig
err := json.NewDecoder(configReader).Decode(&config)
if configCloser != nil {
_ = configCloser.Close()
}
_ = configReader.Close()
if err != nil {
return xerrors.Errorf("read config file %q: %w", configPath, err)
}
Expand Down Expand Up @@ -87,7 +83,7 @@ func loadtest() *cobra.Command {
}
}
if !ok {
return xerrors.Errorf("Not logged in as site owner. Load testing is only available to the site owner.")
return xerrors.Errorf("Not logged in as site owner. Load testing is only available to site owners.")
}

// Disable ratelimits for future requests.
Expand All @@ -100,8 +96,8 @@ func loadtest() *cobra.Command {
for i, t := range config.Tests {
name := fmt.Sprintf("%s-%d", t.Type, i)

for i := 0; i < t.Count; i++ {
id := strconv.Itoa(i)
for j := 0; j < t.Count; j++ {
id := strconv.Itoa(j)
runner, err := t.NewRunner(client)
if err != nil {
return xerrors.Errorf("create %q runner for %s/%s: %w", t.Type, name, id, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name string already has the id in it right? Seems redundant to include it again

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name is the name of the test e.g. workspacebuild-0 and the id is the iteration of the test e.g. 0, 1, 2, 3, etc.

I reused the i variable in the two loops which makes this hard to read, so I've changed the inner loop to j to make it easier to read

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah

Expand Down
7 changes: 6 additions & 1 deletion coderd/httpapi/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import (
)

// Duration wraps time.Duration and provides better JSON marshaling and
// unmarshaling.
// unmarshaling. The default time.Duration marshals as an integer and only
// accepts integers when unmarshaling, which is not very user friendly as users
// cannot write durations like "1h30m".
//
// This type marshals as a string like "1h30m", and unmarshals from either a
// string or an integer.
type Duration time.Duration

var _ json.Marshaler = Duration(0)
Expand Down