Add granular verbosity option to xDS interop client

This commit is contained in:
Michael Lumish 2020-08-31 09:55:29 -07:00
parent 36db24e39f
commit 62bd1cab68
1 changed files with 16 additions and 6 deletions

View File

@ -39,6 +39,8 @@ const loadedProto = grpc.loadPackageDefinition(packageDefinition) as unknown as
const REQUEST_TIMEOUT_SEC = 20; const REQUEST_TIMEOUT_SEC = 20;
const VERBOSITY = Number.parseInt(process.env.NODE_XDS_INTEROP_VERBOSITY ?? '0');
interface CallEndNotifier { interface CallEndNotifier {
onCallSucceeded(peerName: string): void; onCallSucceeded(peerName: string): void;
onCallFailed(message: string): void; onCallFailed(message: string): void;
@ -54,7 +56,9 @@ class CallSubscriber {
constructor(private callGoal: number, private onFinished: () => void) {} constructor(private callGoal: number, private onFinished: () => void) {}
addCallStarted(): void { addCallStarted(): void {
console.log('Call started'); if (VERBOSITY >= 2) {
console.log('Call started');
}
this.callsStarted += 1; this.callsStarted += 1;
} }
@ -65,7 +69,9 @@ class CallSubscriber {
} }
addCallSucceeded(peerName: string): void { addCallSucceeded(peerName: string): void {
console.log(`Call to ${peerName} succeeded`); if (VERBOSITY >= 2) {
console.log(`Call to ${peerName} succeeded`);
}
if (peerName in this.callsSucceededByPeer) { if (peerName in this.callsSucceededByPeer) {
this.callsSucceededByPeer[peerName] += 1; this.callsSucceededByPeer[peerName] += 1;
} else { } else {
@ -76,7 +82,9 @@ class CallSubscriber {
this.maybeOnFinished(); this.maybeOnFinished();
} }
addCallFailed(message: string): void { 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.callsFinished += 1;
this.failureMessageCount.set(message, (this.failureMessageCount.get(message) ?? 0) + 1); this.failureMessageCount.set(message, (this.failureMessageCount.get(message) ?? 0) + 1);
this.maybeOnFinished(); this.maybeOnFinished();
@ -87,9 +95,11 @@ class CallSubscriber {
} }
getFinalStats(): LoadBalancerStatsResponse { getFinalStats(): LoadBalancerStatsResponse {
console.log(`Out of a total of ${this.callGoal} calls requested, ${this.callsFinished} finished. ${this.callsSucceeded} succeeded`); if (VERBOSITY >= 1) {
for (const [message, count] of this.failureMessageCount) { console.log(`Out of a total of ${this.callGoal} calls requested, ${this.callsFinished} finished. ${this.callsSucceeded} succeeded`);
console.log(`${count} failed with the message ${message}`); for (const [message, count] of this.failureMessageCount) {
console.log(`${count} failed with the message ${message}`);
}
} }
return { return {
rpcs_by_peer: this.callsSucceededByPeer, rpcs_by_peer: this.callsSucceededByPeer,