Skip to content

Commit 00e1ac4

Browse files
committed
grpc-js: Pass channel options to LoadBalancer constructors
1 parent 092d1e9 commit 00e1ac4

16 files changed

+110
-78
lines changed

packages/grpc-js-xds/interop/xds-interop-client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const RPC_BEHAVIOR_CHILD_CONFIG = parseLoadBalancingConfig({round_robin: {}});
8888
class RpcBehaviorLoadBalancer implements LoadBalancer {
8989
private child: ChildLoadBalancerHandler;
9090
private latestConfig: RpcBehaviorLoadBalancingConfig | null = null;
91-
constructor(channelControlHelper: ChannelControlHelper) {
91+
constructor(channelControlHelper: ChannelControlHelper, options: grpc.ChannelOptions) {
9292
const childChannelControlHelper = createChildChannelControlHelper(channelControlHelper, {
9393
updateState: (connectivityState, picker) => {
9494
if (connectivityState === grpc.connectivityState.READY && this.latestConfig) {
@@ -97,7 +97,7 @@ class RpcBehaviorLoadBalancer implements LoadBalancer {
9797
channelControlHelper.updateState(connectivityState, picker);
9898
}
9999
});
100-
this.child = new ChildLoadBalancerHandler(childChannelControlHelper);
100+
this.child = new ChildLoadBalancerHandler(childChannelControlHelper, options);
101101
}
102102
updateAddressList(endpointList: Endpoint[], lbConfig: TypedLoadBalancingConfig, attributes: { [key: string]: unknown; }): void {
103103
if (!(lbConfig instanceof RpcBehaviorLoadBalancingConfig)) {

packages/grpc-js-xds/src/load-balancer-cds.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*/
1717

18-
import { connectivityState, status, Metadata, logVerbosity, experimental, LoadBalancingConfig } from '@grpc/grpc-js';
18+
import { connectivityState, status, Metadata, logVerbosity, experimental, LoadBalancingConfig, ChannelOptions } from '@grpc/grpc-js';
1919
import { getSingletonXdsClient, Watcher, XdsClient } from './xds-client';
2020
import { Cluster__Output } from './generated/envoy/config/cluster/v3/Cluster';
2121
import Endpoint = experimental.Endpoint;
@@ -155,8 +155,8 @@ export class CdsLoadBalancer implements LoadBalancer {
155155

156156
private updatedChild = false;
157157

158-
constructor(private readonly channelControlHelper: ChannelControlHelper) {
159-
this.childBalancer = new XdsClusterResolverChildPolicyHandler(channelControlHelper);
158+
constructor(private readonly channelControlHelper: ChannelControlHelper, options: ChannelOptions) {
159+
this.childBalancer = new XdsClusterResolverChildPolicyHandler(channelControlHelper, options);
160160
}
161161

162162
private reportError(errorMessage: string) {

packages/grpc-js-xds/src/load-balancer-priority.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*/
1717

18-
import { connectivityState as ConnectivityState, status as Status, Metadata, logVerbosity as LogVerbosity, experimental, LoadBalancingConfig } from '@grpc/grpc-js';
18+
import { connectivityState as ConnectivityState, status as Status, Metadata, logVerbosity as LogVerbosity, experimental, LoadBalancingConfig, ChannelOptions } from '@grpc/grpc-js';
1919
import LoadBalancer = experimental.LoadBalancer;
2020
import ChannelControlHelper = experimental.ChannelControlHelper;
2121
import registerLoadBalancerType = experimental.registerLoadBalancerType;
@@ -180,7 +180,7 @@ export class PriorityLoadBalancer implements LoadBalancer {
180180
this.parent.channelControlHelper.requestReresolution();
181181
}
182182
}
183-
}));
183+
}), parent.options);
184184
this.picker = new QueuePicker(this.childBalancer);
185185
this.startFailoverTimer();
186186
}
@@ -306,7 +306,7 @@ export class PriorityLoadBalancer implements LoadBalancer {
306306

307307
private updatesPaused = false;
308308

309-
constructor(private channelControlHelper: ChannelControlHelper) {}
309+
constructor(private channelControlHelper: ChannelControlHelper, private options: ChannelOptions) {}
310310

311311
private updateState(state: ConnectivityState, picker: Picker) {
312312
trace(

packages/grpc-js-xds/src/load-balancer-weighted-target.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*/
1717

18-
import { connectivityState as ConnectivityState, status as Status, Metadata, logVerbosity, experimental, LoadBalancingConfig } from "@grpc/grpc-js";
18+
import { connectivityState as ConnectivityState, status as Status, Metadata, logVerbosity, experimental, LoadBalancingConfig, ChannelOptions } from "@grpc/grpc-js";
1919
import { isLocalityEndpoint, LocalityEndpoint } from "./load-balancer-priority";
2020
import TypedLoadBalancingConfig = experimental.TypedLoadBalancingConfig;
2121
import LoadBalancer = experimental.LoadBalancer;
@@ -178,7 +178,7 @@ export class WeightedTargetLoadBalancer implements LoadBalancer {
178178
updateState: (connectivityState: ConnectivityState, picker: Picker) => {
179179
this.updateState(connectivityState, picker);
180180
},
181-
}));
181+
}), parent.options);
182182

