mochengqian commented on code in PR #3309:
URL: https://github.com/apache/dubbo-go/pull/3309#discussion_r3152308075


##########
registry/servicediscovery/service_instances_changed_listener_impl.go:
##########
@@ -183,6 +178,22 @@ func (lstn *ServiceInstancesChangedListenerImpl) OnEvent(e 
observer.Event) error
        return nil
 }
 
+func toInstanceServiceURLs(instance registry.ServiceInstance, serviceInfo 
*info.ServiceInfo) []*common.URL {
+       urls := instance.ToURLs(serviceInfo)
+       metadata := instance.GetMetadata()
+       if metadata == nil {
+               return urls
+       }
+       // Environment is instance-level routing metadata and is not part of 
the revision hash.
+       // Prefer the fresh instance value so same-revision restarts do not 
reuse stale metadata.
+       if environment := metadata[constant.EnvironmentKey]; environment != "" {
+               for _, url := range urls {
+                       url.SetParam(constant.EnvironmentKey, environment)
+               }
+       }
+       return urls
+}

Review Comment:
   Good catch, thanks.
   I have gained a lot from your many reviews, which have greatly improved my 
review thinking skills!
   
   I updated the helper to treat fresh instance metadata as the authoritative 
source:
   - non-empty `environment` overrides the synthesized URL param
   - empty or absent `environment` removes `EnvironmentKey` from the 
synthesized URL
   
   I also added regression coverage for same-revision environment update, empty 
value, and missing key cases.



-- 
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