@@ -34,7 +34,7 @@ import {
3434} from './picker' ;
3535import { Endpoint , SubchannelAddress , subchannelAddressToString } from './subchannel-address' ;
3636import * as logging from './logging' ;
37- import { LogVerbosity , Status } from './constants' ;
37+ import { LogVerbosity } from './constants' ;
3838import {
3939 SubchannelInterface ,
4040 ConnectivityStateListener ,
@@ -44,12 +44,6 @@ import { isTcpSubchannelAddress } from './subchannel-address';
4444import { isIPv6 } from 'net' ;
4545import { ChannelOptions } from './channel-options' ;
4646import { StatusOr , statusOrFromValue } from './call-interface' ;
47- import { OrcaLoadReport__Output } from './generated/xds/data/orca/v3/OrcaLoadReport' ;
48- import { OpenRcaServiceClient } from './generated/xds/service/orca/v3/OpenRcaService' ;
49- import { ClientReadableStream , ServiceError } from './call' ;
50- import { createOrcaClient , MetricsListener } from './orca' ;
51- import { msToDuration } from './duration' ;
52- import { BackoffTimeout } from './backoff-timeout' ;
5347
5448const TRACER_NAME = 'pick_first' ;
5549
@@ -245,13 +239,6 @@ export class PickFirstLoadBalancer implements LoadBalancer {
245239
246240 private latestResolutionNote : string = '' ;
247241
248- private metricsListeners : Map < MetricsListener , number > = new Map ( ) ;
249- private orcaClient : OpenRcaServiceClient | null = null ;
250- private metricsCall : ClientReadableStream < OrcaLoadReport__Output > | null = null ;
251- private currentMetricsIntervalMs : number = Infinity ;
252- private orcaUnsupported = false ;
253- private metricsBackoffTimer = new BackoffTimeout ( ( ) => this . updateMetricsSubscription ( ) ) ;
254-
255242 /**
256243 * Load balancer that attempts to connect to each backend in the address list
257244 * in order, and picks the first one that connects, using it for every
@@ -349,12 +336,6 @@ export class PickFirstLoadBalancer implements LoadBalancer {
349336 this . currentPick . removeHealthStateWatcher (
350337 this . pickedSubchannelHealthListener
351338 ) ;
352- this . orcaClient ?. close ( ) ;
353- this . orcaClient = null ;
354- this . metricsCall ?. cancel ( ) ;
355- this . metricsCall = null ;
356- this . metricsBackoffTimer . stop ( ) ;
357- this . metricsBackoffTimer . reset ( ) ;
358339 // Unref last, to avoid triggering listeners
359340 this . currentPick . unref ( ) ;
360341 this . currentPick = null ;
@@ -458,7 +439,6 @@ export class PickFirstLoadBalancer implements LoadBalancer {
458439 this . currentPick = subchannel ;
459440 clearTimeout ( this . connectionDelayTimeout ) ;
460441 this . calculateAndReportNewState ( ) ;
461- this . updateMetricsSubscription ( ) ;
462442 }
463443
464444 private updateState ( newState : ConnectivityState , picker : Picker , errorMessage : string | null ) {
@@ -588,77 +568,11 @@ export class PickFirstLoadBalancer implements LoadBalancer {
588568 destroy ( ) {
589569 this . resetSubchannelList ( ) ;
590570 this . removeCurrentPick ( ) ;
591- this . metricsCall ?. cancel ( ) ;
592- this . metricsCall = null ;
593- this . orcaClient ?. close ( ) ;
594- this . orcaClient = null ;
595- this . metricsBackoffTimer . stop ( ) ;
596571 }
597572
598573 getTypeName ( ) : string {
599574 return TYPE_NAME ;
600575 }
601-
602- private getOrCreateOrcaClient ( ) : OpenRcaServiceClient | null {
603- if ( this . orcaClient ) {
604- return this . orcaClient ;
605- }
606- if ( this . currentPick ) {
607- const channel = this . currentPick . getChannel ( ) ;
608- this . orcaClient = createOrcaClient ( channel ) ;
609- return this . orcaClient ;
610- }
611- return null ;
612- }
613-
614- private updateMetricsSubscription ( ) {
615- if ( this . orcaUnsupported ) {
616- return ;
617- }
618- if ( this . metricsListeners . size > 0 ) {
619- const newInterval = Math . min ( ...Array . from ( this . metricsListeners . values ( ) ) ) ;
620- if ( ! this . metricsCall || newInterval !== this . currentMetricsIntervalMs ) {
621- const orcaClient = this . getOrCreateOrcaClient ( ) ;
622- if ( ! orcaClient ) {
623- return ;
624- }
625- this . metricsCall ?. cancel ( ) ;
626- this . currentMetricsIntervalMs = newInterval ;
627- const metricsCall = orcaClient . streamCoreMetrics ( { report_interval : msToDuration ( newInterval ) } ) ;
628- this . metricsCall = metricsCall ;
629- metricsCall . on ( 'data' , ( report : OrcaLoadReport__Output ) => {
630- this . metricsListeners . forEach ( ( interval , listener ) => {
631- listener ( report ) ;
632- } ) ;
633- } ) ;
634- metricsCall . on ( 'error' , ( error : ServiceError ) => {
635- this . metricsCall = null ;
636- if ( error . code === Status . UNIMPLEMENTED ) {
637- this . orcaUnsupported = true ;
638- return ;
639- }
640- if ( error . code === Status . CANCELLED ) {
641- return ;
642- }
643- this . metricsBackoffTimer . runOnce ( ) ;
644- } ) ;
645- }
646- } else {
647- this . metricsCall ?. cancel ( ) ;
648- this . metricsCall = null ;
649- this . currentMetricsIntervalMs = Infinity ;
650- }
651- }
652-
653- addMetricsSubscription ( listener : MetricsListener , intervalMs : number ) : void {
654- this . metricsListeners . set ( listener , intervalMs ) ;
655- this . updateMetricsSubscription ( ) ;
656- }
657-
658- removeMetricsSubscription ( listener : MetricsListener ) : void {
659- this . metricsListeners . delete ( listener ) ;
660- this . updateMetricsSubscription ( ) ;
661- }
662576}
663577
664578const LEAF_CONFIG = new PickFirstLoadBalancingConfig ( false ) ;
@@ -736,14 +650,6 @@ export class LeafLoadBalancer {
736650 destroy ( ) {
737651 this . pickFirstBalancer . destroy ( ) ;
738652 }
739-
740- addMetricsSubscription ( listener : MetricsListener , intervalMs : number ) : void {
741- this . pickFirstBalancer . addMetricsSubscription ( listener , intervalMs ) ;
742- }
743-
744- removeMetricsSubscription ( listener : MetricsListener ) : void {
745- this . pickFirstBalancer . removeMetricsSubscription ( listener ) ;
746- }
747653}
748654
749655export function setup ( ) : void {
0 commit comments