import sleep from 'sleep-promise' ; import { LoadTestArgv } from 'src/cmds/deploy/initial/load-test' ; import { getBlockscoutUrl } from 'src/lib/endpoints' ; import { envVar , fetchEnv } from 'src/lib/env-utils' ; import { getEnodesWithExternalIPAddresses } from 'src/lib/geth' ; import { installGenericHelmChart , removeGenericHelmChart , saveHelmValuesFile , upgradeGenericHelmChart , } from 'src/lib/helm_deploy' ; import { scaleResource } from 'src/lib/kubernetes' ; const chartDir = '../helm-charts/load-test/' ; function releaseName ( celoEnv ) { return `${ celoEnv }-load-test` ; } export async function installHelmChart ( celoEnv , blockscoutProb , delayMs , replicas , threads ) { const params = await helmParameters ( celoEnv , blockscoutProb , delayMs , replicas , threads ) ; return installGenericHelmChart ( celoEnv , releaseName ( celoEnv ) , chartDir , params ) ; } export async function upgradeHelmChart ( celoEnv , blockscoutProb , delayMs , replicas , threads ) { const params = await helmParameters ( celoEnv , blockscoutProb , delayMs , replicas , threads ) ; await upgradeGenericHelmChart ( celoEnv , releaseName ( celoEnv ) , chartDir , params ) ; } export async function resetAndUpgrade ( celoEnv , blockscoutProb , delayMs , replicas , threads ) { const loadTestStatefulSetName = `${ celoEnv }-load-test` ; console . info ( 'Scaling load-test StatefulSet down to 0...' ) ; await scaleResource ( celoEnv , 'StatefulSet' , loadTestStatefulSetName , 0 ) ; await sleep ( 3000 ) ; await upgradeHelmChart ( celoEnv , blockscoutProb , delayMs , replicas , threads ) ; await sleep ( 3000 ) ; console . info ( `Scaling load-test StatefulSet back up to ${ replicas }...` ) ; await scaleResource ( celoEnv , 'StatefulSet' , loadTestStatefulSetName , replicas ) ; } export function setArgvDefaults ( argv ) { if ( argv . delay < 0 ) { argv . delay = parseInt ( fetchEnv ( envVar . LOAD_TEST_TX_DELAY_MS ) , 10 ) ; } if ( argv . replicas < 0 ) { argv . replicas = parseInt ( fetchEnv ( envVar . LOAD_TEST_CLIENTS ) , 10 ) ; } if ( argv . threads < 0 ) { argv . replicas = parseInt ( fetchEnv ( envVar . LOAD_TEST_THREADS ) , 1 ) ; } } export async function removeHelmRelease ( celoEnv ) { return removeGenericHelmChart ( `${ celoEnv }-load-test` , celoEnv ) ; } async function helmParameters ( celoEnv , blockscoutProb , delayMs , replicas , threads ) { const enodes = await getEnodesWithExternalIPAddresses ( celoEnv ) ; const staticNodesJsonB64 = Buffer . from ( JSON . stringify ( enodes ) ) . toString ( 'base64' ) ; const valueFilePath = `/tmp/${ celoEnv }-testnet-values.yaml` ; await saveHelmValuesFile ( celoEnv , valueFilePath , true , true ) ; return [ `-f ${ valueFilePath }` , `--set geth.accountSecret="${ fetchEnv ( envVar . GETH_ACCOUNT_SECRET ) }"` , `--set blockscout.measurePercent=${ blockscoutProb }` , `--set blockscout.url=${ getBlockscoutUrl ( celoEnv ) }` , `--set celotool.image.repository=${ fetchEnv ( envVar . CELOTOOL_DOCKER_IMAGE_REPOSITORY ) }` , `--set celotool.image.tag=${ fetchEnv ( envVar . CELOTOOL_DOCKER_IMAGE_TAG ) }` , `--set delay=${ delayMs }` , `--set environment=${ celoEnv }` , `--set geth.image.repository=${ fetchEnv ( envVar . GETH_NODE_DOCKER_IMAGE_REPOSITORY ) }` , `--set geth.image.tag=${ fetchEnv ( envVar . GETH_NODE_DOCKER_IMAGE_TAG ) }` , `--set geth.networkID=${ fetchEnv ( envVar . NETWORK_ID ) }` , `--set geth.staticNodes="${ staticNodesJsonB64 }"` , `--set geth.verbosity=${ fetchEnv ( 'GETH_VERBOSITY' ) }` , `--set mnemonic="${ fetchEnv ( envVar . MNEMONIC ) }"` , `--set replicas=${ replicas }` , `--set threads=${ threads }` , `--set genesis.useGenesisFileBase64=false` , `--set genesis.network=${ celoEnv }` , `--set use_random_recipient=${ fetchEnv ( envVar . LOAD_TEST_USE_RANDOM_RECIPIENT ) }` , `--set reuse_light_clients=true` , ] ; }