Skip to content

Commit 2062062

Browse files
committed
grpc-js: Add outlier detection LB policy
1 parent 4b3c263 commit 2062062

File tree

8 files changed

+733
-7
lines changed

8 files changed

+733
-7
lines changed

packages/grpc-js/gulpfile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const compile = checkTask(() => execNpmCommand('compile'));
6767
const copyTestFixtures = checkTask(() => ncpP(`${jsCoreDir}/test/fixtures`, `${outDir}/test/fixtures`));
6868

6969
const runTests = checkTask(() => {
70+
process.env.GRPC_EXPERIMENTAL_ENABLE_OUTLIER_DETECTION = 'true';
7071
return gulp.src(`${outDir}/test/**/*.js`)
7172
.pipe(mocha({reporter: 'mocha-jenkins-reporter',
7273
require: ['ts-node/register']}));

packages/grpc-js/src/duration.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2022 gRPC authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
export interface Duration {
19+
seconds: number;
20+
nanos: number;
21+
}
22+
23+
export function msToDuration(millis: number): Duration {
24+
return {
25+
seconds: (millis / 1000) | 0,
26+
nanos: (millis % 1000) * 1_000_000 | 0
27+
};
28+
}
29+
30+
export function durationToMs(duration: Duration): number {
31+
return (duration.seconds * 1000 + duration.nanos / 1_000_000) | 0;
32+
}
33+
34+
export function isDuration(value: any): value is Duration {
35+
return (typeof value.seconds === 'number') && (typeof value.nanos === 'number');
36+
}

packages/grpc-js/src/experimental.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export {
66
ConfigSelector,
77
} from './resolver';
88
export { GrpcUri, uriToString } from './uri-parser';
9-
export { ServiceConfig, Duration } from './service-config';
9+
export { Duration } from './duration';
10+
export { ServiceConfig } from './service-config';
1011
export { BackoffTimeout } from './backoff-timeout';
1112
export {
1213
LoadBalancer,

packages/grpc-js/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ import * as resolver_uds from './resolver-uds';
273273
import * as resolver_ip from './resolver-ip';
274274
import * as load_balancer_pick_first from './load-balancer-pick-first';
275275
import * as load_balancer_round_robin from './load-balancer-round-robin';
276+
import * as load_balancer_outlier_detection from './load-balancer-outlier-detection';
276277
import * as channelz from './channelz';
277278

278279
const clientVersion = require('../../package.json').version;
@@ -284,5 +285,6 @@ const clientVersion = require('../../package.json').version;
284285
resolver_ip.setup();
285286
load_balancer_pick_first.setup();
286287
load_balancer_round_robin.setup();
288+
load_balancer_outlier_detection.setup();
287289
channelz.setup();
288290
})();

0 commit comments

Comments
 (0)