Alanxtl opened a new issue, #29: URL: https://github.com/apache/dubbo-go-extensions/issues/29
## 背景 依赖 dubbo-go#3687 提供的统一 extension config/option API,将当前 filter/hystrix 从旧的手工配置方式迁移到新的 extension 配置模型。 当前实现要求用户: 1. 直接依赖并调用 github.com/afex/hystrix-go/hystrix.ConfigureCommand; 2. 自己区分并配置 hystrix_consumer / hystrix_provider; 3. 在 client/server 上手动调用 client.WithFilter / server.WithFilter; 4. 手工使用带有 dubbo:consumer: / dubbo:provider: 前缀的 command name。 当前实现: - [filter/hystrix/filter.go](https://github.com/apache/dubbo-go-extensions/blob/main/filter/hystrix/filter.go) - [filter/hystrix/README.md](https://github.com/apache/dubbo-go-extensions/blob/main/filter/hystrix/README.md) - [filter/hystrix/README_CN.md](https://github.com/apache/dubbo-go-extensions/blob/main/filter/hystrix/README_CN.md) ## 目标 将 Hystrix 迁移为 dubbo-go 新的 extension config/option 使用方式: - 用户不再直接调用 hystrix.ConfigureCommand; - 用户不再直接依赖 hystrix_consumer / hystrix_provider filter name; - 用户通过 client.WithExtension 或 server.WithExtension 使用 Hystrix; - 用户可以通过 dubbo.Load() 加载 Hystrix YAML 配置; - consumer/provider 由调用入口和 YAML 层级明确区分; - 不再要求用户配置 dubbo:consumer: / dubbo:provider: 前缀。 ## 目标 API ### Consumer ~~~go import ( "context" "dubbo.apache.org/dubbo-go/v3" "dubbo.apache.org/dubbo-go/v3/client" "github.com/apache/dubbo-go-extensions/filter/hystrix" ) func main() { ins, err := dubbo.NewInstance(...) if err != nil { panic(err) } cli, err := ins.NewClient( client.WithExtension( hystrix.WithConfig( hystrix.WithCommandName("greet.GreetService:::Greet"), hystrix.WithTimeout(1000), hystrix.WithMaxConcurrentRequests(10), hystrix.WithRequestVolumeThreshold(5), hystrix.WithSleepWindow(5000), hystrix.WithErrorPercentThreshold(50), ), ), ) if err != nil { panic(err) } svc, err := greet.NewGreetService(cli) if err != nil { panic(err) } _, _ = svc.Greet(context.Background(), &greet.GreetRequest{Name: "test"}) } ~~~ ### Provider ~~~go import ( "dubbo.apache.org/dubbo-go/v3/server" "github.com/apache/dubbo-go-extensions/filter/hystrix" ) func main() { srv, err := server.NewServer( server.WithExtension( hystrix.WithConfig( hystrix.WithCommandName("greet.GreetService:::Greet"), hystrix.WithTimeout(1000), hystrix.WithMaxConcurrentRequests(10), hystrix.WithRequestVolumeThreshold(5), hystrix.WithSleepWindow(5000), hystrix.WithErrorPercentThreshold(50), ), ), ) if err != nil { panic(err) } // ... rest of server setup } ~~~ 具体 option 命名可以在实现过程中根据 Hystrix 配置结构进行微调,但需要满足: - hystrix.WithConfig(...) 返回 extension.Option; - option 由 hystrix 包定义; - 核心只接收 extension.Option,不增加 WithHystrix 等具体扩展 API; - 同一个扩展可以通过多个 WithConfig 配置多个 command; - option 按用户声明顺序应用; - 配置对象在不同 client/server 之间相互隔离。 ## YAML 配置 不增加 commands 中间层,每个 command 直接作为一条配置: ~~~yaml dubbo: extensions: hystrix: consumer: "greet.GreetService:::Greet": timeout: 1000 max-concurrent-requests: 10 request-volume-threshold: 5 sleep-window: 5000 error-percent-threshold: 50 provider: "greet.GreetService:::Greet": timeout: 1000 max-concurrent-requests: 10 request-volume-threshold: 5 sleep-window: 5000 error-percent-threshold: 50 ~~~ 要求: - consumer 配置只在 client 生命周期生效; - provider 配置只在 server 生命周期生效; - command key 中的 . 和 : 必须保持为完整 key; - YAML 配置和 typed option 的优先级为:默认值 < YAML < typed option; - 不支持的 scope 或非法配置需要在初始化阶段返回明确错误。 ## 实现要求 ### 1. 接入新的 Config 模型 Hystrix 配置需要实现 dubbo-go 新的 extension.Config: - Prefix() 返回 hystrix; - New() 返回独立且带默认值的配置对象; - Init(scope) 根据当前 scope 初始化 Hystrix command; - FilterNames(scope) 返回对应 scope 的内部 filter name; - 在 init() 中使用 extension.MustRegisterConfig 注册配置; - 继续使用现有 extension.SetFilter 注册 consumer/provider filter。 Hystrix 不支持 InstanceScope,通过 Init(scope) 返回明确错误。 ### 2. 资源名处理 新的用户配置 key 使用: ~~~text greet.GreetService:::Greet ~~~ 不再要求用户配置: ~~~text dubbo:consumer:greet.GreetService:::Greet dubbo:provider:greet.GreetService:::Greet ~~~ filter 执行时继续通过现有的: - invoker.GetURL() - invocation.MethodName() 获取 interface、group、version 和 method。 consumer/provider 的区分由当前 filter 和初始化 scope 决定。若 Hystrix 内部为避免 consumer/provider command 冲突仍需要生成内部名称,该名称必须对用户隐藏,不能再成为配置格式的一部分。 ### 3. Filter chain - 用户不需要显式调用 client.WithFilter("hystrix_consumer"); - 用户不需要显式调用 server.WithFilter("hystrix_provider"); - FilterNames(ClientScope) 返回 consumer filter; - FilterNames(ServerScope) 返回 provider filter; - 继续复用 dubbo-go 现有 filter registry 和 filter chain; - 不重复注册或重复添加 filter。 ### 4. Breaking change 本次允许直接破坏性更新,不需要兼容旧用法: - 删除 README 中直接调用 hystrix.ConfigureCommand 的示例; - 删除 README 中手动调用 client.WithFilter / server.WithFilter 的示例; - 删除用户可见的 dubbo:consumer: / dubbo:provider: command name 前缀; - hystrix_consumer / hystrix_provider 可以保留为扩展内部注册名,但不再作为用户 API 文档的一部分。 ## 测试要求 - Config 注册和 New() 配置隔离; - consumer/provider scope 初始化; - InstanceScope 返回错误; - typed option 能覆盖 YAML 配置; - 多个 command 配置互不影响; - command key 包含 . 和 : 时能正确加载; - consumer filter 自动加入 client filter chain; - provider filter 自动加入 server filter chain; - 用户未显式配置 filter 时保留默认 filter; - 用户显式排除 Hystrix filter 时行为正确; - Hystrix 调用成功、超时、熔断和 fallback 行为; - YAML 和 Go API 两种方式的端到端测试。 ## 文档要求 同步更新: - filter/hystrix/README.md - filter/hystrix/README_CN.md - 必要时更新示例和包注释 移除旧 API 使用说明,并补充新的 Go API、YAML 配置和 consumer/provider scope 说明。 ## 依赖 - 依赖 [apache/dubbo-go#3687](https://github.com/apache/dubbo-go/pull/3687) - 本 issue 只迁移 Hystrix,不扩展通用 extension runtime 能力。 -- 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]
