Skip to content

Commit

Permalink
Revert "[ISSUE #2172] Fix/polaris governance (#2171)" (#2200)
Browse files Browse the repository at this point in the history
This reverts commit c1a0698.
  • Loading branch information
justxuewei authored Feb 1, 2023
1 parent a645070 commit f797b0f
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 58 deletions.
19 changes: 1 addition & 18 deletions cluster/router/polaris/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ 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
Expand All @@ -69,15 +63,12 @@ func newPolarisRouter() (*polarisRouter, error) {
}

return &polarisRouter{
openRoute: true,
routerAPI: routerAPI,
consumerAPI: consumerAPI,
}, nil
}

type polarisRouter struct {
openRoute bool

routerAPI polaris.RouterAPI
consumerAPI polaris.ConsumerAPI

Expand All @@ -91,13 +82,8 @@ 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.Warn("[Router][Polaris] invokers from previous router is empty")
logger.Warnf("[tag router] invokers from previous router is empty")
return invokers
}

Expand Down Expand Up @@ -294,9 +280,6 @@ 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
}
Expand Down
6 changes: 0 additions & 6 deletions filter/polaris/limit/limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package limit

import (
"errors"
"fmt"
"time"
)
Expand Down Expand Up @@ -46,11 +45,6 @@ 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()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
github.com/google/go-cmp v0.5.9
github.com/gopherjs/gopherjs v0.0.0-20190910122728-9d188e94fb99 // indirect
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645
github.com/hashicorp/vault/sdk v0.6.2
github.com/hashicorp/vault/sdk v0.6.0
github.com/jinzhu/copier v0.3.5
github.com/knadh/koanf v1.4.4
github.com/magiconair/properties v1.8.7
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-plugin v1.0.1/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY=
github.com/hashicorp/go-plugin v1.4.5/go.mod h1:viDMjcLJuDui6pXb8U4HVfb8AamCWhHGUjr2IrTF67s=
github.com/hashicorp/go-plugin v1.4.3/go.mod h1:5fGEH17QVwTTcR0zV7yhDPLLmFX9YSZ38b18Udy6vYQ=
github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-retryablehttp v0.5.4/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
Expand All @@ -427,7 +427,7 @@ github.com/hashicorp/go-secure-stdlib/parseutil v0.1.6/go.mod h1:QmrqtbKuxxSWTN3
github.com/hashicorp/go-secure-stdlib/password v0.1.1/go.mod h1:9hH302QllNwu1o2TGYtSk8I8kTAN0ca1EHpwhm5Mmzo=
github.com/hashicorp/go-secure-stdlib/strutil v0.1.1/go.mod h1:gKOamz3EwoIoJq7mlMIRBpVTAUn8qPCrEclOKKWhD3U=
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2/go.mod h1:Gou2R9+il93BqX25LAKCLuM+y9U2T4hlwvT1yprcna4=
github.com/hashicorp/go-secure-stdlib/tlsutil v0.1.2/go.mod h1:l8slYwnJA26yBz+ErHpp2IRCLr0vuOMGBORIz4rRiAs=
github.com/hashicorp/go-secure-stdlib/tlsutil v0.1.1/go.mod h1:l8slYwnJA26yBz+ErHpp2IRCLr0vuOMGBORIz4rRiAs=
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
github.com/hashicorp/go-sockaddr v1.0.2/go.mod h1:rB4wwRAUzs07qva3c5SdrY/NEtAUjGlgmH/UkBUC97A=
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
Expand All @@ -451,8 +451,8 @@ github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/J
github.com/hashicorp/serf v0.9.6/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4=
github.com/hashicorp/vault/api v1.0.4/go.mod h1:gDcqh3WGcR1cpF5AJz/B1UFheUEneMoIospckxBxk6Q=
github.com/hashicorp/vault/sdk v0.1.13/go.mod h1:B+hVj7TpuQY1Y/GPbCpffmgd+tSEwvhkWnjtSYCaS2M=
github.com/hashicorp/vault/sdk v0.6.2 h1:LtWXUM+WheM5T8pOO/6nOTiFwnE+4y3bPztFf15Oz24=
github.com/hashicorp/vault/sdk v0.6.2/go.mod h1:KyfArJkhooyba7gYCKSq8v66QdqJmnbAxtV/OX1+JTs=
github.com/hashicorp/vault/sdk v0.6.0 h1:6Z+In5DXHiUfZvIZdMx7e2loL1PPyDjA4bVh9ZTIAhs=
github.com/hashicorp/vault/sdk v0.6.0/go.mod h1:+DRpzoXIdMvKc88R4qxr+edwy/RvH5QK8itmxLiDHLc=
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/hjson/hjson-go/v4 v4.0.0 h1:wlm6IYYqHjOdXH1gHev4VoXCaW20HdQAGCxdOEEg2cs=
Expand Down
2 changes: 0 additions & 2 deletions metadata/service/local/service_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ func (m *MetadataServiceProxy) GetMetadataInfo(revision string) (*common.Metadat
invocation.WithAttachments(map[string]interface{}{constant.AsyncKey: "false"}),
invocation.WithParameterValues([]reflect.Value{rV}))
res := m.invkr.Invoke(context.Background(), inv)
// when request finished, invoker will colse
defer m.invkr.Destroy()
if res.Error() != nil {
logger.Errorf("could not get the metadata info from remote provider: %v", res.Error())
return nil, res.Error()
Expand Down
7 changes: 6 additions & 1 deletion metadata/service/local_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ func NewBaseMetadataServiceProxyFactory(creator MetadataServiceProxyCreator) *Ba
}

