@@ -857,11 +857,12 @@ func (r *RootCmd) scaletestCreateWorkspaces() *clibase.Cmd {
857
857
858
858
func (r * RootCmd ) scaletestWorkspaceTraffic () * clibase.Cmd {
859
859
var (
860
- tickInterval time.Duration
861
- bytesPerTick int64
862
- ssh bool
863
- app string
864
- template string
860
+ tickInterval time.Duration
861
+ bytesPerTick int64
862
+ ssh bool
863
+ app string
864
+ template string
865
+ targetWorkspaces string
865
866
866
867
client = & codersdk.Client {}
867
868
tracingFlags = & scaletestTracingFlags {}
@@ -912,6 +913,10 @@ func (r *RootCmd) scaletestWorkspaceTraffic() *clibase.Cmd {
912
913
return xerrors .Errorf ("parse template: %w" , err )
913
914
}
914
915
}
916
+ targetWorkspaceStart , targetWorkspaceEnd , err := parseTargetRange ("workspaces" , targetWorkspaces )
917
+ if err != nil {
918
+ return xerrors .Errorf ("parse target workspaces: %w" , err )
919
+ }
915
920
916
921
appHost , err := client .AppHost (ctx )
917
922
if err != nil {
@@ -923,9 +928,16 @@ func (r *RootCmd) scaletestWorkspaceTraffic() *clibase.Cmd {
923
928
return err
924
929
}
925
930
931
+ if targetWorkspaceEnd == 0 {
932
+ targetWorkspaceEnd = len (workspaces )
933
+ }
934
+
926
935
if len (workspaces ) == 0 {
927
936
return xerrors .Errorf ("no scaletest workspaces exist" )
928
937
}
938
+ if targetWorkspaceEnd > len (workspaces ) {
939
+ return xerrors .Errorf ("target workspace end %d is greater than the number of workspaces %d" , targetWorkspaceEnd , len (workspaces ))
940
+ }
929
941
930
942
tracerProvider , closeTracing , tracingEnabled , err := tracingFlags .provider (ctx )
931
943
if err != nil {
@@ -951,6 +963,10 @@ func (r *RootCmd) scaletestWorkspaceTraffic() *clibase.Cmd {
951
963
952
964
th := harness .NewTestHarness (strategy .toStrategy (), cleanupStrategy .toStrategy ())
953
965
for idx , ws := range workspaces {
966
+ if idx < targetWorkspaceStart || idx >= targetWorkspaceEnd {
967
+ continue
968
+ }
969
+
954
970
var (
955
971
agent codersdk.WorkspaceAgent
956
972
name = "workspace-traffic"
@@ -1039,6 +1055,12 @@ func (r *RootCmd) scaletestWorkspaceTraffic() *clibase.Cmd {
1039
1055
Description : "Name or ID of the template. Traffic generation will be limited to workspaces created from this template." ,
1040
1056
Value : clibase .StringOf (& template ),
1041
1057
},
1058
+ {
1059
+ Flag : "target-workspaces" ,
1060
+ Env : "CODER_SCALETEST_TARGET_WORKSPACES" ,
1061
+ Description : "Target a specific range of workspaces in the format [START]:[END] (exclusive). Example: 0:10 will target the 10 first alphabetically sorted workspaces (0-9)." ,
1062
+ Value : clibase .StringOf (& targetWorkspaces ),
1063
+ },
1042
1064
{
1043
1065
Flag : "bytes-per-tick" ,
1044
1066
Env : "CODER_SCALETEST_WORKSPACE_TRAFFIC_BYTES_PER_TICK" ,
@@ -1080,10 +1102,11 @@ func (r *RootCmd) scaletestWorkspaceTraffic() *clibase.Cmd {
1080
1102
1081
1103
func (r * RootCmd ) scaletestDashboard () * clibase.Cmd {
1082
1104
var (
1083
- interval time.Duration
1084
- jitter time.Duration
1085
- headless bool
1086
- randSeed int64
1105
+ interval time.Duration
1106
+ jitter time.Duration
1107
+ headless bool
1108
+ randSeed int64
1109
+ targetUsers string
1087
1110
1088
1111
client = & codersdk.Client {}
1089
1112
tracingFlags = & scaletestTracingFlags {}
@@ -1106,6 +1129,10 @@ func (r *RootCmd) scaletestDashboard() *clibase.Cmd {
1106
1129
if ! (jitter < interval ) {
1107
1130
return xerrors .Errorf ("--jitter must be less than --interval" )
1108
1131
}
1132
+ targetUserStart , targetUserEnd , err := parseTargetRange ("users" , targetUsers )
1133
+ if err != nil {
1134
+ return xerrors .Errorf ("parse target users: %w" , err )
1135
+ }
1109
1136
ctx := inv .Context ()
1110
1137
logger := inv .Logger .AppendSinks (sloghuman .Sink (inv .Stdout ))
1111
1138
if r .verbose {
@@ -1142,8 +1169,15 @@ func (r *RootCmd) scaletestDashboard() *clibase.Cmd {
1142
1169
if err != nil {
1143
1170
return xerrors .Errorf ("get scaletest users" )
1144
1171
}
1172
+ if targetUserEnd == 0 {
1173
+ targetUserEnd = len (users )
1174
+ }
1175
+
1176
+ for idx , usr := range users {
1177
+ if idx < targetUserStart || idx >= targetUserEnd {
1178
+ continue
1179
+ }
1145
1180
1146
- for _ , usr := range users {
1147
1181
//nolint:gosec // not used for cryptographic purposes
1148
1182
rndGen := rand .New (rand .NewSource (randSeed ))
1149
1183
name := fmt .Sprintf ("dashboard-%s" , usr .Username )
@@ -1214,6 +1248,12 @@ func (r *RootCmd) scaletestDashboard() *clibase.Cmd {
1214
1248
}
1215
1249
1216
1250
cmd .Options = []clibase.Option {
1251
+ {
1252
+ Flag : "target-users" ,
1253
+ Env : "CODER_SCALETEST_DASHBOARD_TARGET_USERS" ,
1254
+ Description : "Target a specific range of users in the format [START]:[END] (exclusive). Example: 0:10 will target the 10 first alphabetically sorted users (0-9)." ,
1255
+ Value : clibase .StringOf (& targetUsers ),
1256
+ },
1217
1257
{
1218
1258
Flag : "interval" ,
1219
1259
Env : "CODER_SCALETEST_DASHBOARD_INTERVAL" ,
@@ -1430,6 +1470,36 @@ func parseTemplate(ctx context.Context, client *codersdk.Client, organizationIDs
1430
1470
return tpl , nil
1431
1471
}
1432
1472
1473
+ func parseTargetRange (name , targets string ) (start , end int , err error ) {
1474
+ if targets == "" {
1475
+ return 0 , 0 , nil
1476
+ }
1477
+
1478
+ parts := strings .Split (targets , ":" )
1479
+ if len (parts ) != 2 {
1480
+ return 0 , 0 , xerrors .Errorf ("invalid target %s %q" , name , targets )
1481
+ }
1482
+
1483
+ start , err = strconv .Atoi (parts [0 ])
1484
+ if err != nil {
1485
+ return 0 , 0 , xerrors .Errorf ("invalid target %s %q: %w" , name , targets , err )
1486
+ }
1487
+
1488
+ end , err = strconv .Atoi (parts [1 ])
1489
+ if err != nil {
1490
+ return 0 , 0 , xerrors .Errorf ("invalid target %s %q: %w" , name , targets , err )
1491
+ }
1492
+
1493
+ if start == end {
1494
+ return 0 , 0 , xerrors .Errorf ("invalid target %s %q: start and end cannot be equal" , name , targets )
1495
+ }
1496
+ if end < start {
1497
+ return 0 , 0 , xerrors .Errorf ("invalid target %s %q: end cannot be less than start" , name , targets )
1498
+ }
1499
+
1500
+ return start , end , nil
1501
+ }
1502
+
1433
1503
func createWorkspaceAppConfig (client * codersdk.Client , appHost , app string , workspace codersdk.Workspace , agent codersdk.WorkspaceAgent ) (workspacetraffic.AppConfig , error ) {
1434
1504
if app == "" {
1435
1505
return workspacetraffic.AppConfig {}, nil
0 commit comments