From 62bd1cab6875d1127268db46d75092ffdbc59090 Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Mon, 31 Aug 2020 09:55:29 -0700 Subject: [PATCH] Add granular verbosity option to xDS interop client --- .../grpc-js/interop/xds-interop-client.ts | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/grpc-js/interop/xds-interop-client.ts b/packages/grpc-js/interop/xds-interop-client.ts index 949da238..3009541c 100644 --- a/packages/grpc-js/interop/xds-interop-client.ts +++ b/packages/grpc-js/interop/xds-interop-client.ts @@ -39,6 +39,8 @@ const loadedProto = grpc.loadPackageDefinition(packageDefinition) as unknown as const REQUEST_TIMEOUT_SEC = 20; +const VERBOSITY = Number.parseInt(process.env.NODE_XDS_INTEROP_VERBOSITY ?? '0'); + interface CallEndNotifier { onCallSucceeded(peerName: string): void; onCallFailed(message: string): void; @@ -54,7 +56,9 @@ class CallSubscriber { constructor(private callGoal: number, private onFinished: () => void) {} addCallStarted(): void { - console.log('Call started'); + if (VERBOSITY >= 2) { + console.log('Call started'); + } this.callsStarted += 1; } @@ -65,7 +69,9 @@ class CallSubscriber { } addCallSucceeded(peerName: string): void { - console.log(`Call to ${peerName} succeeded`); + if (VERBOSITY >= 2) { + console.log(`Call to ${peerName} succeeded`); + } if (peerName in this.callsSucceededByPeer) { this.callsSucceededByPeer[peerName] += 1; } else { @@ -76,7 +82,9 @@ class CallSubscriber { this.maybeOnFinished(); } addCallFailed(message: string): void { - console.log(`Call failed with message ${message}`); + if (VERBOSITY >= 2) { + console.log(`Call failed with message ${message}`); + } this.callsFinished += 1; this.failureMessageCount.set(message, (this.failureMessageCount.get(message) ?? 0) + 1); this.maybeOnFinished(); @@ -87,9 +95,11 @@ class CallSubscriber { } getFinalStats(): LoadBalancerStatsResponse { - console.log(`Out of a total of ${this.callGoal} calls requested, ${this.callsFinished} finished. ${this.callsSucceeded} succeeded`); - for (const [message, count] of this.failureMessageCount) { - console.log(`${count} failed with the message ${message}`); + if (VERBOSITY >= 1) { + console.log(`Out of a total of ${this.callGoal} calls requested, ${this.callsFinished} finished. ${this.callsSucceeded} succeeded`); + for (const [message, count] of this.failureMessageCount) { + console.log(`${count} failed with the message ${message}`); + } } return { rpcs_by_peer: this.callsSucceededByPeer,