func (b *BaseMetadataServiceProxyFactory) GetProxy(ins registry.ServiceInstance) MetadataService {
return b.creator(ins).(MetadataService)
key := ins.GetServiceName() + "##" + getExportedServicesRevision(ins)
if proxy, ok := b.proxies.Load(key); ok {
return proxy.(MetadataService)
}
v, _ := b.proxies.LoadOrStore(key, b.creator(ins))
return v.(MetadataService)
}

func getExportedServicesRevision(serviceInstance registry.ServiceInstance) string {
Expand Down
38 changes: 12 additions & 26 deletions remoting/polaris/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,63 +40,51 @@ import (
)

var (
once sync.Once
namesapce string
sdkCtx api.SDKContext
openPolarisAbility bool
once sync.Once
namesapce string
sdkCtx api.SDKContext
)

var (
ErrorNoOpenPolarisAbility = errors.New("polaris ability not open")
ErrorSDKContextNotInit = errors.New("polaris SDKContext not init")
ErrorSDKContextNotInit = errors.New("polaris SDKContext not init")
)

// GetConsumerAPI creates one polaris ConsumerAPI instance
func GetConsumerAPI() (polaris.ConsumerAPI, error) {
if err := Check(); err != nil {
return nil, err
if sdkCtx == nil {
return nil, ErrorSDKContextNotInit
}

return polaris.NewConsumerAPIByContext(sdkCtx), nil
}

// GetProviderAPI creates one polaris ProviderAPI instance
func GetProviderAPI() (polaris.ProviderAPI, error) {
if err := Check(); err != nil {
return nil, err
if sdkCtx == nil {
return nil, ErrorSDKContextNotInit
}

return polaris.NewProviderAPIByContext(sdkCtx), nil
}

// GetRouterAPI create one polaris RouterAPI instance
func GetRouterAPI() (polaris.RouterAPI, error) {
if err := Check(); err != nil {
return nil, err
if sdkCtx == nil {
return nil, ErrorSDKContextNotInit
}

return polaris.NewRouterAPIByContext(sdkCtx), nil
}

// GetLimiterAPI creates one polaris LimiterAPI instance
func GetLimiterAPI() (polaris.LimitAPI, error) {
if err := Check(); err != nil {
return nil, err
if sdkCtx == nil {
return nil, ErrorSDKContextNotInit
}

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
Expand All @@ -108,8 +96,6 @@ 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, ",")
Expand Down

0 comments on commit f797b0f

Please sign in to comment.