You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by ju...@apache.org on 2023/02/01 06:12:40 UTC
[dubbo-go] 01/02: [ISSUE #2172] Fix/polaris governance (#2171)
This is an automated email from the ASF dual-hosted git repository.
justxuewei pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
commit 8279453df4f053bde7b6a5514828e13b3579506e
Author: liaochuntao <li...@live.com>
AuthorDate: Sun Jan 1 13:18:08 2023 +0800
[ISSUE #2172] Fix/polaris governance (#2171)
* 解决 consumer 不断重连已下线的 provider meta service 问题 (#2166)
* registry type support all
* fix test
* set default to interface
* use default protocol registry
* fix unit test
* use swith to judge
* add registry support all test
* Resolve registry name conflicts
* fix ut err
* fix https://github.com/apache/dubbo-go/issues/2159
* del front
* del front
Co-authored-by: bobtthp <bo...@bob-Mac-mini.local>
Co-authored-by: bob <bo...@bobdeMacBook-Pro.local>
Co-authored-by: bobtthp <bo...@bob1.local>
Co-authored-by: bob <bo...@bob.local>
* build(deps): bump github.com/hashicorp/vault/sdk from 0.6.0 to 0.6.2 (#2169)
Bumps [github.com/hashicorp/vault/sdk](https://github.com/hashicorp/vault) from 0.6.0 to 0.6.2.
- [Release notes](https://github.com/hashicorp/vault/releases)
- [Changelog](https://github.com/hashicorp/vault/blob/main/CHANGELOG.md)
- [Commits](https://github.com/hashicorp/vault/compare/v0.6.0...v0.6.2)
---
updated-dependencies:
- dependency-name: github.com/hashicorp/vault/sdk
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <su...@github.com>
Signed-off-by: dependabot[bot] <su...@github.com>
Co-authored-by: dependabot[bot] <49...@users.noreply.github.com>
* refactor:polaris ability open judge
* refactor:polaris ability open judge
Signed-off-by: dependabot[bot] <su...@github.com>
Co-authored-by: bobtthp <gz...@gmail.com>
Co-authored-by: bobtthp <bo...@bob-Mac-mini.local>
Co-authored-by: bob <bo...@bobdeMacBook-Pro.local>
Co-authored-by: bobtthp <bo...@bob1.local>
Co-authored-by: bob <bo...@bob.local>
Co-authored-by: dependabot[bot] <49...@users.noreply.github.com>
---
cluster/router/polaris/router.go | 19 ++++++++++++++++++-
filter/polaris/limit/limiter.go | 6 ++++++
remoting/polaris/builder.go | 38 ++++++++++++++++++++++++++------------
3 files changed, 50 insertions(+), 13 deletions(-)
diff --git a/cluster/router/polaris/router.go b/cluster/router/polaris/router.go
index ab71ab3dd..d29636dd7 100644
--- a/cluster/router/polaris/router.go
+++ b/cluster/router/polaris/router.go
@@ -53,6 +53,12 @@ var (
)
func newPolarisRouter() (*polarisRouter, error) {
+ if err := remotingpolaris.Check(); errors.Is(err, remotingpolaris.ErrorNoOpenPolarisAbility) {
+ return &polarisRouter{
+ openRoute: false,
+ }, nil
+ }
+
routerAPI, err := remotingpolaris.GetRouterAPI()
if err != nil {
return nil, err
@@ -63,12 +69,15 @@ func newPolarisRouter() (*polarisRouter, error) {
}
return &polarisRouter{
+ openRoute: true,
routerAPI: routerAPI,
consumerAPI: consumerAPI,
}, nil
}
type polarisRouter struct {
+ openRoute bool
+
routerAPI polaris.RouterAPI
consumerAPI polaris.ConsumerAPI
@@ -82,8 +91,13 @@ type polarisRouter struct {
func (p *polarisRouter) Route(invokers []protocol.Invoker, url *common.URL,
invoaction protocol.Invocation) []protocol.Invoker {
+ if !p.openRoute {
+ logger.Debug("[Router][Polaris] not open polaris route ability")
+ return invokers
+ }
+
if len(invokers) == 0 {
- logger.Warnf("[tag router] invokers from previous router is empty")
+ logger.Warn("[Router][Polaris] invokers from previous router is empty")
return invokers
}
@@ -280,6 +294,9 @@ func (p *polarisRouter) Priority() int64 {
// Notify the router the invoker list
func (p *polarisRouter) Notify(invokers []protocol.Invoker) {
+ if !p.openRoute {
+ return
+ }
if len(invokers) == 0 {
return
}
diff --git a/filter/polaris/limit/limiter.go b/filter/polaris/limit/limiter.go
index 47d70528d..4d68660f6 100644
--- a/filter/polaris/limit/limiter.go
+++ b/filter/polaris/limit/limiter.go
@@ -18,6 +18,7 @@
package limit
import (
+ "errors"
"fmt"
"time"
)
@@ -45,6 +46,11 @@ type polarisTpsLimiter struct {
}
func (pl *polarisTpsLimiter) IsAllowable(url *common.URL, invocation protocol.Invocation) bool {
+ if err := remotingpolaris.Check(); errors.Is(err, remotingpolaris.ErrorNoOpenPolarisAbility) {
+ logger.Debug("[TpsLimiter][Polaris] not open polaris ratelimit ability")
+ return true
+ }
+
var err error
pl.limitAPI, err = remotingpolaris.GetLimiterAPI()
diff --git a/remoting/polaris/builder.go b/remoting/polaris/builder.go
index f384345e1..389e80466 100644
--- a/remoting/polaris/builder.go
+++ b/remoting/polaris/builder.go
@@ -40,19 +40,21 @@ import (
)
var (
- once sync.Once
- namesapce string
- sdkCtx api.SDKContext
+ once sync.Once
+ namesapce string
+ sdkCtx api.SDKContext
+ openPolarisAbility bool
)
var (
- ErrorSDKContextNotInit = errors.New("polaris SDKContext not init")
+ ErrorNoOpenPolarisAbility = errors.New("polaris ability not open")
+ ErrorSDKContextNotInit = errors.New("polaris SDKContext not init")
)
// GetConsumerAPI creates one polaris ConsumerAPI instance
func GetConsumerAPI() (polaris.ConsumerAPI, error) {
- if sdkCtx == nil {
- return nil, ErrorSDKContextNotInit
+ if err := Check(); err != nil {
+ return nil, err
}
return polaris.NewConsumerAPIByContext(sdkCtx), nil
@@ -60,8 +62,8 @@ func GetConsumerAPI() (polaris.ConsumerAPI, error) {
// GetProviderAPI creates one polaris ProviderAPI instance
func GetProviderAPI() (polaris.ProviderAPI, error) {
- if sdkCtx == nil {
- return nil, ErrorSDKContextNotInit
+ if err := Check(); err != nil {
+ return nil, err
}
return polaris.NewProviderAPIByContext(sdkCtx), nil
@@ -69,8 +71,8 @@ func GetProviderAPI() (polaris.ProviderAPI, error) {
// GetRouterAPI create one polaris RouterAPI instance
func GetRouterAPI() (polaris.RouterAPI, error) {
- if sdkCtx == nil {
- return nil, ErrorSDKContextNotInit
+ if err := Check(); err != nil {
+ return nil, err
}
return polaris.NewRouterAPIByContext(sdkCtx), nil
@@ -78,13 +80,23 @@ func GetRouterAPI() (polaris.RouterAPI, error) {
// GetLimiterAPI creates one polaris LimiterAPI instance
func GetLimiterAPI() (polaris.LimitAPI, error) {
- if sdkCtx == nil {
- return nil, ErrorSDKContextNotInit
+ if err := Check(); err != nil {
+ return nil, err
}
return polaris.NewLimitAPIByContext(sdkCtx), nil
}
+func Check() error {
+ if !openPolarisAbility {
+ return ErrorNoOpenPolarisAbility
+ }
+ if sdkCtx == nil {
+ return ErrorSDKContextNotInit
+ }
+ return nil
+}
+
// GetNamespace gets user defined namespace info
func GetNamespace() string {
return namesapce
@@ -96,6 +108,8 @@ func InitSDKContext(url *common.URL) error {
return errors.New("url is empty!")
}
+ openPolarisAbility = true
+
var rerr error
once.Do(func() {
addresses := strings.Split(url.Location, ",")