@@ -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 := parseTargetWorkspaces (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 workspaces 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" ,
@@ -1430,6 +1452,33 @@ func parseTemplate(ctx context.Context, client *codersdk.Client, organizationIDs
1430
1452
return tpl , nil
1431
1453
}
1432
1454
1455
+ func parseTargetWorkspaces (targetWorkspaces string ) (start , end int , err error ) {
1456
+ if targetWorkspaces == "" {
1457
+ return 0 , 0 , nil
1458
+ }
1459
+
1460
+ parts := strings .Split (targetWorkspaces , ":" )
1461
+ if len (parts ) != 2 {
1462
+ return 0 , 0 , xerrors .Errorf ("invalid target workspaces %q" , targetWorkspaces )
1463
+ }
1464
+
1465
+ start , err = strconv .Atoi (parts [0 ])
1466
+ if err != nil {
1467
+ return 0 , 0 , xerrors .Errorf ("invalid target workspaces %q: %w" , targetWorkspaces , err )
1468
+ }
1469
+
1470
+ end , err = strconv .Atoi (parts [1 ])
1471
+ if err != nil {
1472
+ return 0 , 0 , xerrors .Errorf ("invalid target workspaces %q: %w" , targetWorkspaces , err )
1473
+ }
1474
+
1475
+ if start == end {
1476
+ return 0 , 0 , xerrors .Errorf ("invalid target workspaces %q: start and end cannot be equal" , targetWorkspaces )
1477
+ }
1478
+
1479
+ return start , end , nil
1480
+ }
1481
+
1433
1482
func createWorkspaceAppConfig (client * codersdk.Client , appHost , app string , workspace codersdk.Workspace , agent codersdk.WorkspaceAgent ) (workspacetraffic.AppConfig , error ) {
1434
1483
if app == "" {
1435
1484
return workspacetraffic.AppConfig {}, nil
0 commit comments