xxs588 opened a new issue, #3397: URL: https://github.com/apache/dubbo-go/issues/3397
### ✅ 验证清单 - [x] 🔍 我已经搜索过 [现有 Issues](https://github.com/apache/dubbo-go/issues),确信这不是重复问题 - [x] 📚 我已对照 dubbo-go 源码(metadata、service_discovery、tag router)进行溯源 - [x] 🧪 我已在本地使用 dubbo-go-samples/task/shop demo 实际验证 ### 🚀 Go 版本 go1.25.6 linux/amd64 ### 📦 Dubbo-go 版本 upstream main (e6e14fd3),已同步至最新 ### 🖥️ 服务端配置 使用 `dubbo-go-samples/task/shop` demo,启动 8 个服务: - comment-v1 (port 20010), comment-v2 (port 20020) - detail-v1 (port 20011), detail-v2 (port 20021) - order-v1 (port 20012), order-v2 (port 20022) - user (port 20013), frontend (port 8080) v2 服务配置: ```go ins, _ := dubbo.NewInstance( dubbo.WithName("shop-detail"), dubbo.WithTag("gray"), // 设置 application.tag=gray dubbo.WithRegistry(registry.WithZookeeper(), registry.WithAddress("127.0.0.1:2181")), dubbo.WithConfigCenter(config_center.WithZookeeper(), config_center.WithAddress("127.0.0.1:2181")), dubbo.WithProtocol(protocol.WithTriple(), protocol.WithPort(20021)), ) ``` ### 💻 客户端配置 frontend 通过 `dubbo.NewInstance` + `ins.NewClient()` 创建 consumer,使用 service-discovery-registry 模式发现 provider。 Consumer 发送灰度请求: ```go ctx := context.WithValue(context.Background(), constant.AttachmentKey, map[string]string{ "dubbo.tag": "gray", "dubbo.force.tag": "true", }) detailService.GetItem(ctx, req) ``` ### 🌐 协议配置 Triple ### 📋 注册中心配置 Zookeeper v3.9.4, 127.0.0.1:2181 ### 💾 操作系统 🐧 Linux ### 📝 Bug 描述 在使用 v3 NewInstance API + Triple 协议 + Zookeeper 注册中心的场景下,Tag Router 端到端不可用。 **核心问题:** Provider 导出的 URL 包含 `application.tag=gray`,但 Consumer 通过 service-discovery-registry 发现 provider 时,URL 中的 `dubbo.tag` 为空字符串。Tag Router 只匹配 `dubbo.tag`,导致找不到灰度 provider。 ``` Provider 导出: application.tag=gray ✅ Consumer 发现: dubbo.tag= ❌ (空) ``` **源码溯源发现:** 框架代码中存在 `application.tag → dubbo.tag` 的传播链路: 1. `metadata/metadata.go:44` — `AddService()` 读 `application.tag` 存入 `MetadataInfo.Tag` 2. `servicediscovery/service_discovery_registry.go:135` — `createInstance()` 设置 `instance.Tag = meta.Tag` 3. `servicediscovery/customizer/service_instance_tag_customizer.go:40` — `Customize()` 注入 `instance.GetMetadata()["dubbo.tag"] = tag` 4. `registry/service_instance.go:182` — `ToURLs()` 读 `d.Tag` 设置 `dubbo.tag` 但实际运行中这条链路不生效。consumer 发现的 provider URL 中 `dubbo.tag` 始终为空。 **对比发现:** 同一个 provider,通过 interface-level registry 被其他 provider 发现时 `dubbo.tag=gray` ✅,但通过 service-discovery-registry 被 consumer 发现时 `dubbo.tag=` ❌。说明问题仅在 service-discovery-registry 路径。 ### 🔄 重现步骤 1. 克隆 `dubbo-go-samples`,进入 `task/shop` 目录 2. `go.mod` 添加 `replace dubbo.apache.org/dubbo-go/v3 => <本地最新 upstream main>` 3. v2 服务配置 `dubbo.WithTag("gray")` 4. 启动 Zookeeper (port 2181) 5. 按顺序启动 8 个服务 6. 访问 `http://localhost:8080/grayLogin?username=test&password=123` 7. 观察返回 500,日志报 "No provider available" 8. 检查 frontend 日志中 `selector add service` 的 detail-v2 URL,`dubbo.tag=` 为空 ### ✅ 预期行为 1. Provider 配置 `dubbo.WithTag("gray")` 后,consumer 通过 service-discovery-registry 发现的 provider URL 应包含 `dubbo.tag=gray` 2. Consumer 发送 `dubbo.tag=gray` + `dubbo.force.tag=true` 的请求应能命中带 `dubbo.tag=gray` 的 provider 3. Tag Router 的 static 和 dynamic 两种模式都应端到端可用 ### ❌ 实际行为 1. Consumer 发现的 provider URL 中 `dubbo.tag=` 为空 2. Tag Router 找不到匹配的 provider,返回 "No provider available" 3. 灰度路由完全不可用 ### 💡 可能的解决方案 需要定位 `application.tag → dubbo.tag` 传播链路的具体断裂点。建议在以下位置加 debug log: 1. `servicediscovery/customizer/service_instance_tag_customizer.go:Customize()` — 确认 `instance.GetTag()` 的值 2. `registry/service_instance.go:ToURLs()` — 确认 `d.Tag` 的值 3. `servicediscovery/service_discovery_registry.go:createInstance()` — 确认 `meta.Tag` 的值 可能的原因: - `MetadataInfo.Tag` 在序列化/反序列化过程中丢失(`Tag` 字段缺少 `json` 和 `hessian` tag) - `convertMetadataInfoV2`(`metadata/client.go:94-113`)未映射 Tag 字段 - `ToURLs()` 读取的 `d.Tag` 不是从 instance metadata 中的 `dubbo.tag` 获取的 ### 📎 关联 Issue - #3250 (CLOSED) — Tag router Route 方法 key 构建错误,PR #3251 已修复 - #3199 (CLOSED) — v3 API 下 TagRouter 被绕过,PR #3185 已修复 - #3196 (CLOSED) — context attachment 不注入 invocation,PR #3185 已修复 - #3203 (OPEN) — Router 状态总览 上述已关闭 issue 解决了 tag routing 的部分问题,但 `application.tag → dubbo.tag` 的传播问题仍然存在,导致 tag routing 端到端不可用。 ### 验收标准 - [ ] Provider 配置 `dubbo.WithTag("gray")` 后,consumer 发现的 URL 包含 `dubbo.tag=gray` - [ ] Consumer 发送 `dubbo.tag=gray` + `dubbo.force.tag=true` 能命中灰度 provider - [ ] `dubbo-go-samples/task/shop` 的 `/grayLogin` 接口返回 v2 数据 - [ ] 同时启动 v1 + v2 时,`/login` 返回 v1,`/grayLogin` 返回 v2 -- 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]
