Repository navigation
feat: complete local app metadata lifecycle - #3357
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #3357 +/- ##
===========================================
+ Coverage 46.76% 52.51% +5.74%
===========================================
Files 295 492 +197
Lines 17172 37871 +20699
===========================================
+ Hits 8031 19888 +11857
- Misses 8287 16376 +8089
- Partials 854 1607 +753 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Alanxtl
left a comment
There was a problem hiding this comment.
RemoveService / RemoveSubscribeURL 依赖底层 removeUrl 的指针相等:if u == url。如果 unregister/unsubscribe 传入的是 url.Clone() 或逻辑相同但不是同一个指针的 URL,Services 会按 match key 删除,但 exportedServiceURLs/subscribedServiceURLs 仍残留,revision 计算还会继续包含旧 URL。
相关代码在 metadata_info.go 建议按 URL key / service key + protocol + address / URLEqual 之类的逻辑相等删除,并补 clone URL 的测试。
| if id, exist := s.url.GetNonDefaultParam(constant.RegistryIdKey); exist { | ||
| metadata.RemoveService(id, url) | ||
| if metadataInfo := metadata.GetMetadataInfo(id); metadataInfo != nil { | ||
| instance := createInstance(metadataInfo, url) | ||
| metadataInfo.Revision = instance.GetMetadata()[constant.ExportedServicesRevisionPropertyName] | ||
| } | ||
| } | ||
| return s.UnRegisterService() | ||
| } | ||
|
|
||
| func (s *serviceDiscoveryRegistry) UnSubscribe(url *common.URL, listener registry.NotifyListener) error { | ||
| if !shouldSubscribe(url) { | ||
| return nil | ||
| } | ||
| if id, exist := s.url.GetNonDefaultParam(constant.RegistryIdKey); exist { | ||
| metadata.RemoveSubscribeURL(id, url) | ||
| } |
There was a problem hiding this comment.
UnRegister(url) 现在只删当前 URL 的 metadata,但随后仍调用 bulk 的 UnRegisterService(),它会遍历并注销 s.instances 里的所有 instance。也就是说两个 provider URL 注册后,注销 providerURL1 会把 providerURL2 的 instance 也从 service discovery 删除,但本地 metadata 还保留 providerURL2。这会造成 registry 侧和本地 metadata 状态分裂。
建议要么做 targeted unregister,要么如果语义就是注销整个 app,就同步清空对应 metadata;测试里也应断言 mockSD.unregisterIDs 只包含目标 URL。
|
|
有俩问题想对齐一下您的期望: 关于 remote metadata storage 这点:
|
然后这个的话,我也想确认一下:
|
There was a problem hiding this comment.
Pull request overview
This PR completes local application-level metadata cleanup for service discovery unregister/unsubscribe flows, aligning removal paths with existing register/subscribe metadata updates.
Changes:
- Adds top-level metadata removal APIs for exported and subscribed URLs.
- Wires unsubscribe and service unregister cleanup into service discovery registry behavior.
- Adds tests covering unsubscribe cleanup and unregister metadata revision updates.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
metadata/metadata.go |
Adds public metadata removal wrappers. |
metadata/metadata_test.go |
Adds tests for top-level remove APIs. |
metadata/info/metadata_info.go |
Allows removing cloned/equivalent URLs instead of only identical pointers. |
metadata/info/metadata_info_test.go |
Tests cloned URL removal behavior. |
registry/servicediscovery/service_discovery_registry.go |
Tracks registered instance source URLs and cleans metadata during unregister/unsubscribe. |
registry/servicediscovery/service_discovery_registry_test.go |
Adds lifecycle tests for unsubscribe and unregister metadata cleanup. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if len(removedURLs) == 0 { | ||
| return nil |
| if !exist { | ||
| return | ||
| } | ||
| metadataInfo.RemoveService(url) |
AlexStocks
left a comment
There was a problem hiding this comment.
Read-only review 完成:未发现需要阻断合并的问题。
验证:
golangci-lint run --new-from-rev origin/develop ./...:0 issuesgo test ./metadata/... ./registry/servicediscovery/...:通过
审查重点:本 PR 补齐 app-level metadata 在 unregister / unsubscribe 后的本地状态清理和剩余实例 revision 同步;当前新增用例覆盖 cloned URL remove、partial unregister 后 metadata 同步、bulk unregister 清理等路径,未发现新增逻辑漏洞。
|
已逐个自检+测试,感觉现在基本完成要求(? |
thanks for ur guide~ |
|



Description
Fixes #3349 (issue)
What changed
metadata.RemoveServiceandmetadata.RemoveSubscribeURLUnRegisterandUnSubscribeWhy
We already update local application-level metadata on register/subscribe, but the unregister/unsubscribe path does not clean it up.
That leaves stale service URLs in local
MetadataInfo, and the local revision can stay behind the actual exported state.This change keeps the existing flow as-is and only fills in the missing local cleanup path.
Checklist
develop