feat(router): support static affinity router config#3420
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #3420 +/- ##
===========================================
+ Coverage 46.76% 53.53% +6.76%
===========================================
Files 295 493 +198
Lines 17172 38411 +21239
===========================================
+ Hits 8031 20564 +12533
- Misses 8287 16201 +7914
- Partials 854 1646 +792 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds support for injecting static affinity router configuration (in addition to existing dynamic config-center rules) by extending RouterConfig with AffinityAware and wiring it through clone/compat conversion and affinity router static setters.
Changes:
- Add
AffinityAwaretoglobal.RouterConfigandconfig.RouterConfig, including clone + compat conversion support. - Implement
SetStaticConfigfor service/application affinity routers with scope filtering and validation. - Add unit tests covering static affinity routing behavior, invalid configs, scope handling, and compat/clone preservation.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| global/router_config.go | Adds AffinityAware to static router config and preserves it in Clone(). |
| global/config_test.go | Extends router clone test to assert AffinityAware is cloned. |
| config/router_config.go | Adds AffinityAware to config-layer RouterConfig. |
| compat.go | Preserves AffinityAware when converting global router config to config router config. |
| compat_test.go | Adds test verifying compat conversion includes AffinityAware. |
| cluster/router/affinity/router.go | Adds static config injection entry points and implements affinityRoute.SetStaticConfig. |
| cluster/router/affinity/router_test.go | Adds tests for static affinity routing, invalid configs, and scope filtering. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if err != nil { | ||
| logger.Errorf("[Router][Affinity] parse static affinity rule failed: key=%s, rule=%s, err=%v", a.key, rule, err) | ||
| return | ||
| } |
|
|
@yangpixi @Aetherance help review this, is this pr necessary? |
| // SetStaticConfig applies a RouterConfig directly, bypassing YAML parsing. | ||
| // Static and dynamic rules are not merged: later Process updates replace the | ||
| // current state built here. | ||
| func (a *affinityRoute) SetStaticConfig(cfg *global.RouterConfig) { |
There was a problem hiding this comment.
[P1] injectStaticRouters() 会把同一个 reference 上的所有静态 router config 依次广播给每个 StaticConfigSetter。这里的实现只按 scope 过滤,然后把状态写进单个 matcher/enabled/key/ratio,但没有使用 cfg.Key 做分桶,所以同一个 reference 上如果配置了两条 application/service 级 affinity 规则,后一次 SetStaticConfig() 会直接覆盖前一次,前面的静态规则永远不会生效。tag router 的静态配置是按 cfg.Key 存 map 的,这里也需要类似的按 key 隔离,或者至少校验 cfg.Key 只匹配当前 router 绑定的目标。



What
AffinityAwareto staticRouterConfigand preserve it through clone/compat conversion.SetStaticConfigfor service and application affinity routers with scope filtering.Why
Issue #3203 lists affinity static route configuration as a router follow-up. The router already supports dynamic affinity rules, but static config injection had no affinity fields or
SetStaticConfigentry point.Validation
Refs #3203