@@ -34,7 +34,7 @@ import {
34
34
} from './picker' ;
35
35
import { Endpoint , SubchannelAddress , subchannelAddressToString } from './subchannel-address' ;
36
36
import * as logging from './logging' ;
37
- import { LogVerbosity , Status } from './constants' ;
37
+ import { LogVerbosity } from './constants' ;
38
38
import {
39
39
SubchannelInterface ,
40
40
ConnectivityStateListener ,
@@ -44,12 +44,6 @@ import { isTcpSubchannelAddress } from './subchannel-address';
44
44
import { isIPv6 } from 'net' ;
45
45
import { ChannelOptions } from './channel-options' ;
46
46
import { 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' ;
53
47
54
48
const TRACER_NAME = 'pick_first' ;
55
49
@@ -245,13 +239,6 @@ export class PickFirstLoadBalancer implements LoadBalancer {
245
239
246
240
private latestResolutionNote : string = '' ;
247
241
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
-
255
242
/**
256
243
* Load balancer that attempts to connect to each backend in the address list
257
244
* in order, and picks the first one that connects, using it for every
@@ -349,12 +336,6 @@ export class PickFirstLoadBalancer implements LoadBalancer {
349
336
this . currentPick . removeHealthStateWatcher (
350
337
this . pickedSubchannelHealthListener
351
338
) ;
352
- this . orcaClient ?. close ( ) ;
353
- this . orcaClient = null ;
354
- this . metricsCall ?. cancel ( ) ;
355
- this . metricsCall = null ;
356
- this . metricsBackoffTimer . stop ( ) ;
357
- this . metricsBackoffTimer . reset ( ) ;
358
339
// Unref last, to avoid triggering listeners
359
340
this . currentPick . unref ( ) ;
360
341
this . currentPick = null ;
@@ -458,7 +439,6 @@ export class PickFirstLoadBalancer implements LoadBalancer {
458
439
this . currentPick = subchannel ;
459
440
clearTimeout ( this . connectionDelayTimeout ) ;
460
441
this . calculateAndReportNewState ( ) ;
461
- this . updateMetricsSubscription ( ) ;
462
442
}
463
443
464
444
private updateState ( newState : ConnectivityState , picker : Picker , errorMessage : string | null ) {
@@ -588,77 +568,11 @@ export class PickFirstLoadBalancer implements LoadBalancer {
588
568
destroy ( ) {
589
569
this . resetSubchannelList ( ) ;
590
570
this . removeCurrentPick ( ) ;
591
- this . metricsCall ?. cancel ( ) ;
592
- this . metricsCall = null ;
593
- this . orcaClient ?. close ( ) ;
594
- this . orcaClient = null ;
595
- this . metricsBackoffTimer . stop ( ) ;
596
571
}
597
572
598
573
getTypeName ( ) : string {
599
574
return TYPE_NAME ;
600
575
}
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
- }
662
576
}
663
577
664
578
const LEAF_CONFIG = new PickFirstLoadBalancingConfig ( false ) ;
@@ -736,14 +650,6 @@ export class LeafLoadBalancer {
736
650
destroy ( ) {
737
651
this . pickFirstBalancer . destroy ( ) ;
738
652
}
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
- }
747
653
}
748
654
749
655
export function setup ( ) : void {
0 commit comments