# scaler - scale test tool

The tool is used for scale test.

# Usage

## Prerequisit

To use the tool, you need to prepare the infra-api kubeconfig file, and you also need to create an openapi key pair for access.
To generate openapi key pair, nevigate to "Organization settings" and then "API Keys" tab to generate new API keys.

## Flags

1. `-autoclean`: automatically cleanup test clusters, default to `true`. If set to `false`, the clusters will be left after the test.
2. `-host`: TiDB cloud openapi host, default to `https://api.dev.tidbcloud.com`.
3. `-kubeconfigpath`: path to the infra-api kubeconfig file.
4. `-paral`: number of TiDB clusters creating in parallel, default to `5`.
5. `-privkey`: TiDB cloud openapi private key.
6. `pubkey`: TiDB cloud openapi public key.
7. `-project`: project id, default to `223467`.
8. `-session`: test session name, in format `session-<timestamp>`. No need to set session by default, but if the test is interrupted and you want to resume from previous session, you can specify the session to continue provided that you have kept the `<session-name>.json` file which keeps track of the test progress.
9. `-skipcreate`: skip cluster creation, default to `false`. If set to `true`, the tool will only cleanup the clusters created in previous session.
10. `-total`: number of total clusters to be created, default to `100`.

## Example

A typical test run of the command and the outputs could be:
```console
➜  scaler -kubeconfigpath=$(pwd)/infra.config -pubkey <public-key> -privkey <private-key> -paral 10 -total 10
Test session: session-2023-04-10-22-39-22-3a6aa7d3
created cluster 3028968, time: 2023-04-10 22:39:24.995379525 +0000 UTC m=+2.481847966
created cluster 3028969, time: 2023-04-10 22:39:26.347916716 +0000 UTC m=+3.834385174
created cluster 3028970, time: 2023-04-10 22:39:27.886735162 +0000 UTC m=+5.373212718
created cluster 3028971, time: 2023-04-10 22:39:29.270877092 +0000 UTC m=+6.757345614
created cluster 3028972, time: 2023-04-10 22:39:30.676804099 +0000 UTC m=+8.163272571
created cluster 3028973, time: 2023-04-10 22:39:31.858774518 +0000 UTC m=+9.345242952
created cluster 3028974, time: 2023-04-10 22:39:32.668786957 +0000 UTC m=+10.155255393
created cluster 3028975, time: 2023-04-10 22:39:33.547599218 +0000 UTC m=+11.034067637
created cluster 3028976, time: 2023-04-10 22:39:34.536388349 +0000 UTC m=+12.022856770
created cluster 3028977, time: 2023-04-10 22:39:36.045920152 +0000 UTC m=+13.532388583
===
  completed creation for 10 clusters with parallism 10
  written cluster info to: session-2023-04-10-22-39-22-3a6aa7d3.csv
deleted cluster 3028977, time: 2023-04-10 22:53:56.76882002 +0000 UTC m=+874.255288601
deleted cluster 3028976, time: 2023-04-10 22:53:57.752312633 +0000 UTC m=+875.238780991
deleted cluster 3028974, time: 2023-04-10 22:53:58.479285176 +0000 UTC m=+875.965753534
deleted cluster 3028975, time: 2023-04-10 22:53:59.163615312 +0000 UTC m=+876.650083675
deleted cluster 3028973, time: 2023-04-10 22:53:59.887229899 +0000 UTC m=+877.373698258
deleted cluster 3028972, time: 2023-04-10 22:54:00.980123047 +0000 UTC m=+878.466591411
deleted cluster 3028971, time: 2023-04-10 22:54:01.604741171 +0000 UTC m=+879.091209543
deleted cluster 3028970, time: 2023-04-10 22:54:02.121089552 +0000 UTC m=+879.607557929
deleted cluster 3028969, time: 2023-04-10 22:54:02.988864339 +0000 UTC m=+880.475332706
deleted cluster 3028968, time: 2023-04-10 22:54:03.965193809 +0000 UTC m=+881.451662173
test duration: 14m41.11107324s
➜  cat session-2023-04-10-22-39-22-3a6aa7d3.csv 
id,All,CMEKStorageClass,Cert,DNS,FullService,Guardian,Issuer,MTLS,Namespace,O11yCluster,SGP,Secret,Service,ServiceSG,TiDBCluster,TiDBInitializer,TiDBMonitor,pv
3028968,518.321829,23.103332,150.398027,23.100811,30.497020,10.369357,26.618186,26.808460,23.101549,150.412226,23.998887,26.808064,56.348381,23.864692,518.307565,36.406694,211.241058,26.809009
3028969,667.902813,26.858657,174.810065,26.857531,34.711365,18.502647,30.623998,30.631363,26.857772,174.822895,27.609871,30.630996,114.718246,27.397375,667.814757,34.517381,236.203288,30.632056
3028970,640.747972,24.958205,212.508979,24.955943,31.697551,11.199999,27.821398,27.830647,24.956217,151.427938,25.812551,27.830270,34.008263,25.737192,640.734499,34.000779,212.512190,27.831262
3028971,588.848374,19.509592,99.398003,7.113300,23.345220,6.920356,23.218807,23.227321,7.124212,160.345169,21.392732,23.226804,29.097064,21.323133,588.833676,29.026059,160.333501,23.323136
3028972,506.629800,7.165381,58.119531,6.881020,12.083969,6.658466,10.583458,10.695235,7.001346,76.624232,8.763164,10.695013,17.423746,8.564022,506.514196,11.947412,58.126606,10.695392
3028973,642.556997,24.404837,151.600879,24.401983,32.925391,11.028101,27.736718,27.997683,24.402663,151.709883,25.502188,27.997065,35.904450,25.397786,642.540427,35.826277,212.724472,27.998947
3028974,532.950865,15.408208,105.042767,15.406868,18.373794,10.409018,17.333577,17.339388,15.407105,105.055755,16.206955,17.339211,22.334295,16.071613,532.935593,18.349952,105.043687,17.339620
3028975,636.114391,20.255923,207.533854,20.254582,26.621506,6.137704,23.034870,23.098285,20.254828,146.633415,21.113443,23.097767,29.021004,20.990949,636.014536,29.014243,268.709739,23.099149
3028976,639.939631,22.310382,88.997854,10.893434,27.439625,10.708500,25.530478,25.535801,10.901710,150.155526,23.718426,25.535732,37.935478,23.596823,639.925843,27.411448,150.143735,25.535888
3028977,523.427055,16.889620,94.227968,16.888107,19.736559,6.588315,18.728388,18.735469,16.888383,155.539084,17.485207,18.735261,23.313328,17.408533,523.413145,19.711028,155.527327,18.735726
```

The command will generate a CSV file that records duration for each task for each cluster.