Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soloseng/fix-test-quota-bypass #10471

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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