Skip to content

Commit 1aaa3fd

Browse files
authored
Merge pull request #2998 from murgatroid99/grpc-js_client_weighted_round_robin
grpc-js: Implement weighted_round_robin LB policy
2 parents 6573a0e + 2f74b88 commit 1aaa3fd

13 files changed

+1390
-33
lines changed

packages/grpc-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"pretest": "npm run generate-types && npm run generate-test-types && npm run compile",
6565
"posttest": "npm run check && madge -c ./build/src",
6666
"generate-types": "proto-loader-gen-types --keepCase --longs String --enums String --defaults --oneofs --includeComments --includeDirs proto/ --include-dirs proto/ proto/xds/ proto/protoc-gen-validate/ -O src/generated/ --grpcLib ../index channelz.proto xds/service/orca/v3/orca.proto",
67-
"generate-test-types": "proto-loader-gen-types --keepCase --longs String --enums String --defaults --oneofs --includeComments --include-dirs test/fixtures/ -O test/generated/ --grpcLib ../../src/index test_service.proto",
67+
"generate-test-types": "proto-loader-gen-types --keepCase --longs String --enums String --defaults --oneofs --includeComments --include-dirs test/fixtures/ -O test/generated/ --grpcLib ../../src/index test_service.proto echo_service.proto",
6868
"copy-protos": "node ./copy-protos"
6969
},
7070
"dependencies": {

packages/grpc-js/src/duration.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,18 @@ export function parseDuration(value: string): Duration | null {
5858
nanos: match[2] ? Number.parseInt(match[2].padEnd(9, '0'), 10) : 0
5959
};
6060
}
61+
62+
export function durationToString(duration: Duration): string {
63+
if (duration.nanos === 0) {
64+
return `${duration.seconds}s`;
65+
}
66+
let scaleFactor: number;
67+
if (duration.nanos % 1_000_000 === 0) {
68+
scaleFactor = 1_000_000;
69+
} else if (duration.nanos % 1_000 === 0) {
70+
scaleFactor = 1_000;
71+
} else {
72+
scaleFactor = 1;
73+
}
74+
return `${duration.seconds}.${duration.nanos/scaleFactor}s`;
75+
}

packages/grpc-js/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ import * as resolver_ip from './resolver-ip';
296296
import * as load_balancer_pick_first from './load-balancer-pick-first';
297297
import * as load_balancer_round_robin from './load-balancer-round-robin';
298298
import * as load_balancer_outlier_detection from './load-balancer-outlier-detection';
299+
import * as load_balancer_weighted_round_robin from './load-balancer-weighted-round-robin';
299300
import * as channelz from './channelz';
300301
import { Deadline } from './deadline';
301302

@@ -306,5 +307,6 @@ import { Deadline } from './deadline';
306307
load_balancer_pick_first.setup();
307308
load_balancer_round_robin.setup();
308309
load_balancer_outlier_detection.setup();
310+
load_balancer_weighted_round_robin.setup();
309311
channelz.setup();
310312
})();

packages/grpc-js/src/load-balancer-pick-first.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,11 @@ export class PickFirstLoadBalancer implements LoadBalancer {
588588
destroy() {
589589
this.resetSubchannelList();
590590
this.removeCurrentPick();
591+
this.metricsCall?.cancel();
592+
this.metricsCall = null;
593+
this.orcaClient?.close();
594+
this.orcaClient = null;
595+
this.metricsBackoffTimer.stop();
591596
}
592597

593598
getTypeName(): string {

0 commit comments

Comments
 (0)