@@ -37,6 +37,7 @@ import { Watcher } from './xds-stream-state/xds-stream-state';
3737import Filter = experimental . Filter ;
3838import BaseFilter = experimental . BaseFilter ;
3939import FilterFactory = experimental . FilterFactory ;
40+ import FilterStackFactory = experimental . FilterStackFactory ;
4041import CallStream = experimental . CallStream ;
4142
4243const TRACER_NAME = 'eds_balancer' ;
@@ -204,27 +205,42 @@ export class EdsLoadBalancer implements LoadBalancer {
204205 * Otherwise, delegate picking the subchannel to the child
205206 * balancer. */
206207 if ( dropCategory === null ) {
207- return originalPicker . pick ( pickArgs ) ;
208+ const originalPick = originalPicker . pick ( pickArgs ) ;
209+ let extraFilterFactory : FilterFactory < Filter > = new CallTrackingFilterFactory ( ( ) => {
210+ this . concurrentRequests -= 1 ;
211+ } ) ;
212+ if ( originalPick . extraFilterFactory ) {
213+ extraFilterFactory = new FilterStackFactory ( [ originalPick . extraFilterFactory , extraFilterFactory ] ) ;
214+ }
215+ return {
216+ pickResultType : originalPick . pickResultType ,
217+ status : originalPick . status ,
218+ subchannel : originalPick . subchannel ,
219+ onCallStarted : ( ) => {
220+ originalPick . onCallStarted ?.( ) ;
221+ this . concurrentRequests += 1 ;
222+ } ,
223+ extraFilterFactory : extraFilterFactory
224+ } ;
208225 } else {
226+ let details : string ;
209227 if ( dropCategory === true ) {
228+ details = 'Call dropped by load balancing policy.' ;
210229 this . clusterDropStats ?. addUncategorizedCallDropped ( ) ;
211230 } else {
231+ details = `Call dropped by load balancing policy. Category: ${ dropCategory } ` ;
212232 this . clusterDropStats ?. addCallDropped ( dropCategory ) ;
213233 }
214234 return {
215235 pickResultType : PickResultType . DROP ,
216236 status : {
217237 code : Status . UNAVAILABLE ,
218- details : `Call dropped by load balancing policy. Category: ${ dropCategory } ` ,
238+ details : details ,
219239 metadata : new Metadata ( ) ,
220240 } ,
221241 subchannel : null ,
222- extraFilterFactory : new CallTrackingFilterFactory ( ( ) => {
223- this . concurrentRequests -= 1 ;
224- } ) ,
225- onCallStarted : ( ) => {
226- this . concurrentRequests += 1 ;
227- } ,
242+ extraFilterFactory : null ,
243+ onCallStarted : null
228244 } ;
229245 }
230246 } ,
@@ -265,15 +281,12 @@ export class EdsLoadBalancer implements LoadBalancer {
265281 * output, as a sentinel value indicating a drop with no category.
266282 */
267283 private checkForDrop ( ) : string | true | null {
268- if ( ! this . latestEdsUpdate ?. policy ) {
269- return null ;
284+ if ( this . lastestConfig && this . concurrentRequests >= this . lastestConfig . getMaxConcurrentRequests ( ) ) {
285+ return true ;
270286 }
271- if ( ! this . lastestConfig ) {
287+ if ( ! this . latestEdsUpdate ?. policy ) {
272288 return null ;
273289 }
274- if ( this . concurrentRequests >= this . lastestConfig . getMaxConcurrentRequests ( ) ) {
275- return true ;
276- }
277290 /* The drop_overloads policy is a list of pairs of category names and
278291 * probabilities. For each one, if the random number is within that
279292 * probability range, we drop the call citing that category. Otherwise, the
0 commit comments