forked from grafana/k6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscale.go
45 lines (36 loc) · 1.06 KB
/
scale.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package cmd
import (
"errors"
"github.com/spf13/cobra"
v1 "go.k6.io/k6/api/v1"
"go.k6.io/k6/api/v1/client"
"go.k6.io/k6/cmd/state"
)
func getCmdScale(gs *state.GlobalState) *cobra.Command {
// scaleCmd represents the scale command
scaleCmd := &cobra.Command{
Use: "scale",
Short: "Scale a running test",
Long: `Scale a running test.
Use the global --address flag to specify the URL to the API server.`,
RunE: func(cmd *cobra.Command, _ []string) error {
vus := getNullInt64(cmd.Flags(), "vus")
max := getNullInt64(cmd.Flags(), "max")
if !vus.Valid && !max.Valid {
return errors.New("Specify either -u/--vus or -m/--max") //nolint:golint,stylecheck
}
c, err := client.New(gs.Flags.Address)
if err != nil {
return err
}
status, err := c.SetStatus(gs.Ctx, v1.Status{VUs: vus, VUsMax: max})
if err != nil {
return err
}
return yamlPrint(gs.Stdout, status)
},
}
scaleCmd.Flags().Int64P("vus", "u", 1, "number of virtual users")
scaleCmd.Flags().Int64P("max", "m", 0, "max available virtual users")
return scaleCmd
}