grpc-js: Disallow pick_first as child of outlier_detection

This commit is contained in:
Michael Lumish 2023-06-22 14:26:31 -07:00
parent 09d74ca43d
commit b53f5882f1
4 changed files with 21 additions and 8 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@grpc/grpc-js", "name": "@grpc/grpc-js",
"version": "1.8.16", "version": "1.8.17",
"description": "gRPC Library for Node - pure JS implementation", "description": "gRPC Library for Node - pure JS implementation",
"homepage": "https://grpc.io/", "homepage": "https://grpc.io/",
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js", "repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",

View File

@ -113,6 +113,9 @@ export class OutlierDetectionLoadBalancingConfig implements LoadBalancingConfig
failurePercentageEjection: Partial<FailurePercentageEjectionConfig> | null, failurePercentageEjection: Partial<FailurePercentageEjectionConfig> | null,
private readonly childPolicy: LoadBalancingConfig[] private readonly childPolicy: LoadBalancingConfig[]
) { ) {
if (childPolicy[0].getLoadBalancerName() === 'pick_first') {
throw new Error('outlier_detection LB policy cannot have a pick_first child policy');
}
this.intervalMs = intervalMs ?? 10_000; this.intervalMs = intervalMs ?? 10_000;
this.baseEjectionTimeMs = baseEjectionTimeMs ?? 30_000; this.baseEjectionTimeMs = baseEjectionTimeMs ?? 30_000;
this.maxEjectionTimeMs = maxEjectionTimeMs ?? 300_000; this.maxEjectionTimeMs = maxEjectionTimeMs ?? 300_000;

View File

@ -276,7 +276,7 @@ class DnsResolver implements Resolver {
} catch (err) { } catch (err) {
this.latestServiceConfigError = { this.latestServiceConfigError = {
code: Status.UNAVAILABLE, code: Status.UNAVAILABLE,
details: 'Parsing service config failed', details: `Parsing service config failed with error ${(err as Error).message}`,
metadata: new Metadata(), metadata: new Metadata(),
}; };
} }

View File

@ -360,6 +360,16 @@ describe('Outlier detection config validation', () => {
}, /failure_percentage_ejection\.enforcement_percentage parse error: value out of range for percentage/); }, /failure_percentage_ejection\.enforcement_percentage parse error: value out of range for percentage/);
}); });
}); });
describe('child_policy', () => {
it('Should reject a pick_first child_policy', () => {
const loadBalancingConfig = {
child_policy: [{pick_first: {}}]
};
assert.throws(() => {
OutlierDetectionLoadBalancingConfig.createFromJson(loadBalancingConfig);
}, /outlier_detection LB policy cannot have a pick_first child policy/);
});
});
}); });
describe('Outlier detection', () => { describe('Outlier detection', () => {