()
| 1146 | } |
| 1147 | |
| 1148 | func (r *RootCmd) scaletestWorkspaceUpdates() *serpent.Command { |
| 1149 | var ( |
| 1150 | workspaceCount int64 |
| 1151 | powerUserWorkspaces int64 |
| 1152 | powerUserPercentage float64 |
| 1153 | workspaceUpdatesTimeout time.Duration |
| 1154 | dialTimeout time.Duration |
| 1155 | template string |
| 1156 | noCleanup bool |
| 1157 | |
| 1158 | parameterFlags workspaceParameterFlags |
| 1159 | tracingFlags = &scaletestTracingFlags{} |
| 1160 | // This test requires unlimited concurrency |
| 1161 | timeoutStrategy = &timeoutFlags{} |
| 1162 | cleanupStrategy = newScaletestCleanupStrategy() |
| 1163 | output = &scaletestOutputFlags{} |
| 1164 | prometheusFlags = &scaletestPrometheusFlags{} |
| 1165 | ) |
| 1166 | |
| 1167 | cmd := &serpent.Command{ |
| 1168 | Use: "workspace-updates", |
| 1169 | Short: "Simulate the load of Coder Desktop clients receiving workspace updates", |
| 1170 | Handler: func(inv *serpent.Invocation) error { |
| 1171 | ctx := inv.Context() |
| 1172 | client, err := r.TryInitClient(inv) |
| 1173 | if err != nil { |
| 1174 | return err |
| 1175 | } |
| 1176 | |
| 1177 | notifyCtx, stop := signal.NotifyContext(ctx, StopSignals...) // Checked later. |
| 1178 | defer stop() |
| 1179 | ctx = notifyCtx |
| 1180 | |
| 1181 | me, err := RequireAdmin(ctx, client) |
| 1182 | if err != nil { |
| 1183 | return err |
| 1184 | } |
| 1185 | |
| 1186 | if workspaceCount <= 0 { |
| 1187 | return xerrors.Errorf("--workspace-count must be greater than 0") |
| 1188 | } |
| 1189 | if powerUserWorkspaces <= 1 { |
| 1190 | return xerrors.Errorf("--power-user-workspaces must be greater than 1") |
| 1191 | } |
| 1192 | if powerUserPercentage < 0 || powerUserPercentage > 100 { |
| 1193 | return xerrors.Errorf("--power-user-proportion must be between 0 and 100") |
| 1194 | } |
| 1195 | |
| 1196 | powerUserWorkspaceCount := int64(float64(workspaceCount) * powerUserPercentage / 100) |
| 1197 | remainder := powerUserWorkspaceCount % powerUserWorkspaces |
| 1198 | // If the power user workspaces can't be evenly divided, round down |
| 1199 | // to the nearest multiple so that we only have two groups of users. |
| 1200 | workspaceCount -= remainder |
| 1201 | powerUserWorkspaceCount -= remainder |
| 1202 | powerUserCount := powerUserWorkspaceCount / powerUserWorkspaces |
| 1203 | regularWorkspaceCount := workspaceCount - powerUserWorkspaceCount |
| 1204 | regularUserCount := regularWorkspaceCount |
| 1205 | regularUserWorkspaceCount := 1 |
no test coverage detected