Skip to content

Commit

Permalink
refactor: remove providers and add prefix when use polaris (#2274)
Browse files Browse the repository at this point in the history
* fix:issue #2216

* fix:issue #2216

* fix:注册服务信息不带前缀

* refactor:remove providers: prefix when use polaris

* refactor:remove providers: prefix when use polaris
  • Loading branch information
chuntaojun authored May 11, 2023
1 parent 4b13d2b commit 8f8f514
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 43 deletions.
2 changes: 1 addition & 1 deletion cluster/router/polaris/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func getService(url *common.URL) string {
}
}

service := "providers:" + url.Service()
service := url.Interface()
if applicationMode {
service = config.GetApplicationConfig().Name
}
Expand Down
4 changes: 3 additions & 1 deletion common/constant/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

package constant

import "math"
import (
"math"
)

const (
Dubbo = "dubbo"
Expand Down
2 changes: 1 addition & 1 deletion filter/polaris/limit/limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (pl *polarisTpsLimiter) buildQuotaRequest(url *common.URL, invoaction proto
}
}

svc := "providers:" + url.Service()
svc := url.Interface()
method := invoaction.MethodName()
if applicationMode {
svc = config.GetApplicationConfig().Name
Expand Down
3 changes: 2 additions & 1 deletion protocol/dubbo3/dubbo3_invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ import (

import (
"github.com/dubbogo/gost/log/logger"
"github.com/dustin/go-humanize"

"github.com/dubbogo/grpc-go/metadata"

tripleConstant "github.com/dubbogo/triple/pkg/common/constant"
triConfig "github.com/dubbogo/triple/pkg/config"
"github.com/dubbogo/triple/pkg/triple"

"github.com/dustin/go-humanize"
)

import (
Expand Down
3 changes: 2 additions & 1 deletion protocol/dubbo3/dubbo3_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ import (

import (
"github.com/dubbogo/gost/log/logger"
"github.com/dustin/go-humanize"

"github.com/dubbogo/grpc-go"
"github.com/dubbogo/grpc-go/metadata"

tripleConstant "github.com/dubbogo/triple/pkg/common/constant"
triConfig "github.com/dubbogo/triple/pkg/config"
"github.com/dubbogo/triple/pkg/triple"

"github.com/dustin/go-humanize"
)

import (
Expand Down
1 change: 1 addition & 0 deletions protocol/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

import (
"github.com/dubbogo/gost/log/logger"

"github.com/dustin/go-humanize"

"github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc"
Expand Down
3 changes: 2 additions & 1 deletion protocol/grpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ package grpc
import (
"context"
"fmt"
"github.com/dustin/go-humanize"
"testing"
)

import (
"github.com/dustin/go-humanize"

"github.com/stretchr/testify/assert"
)

Expand Down
1 change: 1 addition & 0 deletions protocol/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

import (
"github.com/dubbogo/gost/log/logger"

"github.com/dustin/go-humanize"

"github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc"
Expand Down
19 changes: 11 additions & 8 deletions registry/polaris/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ type polarisRegistry struct {

// Register will register the service @url to its polaris registry center.
func (pr *polarisRegistry) Register(url *common.URL) error {
if getCategory(url) != "providers" {
return nil
}

serviceName := getServiceName(url)
serviceName := url.Interface()
request := createRegisterParam(url, serviceName)
request.Namespace = pr.namespace
resp, err := pr.provider.RegisterInstance(request)
Expand All @@ -115,11 +118,11 @@ func (pr *polarisRegistry) Register(url *common.URL) error {
}

// UnRegister returns nil if unregister successfully. If not, returns an error.
func (pr *polarisRegistry) UnRegister(conf *common.URL) error {
request := createDeregisterParam(conf, getServiceName(conf))
func (pr *polarisRegistry) UnRegister(url *common.URL) error {
request := createDeregisterParam(url, url.Interface())
request.Namespace = pr.namespace
if err := pr.provider.Deregister(request); err != nil {
return perrors.WithMessagef(err, "register(conf:%+v)", conf)
return perrors.WithMessagef(err, "fail to deregister(conf:%+v)", url)
}
return nil
}
Expand All @@ -135,7 +138,7 @@ func (pr *polarisRegistry) Subscribe(url *common.URL, notifyListener registry.No
defer timer.Stop()

for {
serviceName := getSubscribeName(url)
serviceName := url.Interface()
watcher, err := pr.createPolarisWatcher(serviceName)
if err != nil {
logger.Warnf("getwatcher() = err:%v", perrors.WithStack(err))
Expand Down Expand Up @@ -174,9 +177,9 @@ func (pr *polarisRegistry) UnSubscribe(url *common.URL, notifyListener registry.

// LoadSubscribeInstances load subscribe instance
func (pr *polarisRegistry) LoadSubscribeInstances(url *common.URL, notify registry.NotifyListener) error {
serviceName := getSubscribeName(url)
resp, err := pr.consumer.GetAllInstances(&api.GetAllInstancesRequest{
GetAllInstancesRequest: model.GetAllInstancesRequest{
serviceName := url.Interface()
resp, err := pr.consumer.GetInstances(&api.GetInstancesRequest{
GetInstancesRequest: model.GetInstancesRequest{
Service: serviceName,
Namespace: pr.namespace,
},
Expand Down
28 changes: 0 additions & 28 deletions registry/polaris/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
package polaris

import (
"bytes"
"fmt"
"strconv"
"strings"
)

import (
Expand All @@ -45,29 +43,3 @@ func getCategory(url *common.URL) string {
category := common.DubboNodes[role]
return category
}

// just copy from dubbo-go for nacos
func getServiceName(url *common.URL) string {
var buffer bytes.Buffer

buffer.Write([]byte(getCategory(url)))
appendParam(&buffer, url, constant.InterfaceKey)
return buffer.String()
}

func getSubscribeName(url *common.URL) string {
var buffer bytes.Buffer

buffer.Write([]byte(common.DubboNodes[common.PROVIDER]))
appendParam(&buffer, url, constant.InterfaceKey)
return buffer.String()
}

// just copy from dubbo-go for nacos
func appendParam(target *bytes.Buffer, url *common.URL, key string) {
value := url.GetParam(key, "")
target.Write([]byte(constant.PolarisServiceNameSeparator))
if strings.TrimSpace(value) != "" {
target.Write([]byte(value))
}
}
3 changes: 2 additions & 1 deletion tools/dubbogo-cli/cmd/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import (
)

import (
"github.com/spf13/cobra"
"github.com/olekukonko/tablewriter"

"github.com/spf13/cobra"
)

import (
Expand Down

0 comments on commit 8f8f514

Please sign in to comment.