183183
this.picker = new QueuePicker(this.childBalancer);
184184
}
@@ -243,7 +243,7 @@ export class WeightedTargetLoadBalancer implements LoadBalancer {
243243
private targetList: string[] = [];
244244
private updatesPaused = false;
245245

246-
constructor(private channelControlHelper: ChannelControlHelper) {}
246+
constructor(private channelControlHelper: ChannelControlHelper, private options: ChannelOptions) {}
247247

248248
private maybeUpdateState() {
249249
if (!this.updatesPaused) {

packages/grpc-js-xds/src/load-balancer-xds-cluster-impl.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*/
1717

18-
import { experimental, logVerbosity, status as Status, Metadata, connectivityState } from "@grpc/grpc-js";
18+
import { experimental, logVerbosity, status as Status, Metadata, connectivityState, ChannelOptions } from "@grpc/grpc-js";
1919
import { validateXdsServerConfig, XdsServerConfig } from "./xds-bootstrap";
2020
import { getSingletonXdsClient, XdsClient, XdsClusterDropStats, XdsClusterLocalityStats } from "./xds-client";
2121
import { LocalityEndpoint } from "./load-balancer-priority";
@@ -253,7 +253,7 @@ class XdsClusterImplBalancer implements LoadBalancer {
253253
private clusterDropStats: XdsClusterDropStats | null = null;
254254
private xdsClient: XdsClient | null = null;
255255

256-
constructor(private readonly channelControlHelper: ChannelControlHelper) {
256+
constructor(private readonly channelControlHelper: ChannelControlHelper, options: ChannelOptions) {
257257
this.childBalancer = new ChildLoadBalancerHandler(createChildChannelControlHelper(channelControlHelper, {
258258
createSubchannel: (subchannelAddress, subchannelArgs) => {
259259
if (!this.xdsClient || !this.latestConfig || !this.lastestEndpointList) {
@@ -290,7 +290,7 @@ class XdsClusterImplBalancer implements LoadBalancer {
290290
channelControlHelper.updateState(connectivityState, picker);
291291
}
292292
}
293-
}));
293+
}), options);
294294
}
295295
updateAddressList(endpointList: Endpoint[], lbConfig: TypedLoadBalancingConfig, attributes: { [key: string]: unknown; }): void {
296296
if (!(lbConfig instanceof XdsClusterImplLoadBalancingConfig)) {

packages/grpc-js-xds/src/load-balancer-xds-cluster-manager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*/
1717

18-
import { connectivityState as ConnectivityState, status as Status, experimental, logVerbosity, Metadata, status } from "@grpc/grpc-js/";
18+
import { connectivityState as ConnectivityState, status as Status, experimental, logVerbosity, Metadata, status, ChannelOptions } from "@grpc/grpc-js/";
1919

2020
import TypedLoadBalancingConfig = experimental.TypedLoadBalancingConfig;
2121
import LoadBalancer = experimental.LoadBalancer;
@@ -131,7 +131,7 @@ class XdsClusterManager implements LoadBalancer {
131131
updateState: (connectivityState: ConnectivityState, picker: Picker) => {
132132
this.updateState(connectivityState, picker);
133133
},
134-
}));
134+
}), parent.options);
135135

136136
this.picker = new QueuePicker(this.childBalancer);
137137
}
@@ -167,7 +167,7 @@ class XdsClusterManager implements LoadBalancer {
167167
// Shutdown is a placeholder value that will never appear in normal operation.
168168
private currentState: ConnectivityState = ConnectivityState.SHUTDOWN;
169169
private updatesPaused = false;
170-
constructor(private channelControlHelper: ChannelControlHelper) {}
170+
constructor(private channelControlHelper: ChannelControlHelper, private options: ChannelOptions) {}
171171

172172
private maybeUpdateState() {
173173
if (!this.updatesPaused) {

packages/grpc-js-xds/src/load-balancer-xds-cluster-resolver.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*/
1717

18-
import { LoadBalancingConfig, Metadata, connectivityState, experimental, logVerbosity, status } from "@grpc/grpc-js";
18+
import { ChannelOptions, LoadBalancingConfig, Metadata, connectivityState, experimental, logVerbosity, status } from "@grpc/grpc-js";
1919
import { registerLoadBalancerType } from "@grpc/grpc-js/build/src/load-balancer";
2020
import { EXPERIMENTAL_OUTLIER_DETECTION } from "./environment";
2121
import { Locality__Output } from "./generated/envoy/config/core/v3/Locality";
@@ -232,14 +232,14 @@ export class XdsClusterResolver implements LoadBalancer {
232232
private xdsClient: XdsClient | null = null;
233233
private childBalancer: ChildLoadBalancerHandler;
234234

235-
constructor(private readonly channelControlHelper: ChannelControlHelper) {
235+
constructor(private readonly channelControlHelper: ChannelControlHelper, options: ChannelOptions) {
236236
this.childBalancer = new ChildLoadBalancerHandler(experimental.createChildChannelControlHelper(channelControlHelper, {
237237
requestReresolution: () => {
238238
for (const entry of this.discoveryMechanismList) {
239239
entry.resolver?.updateResolution();
240240
}
241241
}
242-
}));
242+
}), options);
243243
}
244244

245245
private maybeUpdateChild() {

packages/grpc-js-xds/src/load-balancer-xds-wrr-locality.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
// https://github.com/grpc/proposal/blob/master/A52-xds-custom-lb-policies.md
1919

20-
import { LoadBalancingConfig, experimental, logVerbosity } from "@grpc/grpc-js";
20+
import { ChannelOptions, LoadBalancingConfig, experimental, logVerbosity } from "@grpc/grpc-js";
2121
import { loadProtosWithOptionsSync } from "@grpc/proto-loader/build/src/util";
2222
import { WeightedTargetRaw } from "./load-balancer-weighted-target";
2323
import { isLocalityEndpoint } from "./load-balancer-priority";
@@ -73,8 +73,8 @@ class XdsWrrLocalityLoadBalancingConfig implements TypedLoadBalancingConfig {
7373

7474
class XdsWrrLocalityLoadBalancer implements LoadBalancer {
7575
private childBalancer: ChildLoadBalancerHandler;
76-
constructor(private readonly channelControlHelper: ChannelControlHelper) {
77-
this.childBalancer = new ChildLoadBalancerHandler(channelControlHelper);
76+
constructor(private readonly channelControlHelper: ChannelControlHelper, options: ChannelOptions) {
77+
this.childBalancer = new ChildLoadBalancerHandler(channelControlHelper, options);
7878
}
7979
updateAddressList(endpointList: Endpoint[], lbConfig: TypedLoadBalancingConfig, attributes: { [key: string]: unknown; }): void {
8080
if (!(lbConfig instanceof XdsWrrLocalityLoadBalancingConfig)) {

packages/grpc-js-xds/test/test-custom-lb-policies.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { XdsServer } from "./xds-server";
2424
import * as assert from 'assert';
2525
import { WrrLocality } from "../src/generated/envoy/extensions/load_balancing_policies/wrr_locality/v3/WrrLocality";
2626
import { TypedStruct } from "../src/generated/xds/type/v3/TypedStruct";
27-
import { connectivityState, experimental, logVerbosity } from "@grpc/grpc-js";
27+
import { ChannelOptions, connectivityState, experimental, logVerbosity } from "@grpc/grpc-js";
2828

2929
import TypedLoadBalancingConfig = experimental.TypedLoadBalancingConfig;
3030
import LoadBalancer = experimental.LoadBalancer;
@@ -83,7 +83,7 @@ const RPC_BEHAVIOR_CHILD_CONFIG = parseLoadBalancingConfig({round_robin: {}});
8383
class RpcBehaviorLoadBalancer implements LoadBalancer {
8484
private child: ChildLoadBalancerHandler;
8585
private latestConfig: RpcBehaviorLoadBalancingConfig | null = null;
86-
constructor(channelControlHelper: ChannelControlHelper) {
86+
constructor(channelControlHelper: ChannelControlHelper, options: ChannelOptions) {
8787
const childChannelControlHelper = createChildChannelControlHelper(channelControlHelper, {
8888
updateState: (state, picker) => {
8989
if (state === connectivityState.READY && this.latestConfig) {
@@ -92,7 +92,7 @@ class RpcBehaviorLoadBalancer implements LoadBalancer {
9292
channelControlHelper.updateState(state, picker);
9393
}
9494
});
95-
this.child = new ChildLoadBalancerHandler(childChannelControlHelper);
95+
this.child = new ChildLoadBalancerHandler(childChannelControlHelper, options);
9696
}
9797
updateAddressList(endpointList: Endpoint[], lbConfig: TypedLoadBalancingConfig, attributes: { [key: string]: unknown; }): void {
9898
if (!(lbConfig instanceof RpcBehaviorLoadBalancingConfig)) {

packages/grpc-js/src/load-balancer-child-handler.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ export class ChildLoadBalancerHandler implements LoadBalancer {
8484
}
8585
};
8686

87-
constructor(private readonly channelControlHelper: ChannelControlHelper) {}
87+
constructor(
88+
private readonly channelControlHelper: ChannelControlHelper,
89+
private readonly options: ChannelOptions
90+
) {}
8891

8992
protected configUpdateRequiresNewPolicyInstance(
9093
oldConfig: TypedLoadBalancingConfig,
@@ -111,7 +114,7 @@ export class ChildLoadBalancerHandler implements LoadBalancer {
111114
this.configUpdateRequiresNewPolicyInstance(this.latestConfig, lbConfig)
112115
) {
113116
const newHelper = new this.ChildPolicyHelper(this);
114-
const newChild = createLoadBalancer(lbConfig, newHelper)!;
117+
const newChild = createLoadBalancer(lbConfig, newHelper, this.options)!;
115118
newHelper.setChild(newChild);
116119
if (this.currentChild === null) {
117120
this.currentChild = newChild;

0 commit comments

Comments
 (0)