You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "AlbumenJ (via GitHub)" <gi...@apache.org> on 2023/03/13 12:35:49 UTC

[GitHub] [dubbo] AlbumenJ commented on a diff in pull request #11786: Interface level registry metrics

AlbumenJ commented on code in PR #11786:
URL: https://github.com/apache/dubbo/pull/11786#discussion_r1133869892


##########
dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java:
##########
@@ -325,13 +328,25 @@ protected void subscribeURLs(URL url, NotifyListener listener, Set<String> servi
                 serviceListeners.put(serviceNamesKey, serviceInstancesChangedListener);
             }
 
+            ApplicationModel applicationModel = url.getApplicationModel();
+            GlobalMetricsEventMulticaster eventMulticaster = applicationModel.getBeanFactory().getBean(GlobalMetricsEventMulticaster.class);
+            TimePair timePair = TimePair.start();
+
+            eventMulticaster.publishEvent(new RegistryEvent.MetricsServiceSubscribeEvent(applicationModel, timePair, serviceKey));
             if (!serviceInstancesChangedListener.isDestroyed()) {
                 listener.addServiceListener(serviceInstancesChangedListener);
                 serviceInstancesChangedListener.addListenerAndNotify(url, listener);
-                serviceDiscovery.addServiceInstancesChangedListener(serviceInstancesChangedListener);
+                try {
+                    serviceDiscovery.addServiceInstancesChangedListener(serviceInstancesChangedListener);
+                } catch (Throwable t) {
+                    eventMulticaster.publishErrorEvent(new RegistryEvent.MetricsServiceSubscribeEvent(applicationModel, timePair, serviceKey));
+                    throw t;
+                }
+                eventMulticaster.publishFinishEvent(new RegistryEvent.MetricsServiceSubscribeEvent(applicationModel, timePair, serviceKey));

Review Comment:
   Can we exact these logic into separated method like `doExecute(Runnable)`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org