Skip to content

Commit

Permalink
fix:修复路由规则针对老SDK的不兼容下发问题 (#1362)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntaojun authored Jul 1, 2024
1 parent 0cc8c88 commit 82eb9d0
Show file tree
Hide file tree
Showing 89 changed files with 3,633 additions and 1,690 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ jobs:
bash test/codecov.sh
- name: Upload Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
34 changes: 32 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
password: ${{ secrets.POLARIS_DOCKER_PASSWORD }}

- name: Build Server
id: build-server
id: build-hub-server
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
Expand All @@ -63,7 +63,7 @@ jobs:
make build-docker IMAGE_TAG=${DOCKER_TAG}
- name: Build Prometheus
id: build-prom
id: build-hub-prom
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
Expand All @@ -72,3 +72,33 @@ jobs:
cd release/standalone/docker/prometheus
ls -lstrh
bash build_docker_prom.sh ${DOCKER_TAG}
- name: Log in to Tencent CCR
uses: docker/login-action@v1
with:
registry: ccr.ccs.tencentyun.com
username: ${{ secrets.TENCENT_DOCKER_NAME }}
password: ${{ secrets.TENCENT_DOCKER_PASSWORD }}

- name: Build Server
id: build-tencent-server
env:
DOCKER_REPOSITORY: ccr.ccs.tencentyun.com/polarismesh
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
DOCKER_TAG: ${{ steps.get_version.outputs.VERSION }}
run: |
ls -lstrh
make build-docker IMAGE_TAG=${DOCKER_TAG}
- name: Build Prometheus
id: build-tencent-prom
env:
DOCKER_REPOSITORY: ccr.ccs.tencentyun.com/polarismesh
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
DOCKER_TAG: ${{ steps.get_version.outputs.VERSION }}
run: |
cd release/standalone/docker/prometheus
ls -lstrh
bash build_docker_prom.sh ${DOCKER_TAG}
23 changes: 11 additions & 12 deletions apiserver/eurekaserver/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func TestCreateInstance(t *testing.T) {
time.Sleep(5 * time.Second)
instanceId := fmt.Sprintf("%s_%s_%d", appId, host, startPort)
code := eurekaSrv.deregisterInstance(context.Background(), namespace, appId, instanceId, false)
assert.Equal(t, api.ExecuteSuccess, code)
assert.Equal(t, api.ExecuteSuccess, code, fmt.Sprintf("%d", code))
time.Sleep(20 * time.Second)

deltaReq := restful.NewRequest(httpRequest)
Expand Down Expand Up @@ -244,18 +244,17 @@ func Test_EurekaWrite(t *testing.T) {
injectRestfulReqPathParameters(t, restfulReq, map[string]string{
ParamAppId: mockIns.AppName,
})
// 这里是异步注册
eurekaSrv.RegisterApplication(restfulReq, restful.NewResponse(mockRsp))
assert.Equal(t, http.StatusNoContent, mockRsp.statusCode)
assert.Equal(t, restfulReq.Attribute(statusCodeHeader), uint32(apimodel.Code_ExecuteSuccess))

time.Sleep(5 * time.Second)
saveIns, err := eurekaSrv.originDiscoverSvr.Cache().GetStore().GetInstance(mockIns.InstanceId)
_ = discoverSuit.CacheMgr().TestUpdate()
saveIns, err := discoverSuit.Storage.GetInstance(mockIns.InstanceId)
assert.NoError(t, err)
assert.NotNil(t, saveIns)

t.Run("UpdateStatus", func(t *testing.T) {
t.Run("StatusUnknown", func(t *testing.T) {
t.Run("01_StatusUnknown", func(t *testing.T) {
mockReq := httptest.NewRequest("", fmt.Sprintf("http://127.0.0.1:8761/eureka/v2/apps/%s/%s/status",
mockIns.AppName, mockIns.InstanceId), nil)
mockReq.PostForm = url.Values{}
Expand All @@ -278,7 +277,7 @@ func Test_EurekaWrite(t *testing.T) {
assert.False(t, saveIns.Isolate())
})

t.Run("StatusDown", func(t *testing.T) {
t.Run("02_StatusDown", func(t *testing.T) {
mockReq := httptest.NewRequest("", fmt.Sprintf("http://127.0.0.1:8761/eureka/v2/apps/%s/%s/status",
mockIns.AppName, mockIns.InstanceId), nil)
mockReq.PostForm = url.Values{}
Expand All @@ -301,7 +300,7 @@ func Test_EurekaWrite(t *testing.T) {
assert.Equal(t, StatusDown, saveIns.Proto.Metadata[InternalMetadataStatus])
})

t.Run("StatusUp", func(t *testing.T) {
t.Run("03_StatusUp", func(t *testing.T) {
mockReq := httptest.NewRequest("", fmt.Sprintf("http://127.0.0.1:8761/eureka/v2/apps/%s/%s/status",
mockIns.AppName, mockIns.InstanceId), nil)
mockReq.PostForm = url.Values{}
Expand All @@ -324,17 +323,17 @@ func Test_EurekaWrite(t *testing.T) {
assert.Equal(t, StatusUp, saveIns.Proto.Metadata[InternalMetadataStatus])
})

t.Run("Polaris_UpdateInstances", func(t *testing.T) {
t.Run("04_Polaris_UpdateInstances", func(t *testing.T) {
defer func() {
rsp := discoverSuit.OriginDiscoverServer().UpdateInstances(discoverSuit.DefaultCtx, []*service_manage.Instance{
rsp := discoverSuit.DiscoverServer().UpdateInstances(discoverSuit.DefaultCtx, []*service_manage.Instance{
{
Id: wrapperspb.String(mockIns.InstanceId),
Isolate: wrapperspb.Bool(false),
},
})
assert.Equal(t, apimodel.Code_ExecuteSuccess, apimodel.Code(rsp.GetCode().GetValue()))
}()
rsp := discoverSuit.OriginDiscoverServer().UpdateInstances(discoverSuit.DefaultCtx, []*service_manage.Instance{
rsp := discoverSuit.DiscoverServer().UpdateInstances(discoverSuit.DefaultCtx, []*service_manage.Instance{
{
Id: wrapperspb.String(mockIns.InstanceId),
Isolate: wrapperspb.Bool(true),
Expand All @@ -349,8 +348,8 @@ func Test_EurekaWrite(t *testing.T) {
assert.Equal(t, StatusOutOfService, saveIns.Proto.Metadata[InternalMetadataStatus])
})

t.Run("Polaris_UpdateInstancesIsolate", func(t *testing.T) {
rsp := discoverSuit.OriginDiscoverServer().UpdateInstances(discoverSuit.DefaultCtx, []*service_manage.Instance{
t.Run("05_Polaris_UpdateInstancesIsolate", func(t *testing.T) {
rsp := discoverSuit.DiscoverServer().UpdateInstances(discoverSuit.DefaultCtx, []*service_manage.Instance{
{
Id: wrapperspb.String(mockIns.InstanceId),
Isolate: wrapperspb.Bool(true),
Expand Down
2 changes: 1 addition & 1 deletion apiserver/eurekaserver/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type (
func (h *EurekaServer) registerInstanceChain() {
svr := h.originDiscoverSvr.(*service.Server)
svr.AddInstanceChain(&EurekaInstanceChain{
s: h.namingServer.Cache().GetStore(),
s: svr.Store(),
})
}

Expand Down
4 changes: 3 additions & 1 deletion apiserver/eurekaserver/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/polarismesh/polaris/common/model"
commonstore "github.com/polarismesh/polaris/common/store"
"github.com/polarismesh/polaris/common/utils"
"github.com/polarismesh/polaris/service"
)

func checkOrBuildNewInstanceId(appId string, instId string, generateUniqueInstId bool) string {
Expand Down Expand Up @@ -256,7 +257,8 @@ func (h *EurekaServer) updateStatus(
})
instanceId = checkOrBuildNewInstanceIdByNamespace(namespace, h.namespace, appId, instanceId, h.generateUniqueInstId)

saveIns, err := h.originDiscoverSvr.Cache().GetStore().GetInstance(instanceId)
svr := h.originDiscoverSvr.(*service.Server)
saveIns, err := svr.Store().GetInstance(instanceId)
if err != nil {
eurekalog.Error("[EUREKA-SERVER] get instance from store when update status", zap.Error(err))
return uint32(commonstore.StoreCode2APICode(err))
Expand Down
10 changes: 5 additions & 5 deletions apiserver/nacosserver/core/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"golang.org/x/sync/singleflight"

nacosmodel "github.com/polarismesh/polaris/apiserver/nacosserver/model"
"github.com/polarismesh/polaris/cache"
cachetypes "github.com/polarismesh/polaris/cache/api"
"github.com/polarismesh/polaris/common/eventhub"
"github.com/polarismesh/polaris/common/model"
commontime "github.com/polarismesh/polaris/common/time"
Expand All @@ -50,7 +50,7 @@ type (
ins []*nacosmodel.Instance, healthyCount int32) *nacosmodel.ServiceInfo
)

func NewNacosDataStorage(cacheMgr *cache.CacheManager) *NacosDataStorage {
func NewNacosDataStorage(cacheMgr cachetypes.CacheManager) *NacosDataStorage {
ctx, cancel := context.WithCancel(context.Background())
notifier, notifierFinish := context.WithCancel(context.Background())
store := &NacosDataStorage{
Expand All @@ -67,7 +67,7 @@ func NewNacosDataStorage(cacheMgr *cache.CacheManager) *NacosDataStorage {

// NacosDataStorage .
type NacosDataStorage struct {
cacheMgr *cache.CacheManager
cacheMgr cachetypes.CacheManager
ctx context.Context
cancel context.CancelFunc

Expand All @@ -82,7 +82,7 @@ type NacosDataStorage struct {
revisions map[string]string
}

func (n *NacosDataStorage) Cache() *cache.CacheManager {
func (n *NacosDataStorage) Cache() cachetypes.CacheManager {
return n.cacheMgr
}

Expand Down Expand Up @@ -343,7 +343,7 @@ func SelectInstancesWithHealthyProtection(ctx *FilterContext, result *nacosmodel
return result
}

func ToNacosService(cacheMgr *cache.CacheManager, namespace, service, group string) *nacosmodel.ServiceMetadata {
func ToNacosService(cacheMgr cachetypes.CacheManager, namespace, service, group string) *nacosmodel.ServiceMetadata {
ret := &nacosmodel.ServiceMetadata{
ServiceKey: nacosmodel.ServiceKey{
Namespace: namespace,
Expand Down
4 changes: 2 additions & 2 deletions apiserver/nacosserver/v1/config/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/polarismesh/polaris/apiserver/nacosserver/core"
"github.com/polarismesh/polaris/apiserver/nacosserver/v2/remote"
"github.com/polarismesh/polaris/auth"
"github.com/polarismesh/polaris/cache"
cachetypes "github.com/polarismesh/polaris/cache/api"
"github.com/polarismesh/polaris/config"
"github.com/polarismesh/polaris/namespace"
)
Expand All @@ -45,7 +45,7 @@ type ConfigServer struct {
namespaceSvr namespace.NamespaceOperateServer
configSvr config.ConfigCenterServer
originConfigSvr config.ConfigCenterServer
cacheSvr *cache.CacheManager
cacheSvr cachetypes.CacheManager
}

func (h *ConfigServer) Initialize(opt *ServerOption) error {
Expand Down
4 changes: 3 additions & 1 deletion apiserver/nacosserver/v1/discover/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/polarismesh/polaris/apiserver/nacosserver/model"
commonmodel "github.com/polarismesh/polaris/common/model"
"github.com/polarismesh/polaris/common/utils"
"github.com/polarismesh/polaris/service"
)

func (n *DiscoverServer) handleRegister(ctx context.Context, namespace, serviceName string, ins *model.Instance) error {
Expand All @@ -57,7 +58,8 @@ func (n *DiscoverServer) handleUpdate(ctx context.Context, namespace, serviceNam
}
specIns.Id = wrapperspb.String(insId)
}
saveIns, err := n.discoverSvr.Cache().GetStore().GetInstance(specIns.GetId().GetValue())
svr := n.discoverSvr.(*service.Server)
saveIns, err := svr.Store().GetInstance(specIns.GetId().GetValue())
if err != nil {
return &model.NacosError{
ErrCode: int32(model.ExceptionCode_ServerError),
Expand Down
4 changes: 2 additions & 2 deletions apiserver/nacosserver/v2/config/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
nacospb "github.com/polarismesh/polaris/apiserver/nacosserver/v2/pb"
"github.com/polarismesh/polaris/apiserver/nacosserver/v2/remote"
"github.com/polarismesh/polaris/auth"
"github.com/polarismesh/polaris/cache"
cachetypes "github.com/polarismesh/polaris/cache/api"
"github.com/polarismesh/polaris/config"
"github.com/polarismesh/polaris/namespace"
)
Expand All @@ -49,7 +49,7 @@ type ConfigServer struct {
namespaceSvr namespace.NamespaceOperateServer
configSvr config.ConfigCenterServer
originConfigSvr config.ConfigCenterServer
cacheSvr *cache.CacheManager
cacheSvr cachetypes.CacheManager
handleRegistry map[string]*remote.RequestHandlerWarrper
}

Expand Down
10 changes: 6 additions & 4 deletions apiserver/nacosserver/v2/discover/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

nacosmodel "github.com/polarismesh/polaris/apiserver/nacosserver/model"
"github.com/polarismesh/polaris/apiserver/nacosserver/v2/remote"
"github.com/polarismesh/polaris/cache"
cachetypes "github.com/polarismesh/polaris/cache/api"
"github.com/polarismesh/polaris/common/eventhub"
"github.com/polarismesh/polaris/common/model"
"github.com/polarismesh/polaris/common/utils"
Expand All @@ -44,7 +44,7 @@ type Checker struct {
discoverSvr service.DiscoverServer
healthSvr *healthcheck.Server

cacheMgr *cache.CacheManager
cacheMgr cachetypes.CacheManager
connMgr *remote.ConnectionManager
clientMgr *ConnectionClientManager

Expand Down Expand Up @@ -192,6 +192,8 @@ func (c *Checker) runCheck(ctx context.Context) {
// BUT: 一个实例 T1 时刻对应长连接为 Conn-1,T2 时刻对应的长连接为 Conn-2,但是在 T1 ~ T2 之间的某个时刻检测发现长连接不存在
// 此时发起一个反注册请求,该请求在 T3 时刻发起,是否会影响 T2 时刻注册上来的实例?
func (c *Checker) realCheck() {
svr := c.discoverSvr.(*service.Server)

defer func() {
if err := recover(); err != nil {
var buf [4086]byte
Expand Down Expand Up @@ -267,7 +269,7 @@ func (c *Checker) realCheck() {
}
nacoslog.Info("[NACOS-V2][Checker] batch set instance health_status to unhealthy",
zap.Any("instance-ids", ids))
if err := c.discoverSvr.Cache().GetStore().
if err := svr.Store().
BatchSetInstanceHealthStatus(ids, model.StatusBoolToInt(false), utils.NewUUID()); err != nil {
nacoslog.Error("[NACOS-V2][Checker] batch set instance health_status to unhealthy",
zap.Any("instance-ids", ids), zap.Error(err))
Expand All @@ -281,7 +283,7 @@ func (c *Checker) realCheck() {
}
nacoslog.Info("[NACOS-V2][Checker] batch set instance health_status to healty",
zap.Any("instance-ids", ids))
if err := c.discoverSvr.Cache().GetStore().
if err := svr.Store().
BatchSetInstanceHealthStatus(ids, model.StatusBoolToInt(true), utils.NewUUID()); err != nil {
nacoslog.Error("[NACOS-V2][Checker] batch set instance health_status to healty",
zap.Any("instance-ids", ids), zap.Error(err))
Expand Down
6 changes: 3 additions & 3 deletions auth/user/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (svr *Server) UpdateGroup(ctx context.Context, req *apisecurity.ModifyUserG
return errResp
}

modifyReq, needUpdate := updateGroupAttribute(ctx, data.UserGroup, req)
modifyReq, needUpdate := UpdateGroupAttribute(ctx, data.UserGroup, req)
if !needUpdate {
log.Info("update group data no change, no need update",
utils.RequestID(ctx), zap.String("group", req.String()))
Expand Down Expand Up @@ -385,8 +385,8 @@ func (svr *Server) checkUpdateGroup(ctx context.Context, req *apisecurity.Modify
return nil
}

// updateGroupAttribute 更新计算用户组更新时的结构体数据,并判断是否需要执行更新操作
func updateGroupAttribute(ctx context.Context, old *model.UserGroup, newUser *apisecurity.ModifyUserGroup) (
// UpdateGroupAttribute 更新计算用户组更新时的结构体数据,并判断是否需要执行更新操作
func UpdateGroupAttribute(ctx context.Context, old *model.UserGroup, newUser *apisecurity.ModifyUserGroup) (
*model.ModifyUserGroup, bool) {
var (
needUpdate bool
Expand Down
27 changes: 27 additions & 0 deletions auth/user/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/golang/mock/gomock"
"github.com/golang/protobuf/ptypes/wrappers"
apimodel "github.com/polarismesh/specification/source/go/api/v1/model"
apisecurity "github.com/polarismesh/specification/source/go/api/v1/security"
"github.com/stretchr/testify/assert"

Expand Down Expand Up @@ -318,6 +319,32 @@ func Test_server_CreateUsers(t *testing.T) {
})
}

func Test_server_Login(t *testing.T) {

userTest := newUserTest(t)
defer userTest.Clean()

t.Run("正常登陆", func(t *testing.T) {
rsp := userTest.svr.Login(&apisecurity.LoginRequest{
Name: &wrappers.StringValue{Value: userTest.users[0].Name},
Password: &wrappers.StringValue{Value: "polaris"},
})

assert.True(t, api.IsSuccess(rsp), rsp.GetInfo().GetValue())
})

t.Run("错误的密码", func(t *testing.T) {
rsp := userTest.svr.Login(&apisecurity.LoginRequest{
Name: &wrappers.StringValue{Value: userTest.users[0].Name},
Password: &wrappers.StringValue{Value: "polaris_123"},
})

assert.False(t, api.IsSuccess(rsp), rsp.GetInfo().GetValue())
assert.Equal(t, uint32(apimodel.Code_NotAllowedAccess), rsp.GetCode().GetValue())
assert.Contains(t, rsp.GetInfo().GetValue(), model.ErrorWrongUsernameOrPassword.Error())
})
}

func Test_server_UpdateUser(t *testing.T) {

userTest := newUserTest(t)
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ func polarisServiceRegister(polarisService *boot_config.PolarisService, apiServe
// selfRegister 服务自注册
func selfRegister(
host string, port uint32, protocol string, isolated bool, polarisService *boot_config.Service, hbInterval int) error {
server, err := service.GetOriginServer()
server, err := service.GetServer()
if err != nil {
return err
}
Expand Down Expand Up @@ -609,7 +609,7 @@ func selfRegister(
Metadata: metadata,
}

resp := server.CreateInstance(genContext(), req)
resp := server.RegisterInstance(genContext(), req)
if api.CalcCode(resp) != 200 {
// 如果self之前注册过,那么可以忽略
if resp.GetCode().GetValue() != api.ExistedResource {
Expand Down
Loading

0 comments on commit 82eb9d0

Please sign in to comment.