Modo-me commented on code in PR #3685:
URL: https://github.com/apache/dubbo-go/pull/3685#discussion_r3823519241


##########
registry/servicediscovery/service_instances_changed_listener_impl.go:
##########
@@ -277,8 +281,23 @@ func GetMetadataInfo(app string, instance 
registry.ServiceInstance, revision str
                initCache(app)
        })
        cacheKey := metadataCacheKey(app, registryId, revision)
-       if metadataInfo, ok := metaCache.Get(cacheKey); ok {
-               return metadataInfo.(*info.MetadataInfo), nil
+       if cached, ok := metaCache.Get(cacheKey); ok {
+               logger.Debugf("[Metadata][Cache] hit app=%s registry=%s 
revision=%s host=%s",
+                       app, registryId, revision, instance.GetHost())
+               event := 
metricsMetadata.NewMetadataMetricTimeEvent(metricsMetadata.MetadataCache)
+               event.Succ = true
+               event.Attachment[metricsMetadata.TagProviderApp] = app
+               metrics.Publish(event)
+               metadataInfo := cached.(*info.MetadataInfo)
+               if metadataInfo == nil {
+                       publishMetadataFetchEvent(app, registryId, revision, 
instance.GetHost(),
+                               metricsMetadata.SourceCache, 
metricsMetadata.StorageTypeCache, metricsMetadata.ResultFailure,
+                               perrors.New("typed nil metadata in cache"))
+                       return nil, nil
+               }
+               publishMetadataFetchEvent(app, registryId, revision, 
instance.GetHost(),
+                       metricsMetadata.SourceCache, 
metricsMetadata.StorageTypeCache, metricsMetadata.ResultSuccess, nil)
+               return metadataInfo, nil
        }

Review Comment:
   写的时候考虑过这里,但是此次埋点改动并未涉及到任何业务逻辑上的变更,如果原来的时候nil就不成问题,那么就没必要加上去一长串防御性代码



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to