@@ -57,7 +57,6 @@ final class SharedXdsClientPoolProvider implements XdsClientPoolFactory {
5757 private final Object lock = new Object ();
5858 private final AtomicReference <Map <String , ?>> bootstrapOverride = new AtomicReference <>();
5959 private final Map <String , ObjectPool <XdsClient >> targetToXdsClientMap = new ConcurrentHashMap <>();
60- private final Map <String , MetricRecorder > targetToMetricRecorderMap = new ConcurrentHashMap <>();
6160
6261 SharedXdsClientPoolProvider () {
6362 this (new GrpcBootstrapperImpl ());
@@ -83,12 +82,6 @@ public ObjectPool<XdsClient> get(String target) {
8382 return targetToXdsClientMap .get (target );
8483 }
8584
86- @ Override
87- @ Nullable
88- public ObjectPool <XdsClient > getOrCreate (String target ) throws XdsInitializationException {
89- return this .getOrCreate (target , new MetricRecorder () {});
90- }
91-
9285 @ Override
9386 public ObjectPool <XdsClient > getOrCreate (String target , MetricRecorder metricRecorder )
9487 throws XdsInitializationException {
@@ -107,12 +100,8 @@ public ObjectPool<XdsClient> getOrCreate(String target, MetricRecorder metricRec
107100 if (bootstrapInfo .servers ().isEmpty ()) {
108101 throw new XdsInitializationException ("No xDS server provided" );
109102 }
110- MetricRecorder metricRecorderForTarget = targetToMetricRecorderMap .get (target );
111- metricRecorder =
112- metricRecorderForTarget != null ? metricRecorderForTarget : metricRecorder ;
113103 ref = new RefCountedXdsClientObjectPool (bootstrapInfo , target , metricRecorder );
114104 targetToXdsClientMap .put (target , ref );
115- targetToMetricRecorderMap .putIfAbsent (target , metricRecorder );
116105 }
117106 }
118107 }
@@ -124,25 +113,19 @@ public ImmutableList<String> getTargets() {
124113 return ImmutableList .copyOf (targetToXdsClientMap .keySet ());
125114 }
126115
127- @ VisibleForTesting
128- MetricRecorder getMetricRecorder (String target ) {
129- return targetToMetricRecorderMap .get (target );
130- }
131-
132-
133116 private static class SharedXdsClientPoolProviderHolder {
134117 private static final SharedXdsClientPoolProvider instance = new SharedXdsClientPoolProvider ();
135118 }
136119
137120 @ ThreadSafe
138121 @ VisibleForTesting
139- static class RefCountedXdsClientObjectPool implements ObjectPool <XdsClient > {
122+ protected class RefCountedXdsClientObjectPool implements ObjectPool <XdsClient > {
140123
141- private static final ExponentialBackoffPolicy .Provider BACKOFF_POLICY_PROVIDER =
124+ private final ExponentialBackoffPolicy .Provider backoffPolicyProvider =
142125 new ExponentialBackoffPolicy .Provider ();
143126 private final BootstrapInfo bootstrapInfo ;
144127 private final String target ; // The target associated with the xDS client.
145- private final MetricRecorder metricRecorder ;
128+ private final XdsClientMetricReporterImpl xdsClientMetricReporter ;
146129 private final Object lock = new Object ();
147130 @ GuardedBy ("lock" )
148131 private ScheduledExecutorService scheduler ;
@@ -156,7 +139,7 @@ static class RefCountedXdsClientObjectPool implements ObjectPool<XdsClient> {
156139 MetricRecorder metricRecorder ) {
157140 this .bootstrapInfo = checkNotNull (bootstrapInfo );
158141 this .target = target ;
159- this .metricRecorder = metricRecorder ;
142+ this .xdsClientMetricReporter = new XdsClientMetricReporterImpl ( metricRecorder ) ;
160143 }
161144
162145 @ Override
@@ -171,13 +154,14 @@ public XdsClient getObject() {
171154 DEFAULT_XDS_TRANSPORT_FACTORY ,
172155 bootstrapInfo ,
173156 scheduler ,
174- BACKOFF_POLICY_PROVIDER ,
157+ backoffPolicyProvider ,
175158 GrpcUtil .STOPWATCH_SUPPLIER ,
176159 TimeProvider .SYSTEM_TIME_PROVIDER ,
177160 MessagePrinter .INSTANCE ,
178161 new TlsContextManagerImpl (bootstrapInfo ),
179162 getTarget (),
180- new XdsClientMetricReporterImpl (metricRecorder ));
163+ xdsClientMetricReporter );
164+ xdsClientMetricReporter .setXdsClient (xdsClient );
181165 }
182166 refCount ++;
183167 return xdsClient ;
@@ -191,6 +175,8 @@ public XdsClient returnObject(Object object) {
191175 if (refCount == 0 ) {
192176 xdsClient .shutdown ();
193177 xdsClient = null ;
178+ xdsClientMetricReporter .close ();
179+ targetToXdsClientMap .remove (target );
194180 scheduler = SharedResourceHolder .release (GrpcUtil .TIMER_SERVICE , scheduler );
195181 }
196182 return null ;
0 commit comments