fix(router): call BuildRouterChain method when creating directory.#3225
fix(router): call BuildRouterChain method when creating directory.#3225yangpixi wants to merge 4 commits intoapache:developfrom
Conversation
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #3225 +/- ##
===========================================
- Coverage 47.99% 47.91% -0.08%
===========================================
Files 463 463
Lines 33727 33752 +25
===========================================
- Hits 16187 16173 -14
- Misses 16237 16271 +34
- Partials 1303 1308 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes static-directory routing initialization by building the router chain at static.NewDirectory creation time, so router-based behaviors (notably Tag Router) can take effect when no registry is used (Fixes #3222).
Changes:
- Call
BuildRouterChainduring static directory construction instead of only setting invokers on the default chain. - Update multiple cluster tests to blank-import the Tag Router so router factories are registered during test runs.
- Tidy
go.modto markgithub.com/cenkalti/backoff/v4as a direct dependency.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| go.mod | Moves cenkalti/backoff/v4 to direct require (matches direct imports in code). |
| cluster/directory/static/directory.go | Builds router chain during static directory creation. |
| cluster/directory/static/directory_test.go | Adds Tag Router blank import for router-factory registration in tests. |
| cluster/cluster/available/cluster_invoker_test.go | Adds Tag Router blank import for router-factory registration in tests. |
| cluster/cluster/broadcast/cluster_invoker_test.go | Adds Tag Router blank import for router-factory registration in tests. |
| cluster/cluster/failback/cluster_test.go | Adds Tag Router blank import for router-factory registration in tests. |
| cluster/cluster/failfast/cluster_test.go | Adds Tag Router blank import for router-factory registration in tests. |
| cluster/cluster/failover/cluster_test.go | Adds Tag Router blank import for router-factory registration in tests. |
| cluster/cluster/failover/cluster_invoker_test.go | Adds Tag Router blank import for router-factory registration in tests. |
| cluster/cluster/failsafe/cluster_test.go | Adds Tag Router blank import for router-factory registration in tests. |
| cluster/cluster/forking/cluster_test.go | Adds Tag Router blank import for router-factory registration in tests. |
| cluster/cluster/zoneaware/cluster_invoker_test.go | Adds Tag Router blank import for router-factory registration in tests. |
Comments suppressed due to low confidence (1)
cluster/directory/static/directory_test.go:34
- The tests in this file still only assert that
List()returns all invokers; they don’t validate the regression fixed by this PR (router chain being built for static directories). Consider extendingTestStaticDirList(or adding a new test) to configure tag-based routing (e.g., setdubbo.tagon invoker URLs and setinvocationattachmentdubbo.tag) and assert thatList()returns only the routed subset. That would fail under the old implementation and pass withBuildRouterChain.
import (
_ "dubbo.apache.org/dubbo-go/v3/cluster/router/tag"
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/protocol/base"
"dubbo.apache.org/dubbo-go/v3/protocol/invocation"
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| err := dir.BuildRouterChain(invokers, url) | ||
| if err != nil { | ||
| logger.Error(err) |
There was a problem hiding this comment.
BuildRouterChain returns an error for len(invokers)==0, and NewDirectory logs it as an error. If NewDirectory can be called with an empty invoker list (e.g., during startup or transient states), this will introduce noisy error logs for a non-exceptional condition. Consider skipping router-chain building (and/or logging at debug level) when len(invokers)==0.
| err := dir.BuildRouterChain(invokers, url) | |
| if err != nil { | |
| logger.Error(err) | |
| if len(invokers) > 0 { | |
| if err := dir.BuildRouterChain(invokers, url); err != nil { | |
| logger.Error(err) | |
| } |
| clusterpkg "dubbo.apache.org/dubbo-go/v3/cluster/cluster" | ||
| "dubbo.apache.org/dubbo-go/v3/cluster/directory/static" | ||
| "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance/random" | ||
| _ "dubbo.apache.org/dubbo-go/v3/cluster/router/tag" |
There was a problem hiding this comment.
The new blank import of cluster/router/tag is duplicated within the same failover test package (it’s also imported in cluster_invoker_test.go). Only one blank import is needed per package; consider keeping it in a single shared _test.go (e.g., init_test.go) to avoid repetition.
| _ "dubbo.apache.org/dubbo-go/v3/cluster/router/tag" |
| dir.RouterChain().SetInvokers(invokers) | ||
| err := dir.BuildRouterChain(invokers, url) | ||
| if err != nil { | ||
| logger.Error(err) |
There was a problem hiding this comment.
NewDirectory now calls BuildRouterChain and only logs on error, but does not fall back to setting the router chain invokers. If chain.NewRouterChain(url) fails (e.g., no router factories registered), dir.RouterChain() remains the default empty chain.RouterChain{} with no invokers, so List() will route against an empty chain and can return an empty slice even though dir.invokers is populated. Consider always calling dir.RouterChain().SetInvokers(invokers) (or setting invokers on the existing chain) as a fallback when BuildRouterChain fails, so behavior matches the previous implementation when routing is unavailable.
| logger.Error(err) | |
| logger.Error(err) | |
| // Fallback: ensure any existing router chain still sees the invokers | |
| if routerChain := dir.RouterChain(); routerChain != nil { | |
| routerChain.SetInvokers(invokers) | |
| } |



Description
Fixes #3222
Call BuildRouterChain method when creating static directory to ensure router capabilities work properly.
Currently, dubbo-go does not support static router configuration, with the exception of the Tag Router. (Pending #3219 to support this).
Checklist
develop