Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dynamic route config #1519

Merged
merged 6 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cluster/directory/base/directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestBuildRouterChain(t *testing.T) {
regURL.AddParam(constant.INTERFACE_KEY, "mock-app")
directory := NewDirectory(regURL)
var err error
directory.routerChain, err = chain.NewRouterChain(regURL)
directory.routerChain, err = chain.NewRouterChain()
assert.Error(t, err)
}

Expand Down
3 changes: 1 addition & 2 deletions cluster/directory/static/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ func (dir *directory) BuildRouterChain(invokers []protocol.Invoker) error {
if len(invokers) == 0 {
return perrors.Errorf("invokers == null")
}
url := invokers[0].GetURL()
routerChain, e := chain.NewRouterChain(url)
routerChain, e := chain.NewRouterChain()
if e != nil {
return e
}
Expand Down
21 changes: 4 additions & 17 deletions cluster/router/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ import (
"dubbo.apache.org/dubbo-go/v3/protocol"
)

var (
virtualServiceConfigByte []byte
destinationRuleConfigByte []byte
)

// RouterChain Router chain
type RouterChain struct {
// Full list of addresses from registry, classified by method name.
Expand Down Expand Up @@ -106,14 +101,9 @@ func (c *RouterChain) copyInvokers() []protocol.Invoker {
return ret
}

func SetVSAndDRConfigByte(vs, dr []byte) {
virtualServiceConfigByte = vs
destinationRuleConfigByte = dr
}

// NewRouterChain Use url to init router chain
// NewRouterChain init router chain
// Loop routerFactories and call NewRouter method
func NewRouterChain(url *common.URL) (*RouterChain, error) {
func NewRouterChain() (*RouterChain, error) {
routerFactories := extension.GetRouterFactories()
if len(routerFactories) == 0 {
return nil, perrors.Errorf("No routerFactory exits , create one please")
Expand All @@ -122,12 +112,9 @@ func NewRouterChain(url *common.URL) (*RouterChain, error) {
routers := make([]router.PriorityRouter, 0, len(routerFactories))

for key, routerFactory := range routerFactories {
if virtualServiceConfigByte == nil || destinationRuleConfigByte == nil {
logger.Warnf("virtual Service ProtocolConfig or destinationRule Confi Byte may be empty, pls check your CONF_VIRTUAL_SERVICE_FILE_PATH and CONF_DEST_RULE_FILE_PATH env is correctly point to your yaml file\n")
}
r, err := routerFactory().NewPriorityRouter(virtualServiceConfigByte, destinationRuleConfigByte)
r, err := routerFactory().NewPriorityRouter()
if r == nil || err != nil {
logger.Errorf("router chain build router fail! routerFactories key:%s error:%vv", key, err)
logger.Errorf("router chain build router fail! routerFactories key:%s error:%v", key, err)
continue
}
routers = append(routers, r)
Expand Down
13 changes: 4 additions & 9 deletions cluster/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,20 @@ import (
"dubbo.apache.org/dubbo-go/v3/protocol"
)

// Extension - Router
// PriorityRouterFactory creates creates priority router with url
type PriorityRouterFactory interface {
// NewPriorityRouter creates router instance with URL
NewPriorityRouter([]byte, []byte) (PriorityRouter, error)
NewPriorityRouter() (PriorityRouter, error)
}

// Router
type router interface {
// PriorityRouter routes with priority
type PriorityRouter interface {
// Route Determine the target invokers list.
Route([]protocol.Invoker, *common.URL, protocol.Invocation) []protocol.Invoker

// URL Return URL in router
URL() *common.URL
}

// Router
type PriorityRouter interface {
router
// Priority Return Priority in router
// 0 to ^int(0) is better
Priority() int64
Expand All @@ -66,7 +61,7 @@ type Poolable interface {
// AddrPool is an address pool, backed by a snapshot of address list, divided into categories.
type AddrPool map[string]*roaring.Bitmap

// AddrMetadta is address metadata, collected from a snapshot of address list by a router, if it implements Poolable.
// AddrMetadata is address metadata, collected from a snapshot of address list by a router, if it implements Poolable.
type AddrMetadata interface {
// Source indicates where the metadata comes from.
Source() string
Expand Down
61 changes: 0 additions & 61 deletions cluster/router/v3router/dubbo_rule.go

This file was deleted.

9 changes: 7 additions & 2 deletions cluster/router/v3router/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ package v3router

import (
"dubbo.apache.org/dubbo-go/v3/cluster/router"
"dubbo.apache.org/dubbo-go/v3/common/extension"
)

func init() {
extension.SetRouterFactory("mesh", NewUniformRouterFactory)
}

// UniformRouteFactory is uniform router's factory
type UniformRouteFactory struct{}

Expand All @@ -30,6 +35,6 @@ func NewUniformRouterFactory() router.PriorityRouterFactory {
}

// NewPriorityRouter construct a new UniformRouteFactory as PriorityRouter
func (f *UniformRouteFactory) NewPriorityRouter(vsConfigBytes, distConfigBytes []byte) (router.PriorityRouter, error) {
return NewUniformRouterChain(vsConfigBytes, distConfigBytes)
func (f *UniformRouteFactory) NewPriorityRouter() (router.PriorityRouter, error) {
return NewUniformRouterChain()
}
35 changes: 0 additions & 35 deletions cluster/router/v3router/factory_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion cluster/router/v3router/k8s_api/listener_handler_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (

const (
VirtualServiceEventKey = "virtualServiceEventKey"
DestinationRuleEventKey = "destinationRuleEventKe3y"
DestinationRuleEventKey = "destinationRuleEventKey"

VirtualServiceResource = "virtualservices"
DestRuleResource = "destinationrules"
Expand Down
2 changes: 1 addition & 1 deletion cluster/router/v3router/k8s_crd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func NewK8sCRDClient(groupName, groupVersion, namespace string, handlers ...List
return newClient, nil
}

// func (c *Client) WatchResources() []cache.Store { can only be called once
// WatchResources can only be called once
func (c *Client) WatchResources() []cache.Store {
stores := make([]cache.Store, 0)
c.once.Do(
Expand Down
Loading