Skip to content

Commit 91631ba

Browse files
committed
Update XdsClusterImpl LB policy to accept unset LRS config
1 parent c8b5d31 commit 91631ba

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class XdsClusterImplLoadBalancingConfig implements TypedLoadBalancingConfig {
7979
};
8080
}
8181

82-
constructor(private cluster: string, private dropCategories: DropCategory[], private childPolicy: TypedLoadBalancingConfig, private edsServiceName: string, private lrsLoadReportingServer: XdsServerConfig, maxConcurrentRequests?: number) {
82+
constructor(private cluster: string, private dropCategories: DropCategory[], private childPolicy: TypedLoadBalancingConfig, private edsServiceName: string, private lrsLoadReportingServer?: XdsServerConfig, maxConcurrentRequests?: number) {
8383
this.maxConcurrentRequests = maxConcurrentRequests ?? DEFAULT_MAX_CONCURRENT_REQUESTS;
8484
}
8585

@@ -127,7 +127,11 @@ class XdsClusterImplLoadBalancingConfig implements TypedLoadBalancingConfig {
127127
if (!childConfig) {
128128
throw new Error('xds_cluster_impl config child_policy parsing failed');
129129
}
130-
return new XdsClusterImplLoadBalancingConfig(obj.cluster, obj.drop_categories.map(validateDropCategory), childConfig, obj.eds_service_name, validateXdsServerConfig(obj.lrs_load_reporting_server), obj.max_concurrent_requests);
130+
let lrsServer: XdsServerConfig | undefined = undefined;
131+
if (obj.lrs_load_reporting_server) {
132+
lrsServer = validateXdsServerConfig(obj.lrs_load_reporting_server)
133+
}
134+
return new XdsClusterImplLoadBalancingConfig(obj.cluster, obj.drop_categories.map(validateDropCategory), childConfig, obj.eds_service_name, lrsServer, obj.max_concurrent_requests);
131135
}
132136
}
133137

@@ -156,7 +160,7 @@ class CallCounterMap {
156160
const callCounterMap = new CallCounterMap();
157161

158162
class LocalitySubchannelWrapper extends BaseSubchannelWrapper implements SubchannelInterface {
159-
constructor(child: SubchannelInterface, private statsObject: XdsClusterLocalityStats) {
163+
constructor(child: SubchannelInterface, private statsObject: XdsClusterLocalityStats | null) {
160164
super(child);
161165
}
162166

@@ -210,12 +214,12 @@ class XdsClusterImplPicker implements Picker {
210214
subchannel: pickSubchannel?.getWrappedSubchannel() ?? null,
211215
onCallStarted: () => {
212216
originalPick.onCallStarted?.();
213-
pickSubchannel?.getStatsObject().addCallStarted();
217+
pickSubchannel?.getStatsObject()?.addCallStarted();
214218
callCounterMap.startCall(this.callCounterMapKey);
215219
},
216220
onCallEnded: status => {
217221
originalPick.onCallEnded?.(status);
218-
pickSubchannel?.getStatsObject().addCallFinished(status !== Status.OK)
222+
pickSubchannel?.getStatsObject()?.addCallFinished(status !== Status.OK)
219223
callCounterMap.endCall(this.callCounterMapKey);
220224
}
221225
};
@@ -253,12 +257,16 @@ class XdsClusterImplBalancer implements LoadBalancer {
253257
}
254258
const locality = (subchannelAddress as LocalitySubchannelAddress).locality ?? '';
255259
const wrapperChild = channelControlHelper.createSubchannel(subchannelAddress, subchannelArgs);
256-
const statsObj = this.xdsClient.addClusterLocalityStats(
257-
this.latestConfig.getLrsLoadReportingServer(),
258-
this.latestConfig.getCluster(),
259-
this.latestConfig.getEdsServiceName(),
260-
locality
261-
);
260+
const lrsServer = this.latestConfig.getLrsLoadReportingServer();
261+
let statsObj: XdsClusterLocalityStats | null = null;
262+
if (lrsServer) {
263+
statsObj = this.xdsClient.addClusterLocalityStats(
264+
lrsServer,
265+
this.latestConfig.getCluster(),
266+
this.latestConfig.getEdsServiceName(),
267+
locality
268+
);
269+
}
262270
return new LocalitySubchannelWrapper(wrapperChild, statsObj);
263271
},
264272
updateState: (connectivityState, originalPicker) => {

0 commit comments

Comments
 (0)