Skip to content

fix(router): call BuildRouterChain method when creating directory.#3225

Open
yangpixi wants to merge 4 commits intoapache:developfrom
yangpixi:fix-static-routerChain
Open

fix(router): call BuildRouterChain method when creating directory.#3225
yangpixi wants to merge 4 commits intoapache:developfrom
yangpixi:fix-static-routerChain

Conversation

@yangpixi
Copy link

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

  • I confirm the target branch is develop
  • Code has passed local testing
  • I have added tests that prove my fix is effective or that my feature works

@yangpixi yangpixi changed the title fix(router): call BuildRouterChain method when creatiing directory. fix(router): call BuildRouterChain method when creating directory. Feb 28, 2026
@sonarqubecloud
Copy link

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.91%. Comparing base (35ea886) to head (664bce8).
⚠️ Report is 7 commits behind head on develop.

Files with missing lines Patch % Lines
cluster/directory/static/directory.go 33.33% 1 Missing and 1 partial ⚠️
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.
📢 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.

@AlexStocks AlexStocks requested review from Alanxtl, No-SilverBullet and Copilot and removed request for Alanxtl and Copilot February 28, 2026 16:43
@AlexStocks AlexStocks added the 3.3.2 version 3.3.2 label Feb 28, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 BuildRouterChain during 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.mod to mark github.com/cenkalti/backoff/v4 as 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 extending TestStaticDirList (or adding a new test) to configure tag-based routing (e.g., set dubbo.tag on invoker URLs and set invocation attachment dubbo.tag) and assert that List() returns only the routed subset. That would fail under the old implementation and pass with BuildRouterChain.
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.

Comment on lines +50 to +52
err := dir.BuildRouterChain(invokers, url)
if err != nil {
logger.Error(err)
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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)
}

Copilot uses AI. Check for mistakes.
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"
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
_ "dubbo.apache.org/dubbo-go/v3/cluster/router/tag"

Copilot uses AI. Check for mistakes.
dir.RouterChain().SetInvokers(invokers)
err := dir.BuildRouterChain(invokers, url)
if err != nil {
logger.Error(err)
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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)
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.3.2 version 3.3.2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants