Skip to content

feat(router): support static affinity router config#3420

Open
leno23 wants to merge 3 commits into
apache:developfrom
leno23:codex/affinity-router-static-config-3203
Open

feat(router): support static affinity router config#3420
leno23 wants to merge 3 commits into
apache:developfrom
leno23:codex/affinity-router-static-config-3203

Conversation

@leno23

@leno23 leno23 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

What

  • Add AffinityAware to static RouterConfig and preserve it through clone/compat conversion.
  • Implement SetStaticConfig for service and application affinity routers with scope filtering.
  • Add tests for static affinity routing, invalid configs, scope handling, and config cloning.

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 SetStaticConfig entry point.

Validation

  • go test ./cluster/router/affinity ./global ./config
  • go test ./cluster/router/...
  • go test .
  • git diff --check

Refs #3203

@codecov-commenter

codecov-commenter commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 53.53%. Comparing base (60d1c2a) to head (edae6d2).
⚠️ Report is 844 commits behind head on develop.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 AffinityAware to global.RouterConfig and config.RouterConfig, including clone + compat conversion support.
  • Implement SetStaticConfig for 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.

Comment on lines +191 to +194
if err != nil {
logger.Errorf("[Router][Affinity] parse static affinity rule failed: key=%s, rule=%s, err=%v", a.key, rule, err)
return
}
@sonarqubecloud

Copy link
Copy Markdown

@Alanxtl

Alanxtl commented Jun 16, 2026

Copy link
Copy Markdown
Member

@yangpixi @Aetherance help review this, is this pr necessary?

@Alanxtl Alanxtl added ✏️ Feature 3.3.2 version 3.3.2 labels Jun 16, 2026
@Alanxtl Alanxtl linked an issue Jun 16, 2026 that may be closed by this pull request
// 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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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 绑定的目标。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[讨论] dubbo-go router report

5 participants