Skip to content

Commit

Permalink
Soloseng/fix-test-quota-bypass (#10471)
Browse files Browse the repository at this point in the history
* enable optional quota bypass during load test.

* moved log to better track failed signers

* increase the range test sessionID
  • Loading branch information
soloseng authored Aug 7, 2023
1 parent 2077c41 commit 49e8044
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 17 deletions.
6 changes: 3 additions & 3 deletions packages/phone-number-privacy/combiner/src/common/combine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ export abstract class CombineAction<R extends OdisRequest> implements Action<R>
}

private addFailureToSession(signer: Signer, errorCode: number | undefined, session: Session<R>) {
session.logger.warn(
`Received failure from ${session.failedSigners.size}/${this.signers.length} signers`
)
// Tracking failed request count via signer url prevents
// double counting the same failed request by mistake
session.failedSigners.add(signer.url)
session.logger.warn(
`Received failure from ${session.failedSigners.size}/${this.signers.length} signers`
)
if (errorCode) {
session.incrementErrorCodeCount(errorCode)
}
Expand Down
6 changes: 4 additions & 2 deletions packages/phone-number-privacy/monitor/src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const newPrivateKey = async () => {
export const queryOdisForSalt = async (
blockchainProvider: string,
contextName: OdisContextName,
timeoutMs: number = 10000
timeoutMs: number = 10000,
bypassQuota: boolean = false
) => {
console.log(`contextName: ${contextName}`) // tslint:disable-line:no-console
console.log(`blockchain provider: ${blockchainProvider}`) // tslint:disable-line:no-console
Expand All @@ -52,6 +53,7 @@ export const queryOdisForSalt = async (
console.log(`ODIS salt request timed out after ${timeoutMs} ms`) // tslint:disable-line:no-console
}, timeoutMs)
try {
const testSessionId = Math.floor(Math.random() * 100000).toString()
const res = await OdisUtils.Identifier.getObfuscatedIdentifier(
phoneNumber,
OdisUtils.Identifier.IdentifierPrefix.PHONE_NUMBER,
Expand All @@ -61,7 +63,7 @@ export const queryOdisForSalt = async (
undefined,
undefined,
undefined,
genSessionID(),
bypassQuota ? testSessionId : genSessionID(),
undefined,
abortController
)
Expand Down
58 changes: 52 additions & 6 deletions packages/phone-number-privacy/monitor/src/scripts/run-load-test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { OdisContextName } from '@celo/identity/lib/odis/query'
import { CombinerEndpointPNP } from '@celo/phone-number-privacy-common'
import yargs from 'yargs'
import { concurrentLoadTest, serialLoadTest } from '../test'

/* tslint:disable:no-console */

const runLoadTest = (contextName: string, numWorker: number, isSerial: boolean) => {
const runLoadTest = (
contextName: string,
numWorker: number,
isSerial: boolean,
pnpQuotaEndpoint: boolean,
timeoutMs: number,
bypassQuota: boolean
) => {
let blockchainProvider: string
switch (contextName) {
case 'alfajoresstaging':
Expand All @@ -25,12 +33,26 @@ const runLoadTest = (contextName: string, numWorker: number, isSerial: boolean)
process.exit(1)
}
if (isSerial) {
serialLoadTest(numWorker, blockchainProvider!, contextName as OdisContextName) // tslint:disable-line:no-floating-promises
serialLoadTest(
numWorker,
blockchainProvider!,
contextName as OdisContextName,
pnpQuotaEndpoint ? CombinerEndpointPNP.PNP_QUOTA : CombinerEndpointPNP.PNP_SIGN,
timeoutMs,
bypassQuota
)
} else {
concurrentLoadTest(numWorker, blockchainProvider!, contextName as OdisContextName) // tslint:disable-line:no-floating-promises
concurrentLoadTest(
numWorker,
blockchainProvider!,
contextName as OdisContextName,
pnpQuotaEndpoint ? CombinerEndpointPNP.PNP_QUOTA : CombinerEndpointPNP.PNP_SIGN,
timeoutMs,
bypassQuota
)
}
}
// tslint:disable-next-line: no-unused-expression

yargs
.scriptName('ODIS-load-test')
.recommendCommands()
Expand All @@ -52,8 +74,32 @@ yargs
})
.option('isSerial', {
type: 'boolean',
description: 'run test workers in series.',
description: 'Run test workers in series.',
default: false,
})
.option('timeoutMs', {
type: 'number',
description: 'Timout in ms.',
default: 10000,
})
.option('bypassQuota', {
type: 'boolean',
description: 'Bypass Signer quota check.',
default: false,
})
.option('pnpQuotaEndpoint', {
type: 'boolean',
description:
'Use this flag to load test PNP_QUOTA endpoint instead of PNP_SIGN endpoint.',
default: false,
}),
(args) => runLoadTest(args.contextName!, args.numWorkers!, args.isSerial)
(args) =>
runLoadTest(
args.contextName!,
args.numWorkers!,
args.isSerial,
args.pnpQuotaEndpoint,
args.timeoutMs,
args.bypassQuota
)
).argv
22 changes: 16 additions & 6 deletions packages/phone-number-privacy/monitor/src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ export async function testPNPSignQuery(
blockchainProvider: string,
contextName: OdisContextName,
endpoint: CombinerEndpointPNP.PNP_SIGN,
timeoutMs?: number
timeoutMs?: number,
bypassQuota?: boolean
) {
logger.info(`Performing test PNP query for ${endpoint}`)
try {
const odisResponse: IdentifierHashDetails = await queryOdisForSalt(
blockchainProvider,
contextName,
timeoutMs
timeoutMs,
bypassQuota
)
logger.info({ odisResponse }, 'ODIS salt request successful. System is healthy.')
} catch (err) {
Expand Down Expand Up @@ -82,13 +84,14 @@ export async function serialLoadTest(
endpoint:
| CombinerEndpointPNP.PNP_QUOTA
| CombinerEndpointPNP.PNP_SIGN = CombinerEndpointPNP.PNP_SIGN,
timeoutMs?: number
timeoutMs?: number,
bypassQuota?: boolean
) {
for (let i = 0; i < n; i++) {
try {
switch (endpoint) {
case CombinerEndpointPNP.PNP_SIGN:
await testPNPSignQuery(blockchainProvider, contextName, endpoint, timeoutMs)
await testPNPSignQuery(blockchainProvider, contextName, endpoint, timeoutMs, bypassQuota)
break
case CombinerEndpointPNP.PNP_QUOTA:
await testPNPQuotaQuery(blockchainProvider, contextName, timeoutMs)
Expand All @@ -104,7 +107,8 @@ export async function concurrentLoadTest(
endpoint:
| CombinerEndpointPNP.PNP_QUOTA
| CombinerEndpointPNP.PNP_SIGN = CombinerEndpointPNP.PNP_SIGN,
timeoutMs?: number
timeoutMs?: number,
bypassQuota?: boolean
) {
while (true) {
const reqs = []
Expand All @@ -117,7 +121,13 @@ export async function concurrentLoadTest(
try {
switch (endpoint) {
case CombinerEndpointPNP.PNP_SIGN:
await testPNPSignQuery(blockchainProvider, contextName, endpoint, timeoutMs)
await testPNPSignQuery(
blockchainProvider,
contextName,
endpoint,
timeoutMs,
bypassQuota
)
break
case CombinerEndpointPNP.PNP_QUOTA:
await testPNPQuotaQuery(blockchainProvider, contextName, timeoutMs)
Expand Down

0 comments on commit 49e8044

Please sign in to comment.