Skip to content

Commit 82eb9d0

Browse files
authored
fix:修复路由规则针对老SDK的不兼容下发问题 (polarismesh#1362)
1 parent 0cc8c88 commit 82eb9d0

File tree

89 files changed

+3633
-1690
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+3633
-1690
lines changed

.github/workflows/codecov.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,6 @@ jobs:
100100
bash test/codecov.sh
101101
102102
- name: Upload Codecov
103-
uses: codecov/codecov-action@v3
103+
uses: codecov/codecov-action@v4
104104
with:
105105
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/docker.yml

+32-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
password: ${{ secrets.POLARIS_DOCKER_PASSWORD }}
5454

5555
- name: Build Server
56-
id: build-server
56+
id: build-hub-server
5757
env:
5858
GOOS: ${{ matrix.goos }}
5959
GOARCH: ${{ matrix.goarch }}
@@ -63,7 +63,7 @@ jobs:
6363
make build-docker IMAGE_TAG=${DOCKER_TAG}
6464
6565
- name: Build Prometheus
66-
id: build-prom
66+
id: build-hub-prom
6767
env:
6868
GOOS: ${{ matrix.goos }}
6969
GOARCH: ${{ matrix.goarch }}
@@ -72,3 +72,33 @@ jobs:
7272
cd release/standalone/docker/prometheus
7373
ls -lstrh
7474
bash build_docker_prom.sh ${DOCKER_TAG}
75+
76+
- name: Log in to Tencent CCR
77+
uses: docker/login-action@v1
78+
with:
79+
registry: ccr.ccs.tencentyun.com
80+
username: ${{ secrets.TENCENT_DOCKER_NAME }}
81+
password: ${{ secrets.TENCENT_DOCKER_PASSWORD }}
82+
83+
- name: Build Server
84+
id: build-tencent-server
85+
env:
86+
DOCKER_REPOSITORY: ccr.ccs.tencentyun.com/polarismesh
87+
GOOS: ${{ matrix.goos }}
88+
GOARCH: ${{ matrix.goarch }}
89+
DOCKER_TAG: ${{ steps.get_version.outputs.VERSION }}
90+
run: |
91+
ls -lstrh
92+
make build-docker IMAGE_TAG=${DOCKER_TAG}
93+
94+
- name: Build Prometheus
95+
id: build-tencent-prom
96+
env:
97+
DOCKER_REPOSITORY: ccr.ccs.tencentyun.com/polarismesh
98+
GOOS: ${{ matrix.goos }}
99+
GOARCH: ${{ matrix.goarch }}
100+
DOCKER_TAG: ${{ steps.get_version.outputs.VERSION }}
101+
run: |
102+
cd release/standalone/docker/prometheus
103+
ls -lstrh
104+
bash build_docker_prom.sh ${DOCKER_TAG}

apiserver/eurekaserver/access_test.go

+11-12
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func TestCreateInstance(t *testing.T) {
197197
time.Sleep(5 * time.Second)
198198
instanceId := fmt.Sprintf("%s_%s_%d", appId, host, startPort)
199199
code := eurekaSrv.deregisterInstance(context.Background(), namespace, appId, instanceId, false)
200-
assert.Equal(t, api.ExecuteSuccess, code)
200+
assert.Equal(t, api.ExecuteSuccess, code, fmt.Sprintf("%d", code))
201201
time.Sleep(20 * time.Second)
202202

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

252-
time.Sleep(5 * time.Second)
253-
saveIns, err := eurekaSrv.originDiscoverSvr.Cache().GetStore().GetInstance(mockIns.InstanceId)
251+
_ = discoverSuit.CacheMgr().TestUpdate()
252+
saveIns, err := discoverSuit.Storage.GetInstance(mockIns.InstanceId)
254253
assert.NoError(t, err)
255254
assert.NotNil(t, saveIns)
256255

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

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

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

327-
t.Run("Polaris_UpdateInstances", func(t *testing.T) {
326+
t.Run("04_Polaris_UpdateInstances", func(t *testing.T) {
328327
defer func() {
329-
rsp := discoverSuit.OriginDiscoverServer().UpdateInstances(discoverSuit.DefaultCtx, []*service_manage.Instance{
328+
rsp := discoverSuit.DiscoverServer().UpdateInstances(discoverSuit.DefaultCtx, []*service_manage.Instance{
330329
{
331330
Id: wrapperspb.String(mockIns.InstanceId),
332331
Isolate: wrapperspb.Bool(false),
333332
},
334333
})
335334
assert.Equal(t, apimodel.Code_ExecuteSuccess, apimodel.Code(rsp.GetCode().GetValue()))
336335
}()
337-
rsp := discoverSuit.OriginDiscoverServer().UpdateInstances(discoverSuit.DefaultCtx, []*service_manage.Instance{
336+
rsp := discoverSuit.DiscoverServer().UpdateInstances(discoverSuit.DefaultCtx, []*service_manage.Instance{
338337
{
339338
Id: wrapperspb.String(mockIns.InstanceId),
340339
Isolate: wrapperspb.Bool(true),
@@ -349,8 +348,8 @@ func Test_EurekaWrite(t *testing.T) {
349348
assert.Equal(t, StatusOutOfService, saveIns.Proto.Metadata[InternalMetadataStatus])
350349
})
351350

352-
t.Run("Polaris_UpdateInstancesIsolate", func(t *testing.T) {
353-
rsp := discoverSuit.OriginDiscoverServer().UpdateInstances(discoverSuit.DefaultCtx, []*service_manage.Instance{
351+
t.Run("05_Polaris_UpdateInstancesIsolate", func(t *testing.T) {
352+
rsp := discoverSuit.DiscoverServer().UpdateInstances(discoverSuit.DefaultCtx, []*service_manage.Instance{
354353
{
355354
Id: wrapperspb.String(mockIns.InstanceId),
356355
Isolate: wrapperspb.Bool(true),

apiserver/eurekaserver/chain.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type (
3535
func (h *EurekaServer) registerInstanceChain() {
3636
svr := h.originDiscoverSvr.(*service.Server)
3737
svr.AddInstanceChain(&EurekaInstanceChain{
38-
s: h.namingServer.Cache().GetStore(),
38+
s: svr.Store(),
3939
})
4040
}
4141

apiserver/eurekaserver/write.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/polarismesh/polaris/common/model"
3333
commonstore "github.com/polarismesh/polaris/common/store"
3434
"github.com/polarismesh/polaris/common/utils"
35+
"github.com/polarismesh/polaris/service"
3536
)
3637

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

259-
saveIns, err := h.originDiscoverSvr.Cache().GetStore().GetInstance(instanceId)
260+
svr := h.originDiscoverSvr.(*service.Server)
261+
saveIns, err := svr.Store().GetInstance(instanceId)
260262
if err != nil {
261263
eurekalog.Error("[EUREKA-SERVER] get instance from store when update status", zap.Error(err))
262264
return uint32(commonstore.StoreCode2APICode(err))

apiserver/nacosserver/core/storage.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"golang.org/x/sync/singleflight"
3030

3131
nacosmodel "github.com/polarismesh/polaris/apiserver/nacosserver/model"
32-
"github.com/polarismesh/polaris/cache"
32+
cachetypes "github.com/polarismesh/polaris/cache/api"
3333
"github.com/polarismesh/polaris/common/eventhub"
3434
"github.com/polarismesh/polaris/common/model"
3535
commontime "github.com/polarismesh/polaris/common/time"
@@ -50,7 +50,7 @@ type (
5050
ins []*nacosmodel.Instance, healthyCount int32) *nacosmodel.ServiceInfo
5151
)
5252

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

6868
// NacosDataStorage .
6969
type NacosDataStorage struct {
70-
cacheMgr *cache.CacheManager
70+
cacheMgr cachetypes.CacheManager
7171
ctx context.Context
7272
cancel context.CancelFunc
7373

@@ -82,7 +82,7 @@ type NacosDataStorage struct {
8282
revisions map[string]string
8383
}
8484

85-
func (n *NacosDataStorage) Cache() *cache.CacheManager {
85+
func (n *NacosDataStorage) Cache() cachetypes.CacheManager {
8686
return n.cacheMgr
8787
}
8888

@@ -343,7 +343,7 @@ func SelectInstancesWithHealthyProtection(ctx *FilterContext, result *nacosmodel
343343
return result
344344
}
345345

346-
func ToNacosService(cacheMgr *cache.CacheManager, namespace, service, group string) *nacosmodel.ServiceMetadata {
346+
func ToNacosService(cacheMgr cachetypes.CacheManager, namespace, service, group string) *nacosmodel.ServiceMetadata {
347347
ret := &nacosmodel.ServiceMetadata{
348348
ServiceKey: nacosmodel.ServiceKey{
349349
Namespace: namespace,

apiserver/nacosserver/v1/config/server.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"github.com/polarismesh/polaris/apiserver/nacosserver/core"
2222
"github.com/polarismesh/polaris/apiserver/nacosserver/v2/remote"
2323
"github.com/polarismesh/polaris/auth"
24-
"github.com/polarismesh/polaris/cache"
24+
cachetypes "github.com/polarismesh/polaris/cache/api"
2525
"github.com/polarismesh/polaris/config"
2626
"github.com/polarismesh/polaris/namespace"
2727
)
@@ -45,7 +45,7 @@ type ConfigServer struct {
4545
namespaceSvr namespace.NamespaceOperateServer
4646
configSvr config.ConfigCenterServer
4747
originConfigSvr config.ConfigCenterServer
48-
cacheSvr *cache.CacheManager
48+
cacheSvr cachetypes.CacheManager
4949
}
5050

5151
func (h *ConfigServer) Initialize(opt *ServerOption) error {

apiserver/nacosserver/v1/discover/instance.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/polarismesh/polaris/apiserver/nacosserver/model"
3232
commonmodel "github.com/polarismesh/polaris/common/model"
3333
"github.com/polarismesh/polaris/common/utils"
34+
"github.com/polarismesh/polaris/service"
3435
)
3536

3637
func (n *DiscoverServer) handleRegister(ctx context.Context, namespace, serviceName string, ins *model.Instance) error {
@@ -57,7 +58,8 @@ func (n *DiscoverServer) handleUpdate(ctx context.Context, namespace, serviceNam
5758
}
5859
specIns.Id = wrapperspb.String(insId)
5960
}
60-
saveIns, err := n.discoverSvr.Cache().GetStore().GetInstance(specIns.GetId().GetValue())
61+
svr := n.discoverSvr.(*service.Server)
62+
saveIns, err := svr.Store().GetInstance(specIns.GetId().GetValue())
6163
if err != nil {
6264
return &model.NacosError{
6365
ErrCode: int32(model.ExceptionCode_ServerError),

apiserver/nacosserver/v2/config/server.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
nacospb "github.com/polarismesh/polaris/apiserver/nacosserver/v2/pb"
2323
"github.com/polarismesh/polaris/apiserver/nacosserver/v2/remote"
2424
"github.com/polarismesh/polaris/auth"
25-
"github.com/polarismesh/polaris/cache"
25+
cachetypes "github.com/polarismesh/polaris/cache/api"
2626
"github.com/polarismesh/polaris/config"
2727
"github.com/polarismesh/polaris/namespace"
2828
)
@@ -49,7 +49,7 @@ type ConfigServer struct {
4949
namespaceSvr namespace.NamespaceOperateServer
5050
configSvr config.ConfigCenterServer
5151
originConfigSvr config.ConfigCenterServer
52-
cacheSvr *cache.CacheManager
52+
cacheSvr cachetypes.CacheManager
5353
handleRegistry map[string]*remote.RequestHandlerWarrper
5454
}
5555

apiserver/nacosserver/v2/discover/checker.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030

3131
nacosmodel "github.com/polarismesh/polaris/apiserver/nacosserver/model"
3232
"github.com/polarismesh/polaris/apiserver/nacosserver/v2/remote"
33-
"github.com/polarismesh/polaris/cache"
33+
cachetypes "github.com/polarismesh/polaris/cache/api"
3434
"github.com/polarismesh/polaris/common/eventhub"
3535
"github.com/polarismesh/polaris/common/model"
3636
"github.com/polarismesh/polaris/common/utils"
@@ -44,7 +44,7 @@ type Checker struct {
4444
discoverSvr service.DiscoverServer
4545
healthSvr *healthcheck.Server
4646

47-
cacheMgr *cache.CacheManager
47+
cacheMgr cachetypes.CacheManager
4848
connMgr *remote.ConnectionManager
4949
clientMgr *ConnectionClientManager
5050

@@ -192,6 +192,8 @@ func (c *Checker) runCheck(ctx context.Context) {
192192
// BUT: 一个实例 T1 时刻对应长连接为 Conn-1,T2 时刻对应的长连接为 Conn-2,但是在 T1 ~ T2 之间的某个时刻检测发现长连接不存在
193193
// 此时发起一个反注册请求,该请求在 T3 时刻发起,是否会影响 T2 时刻注册上来的实例?
194194
func (c *Checker) realCheck() {
195+
svr := c.discoverSvr.(*service.Server)
196+
195197
defer func() {
196198
if err := recover(); err != nil {
197199
var buf [4086]byte
@@ -267,7 +269,7 @@ func (c *Checker) realCheck() {
267269
}
268270
nacoslog.Info("[NACOS-V2][Checker] batch set instance health_status to unhealthy",
269271
zap.Any("instance-ids", ids))
270-
if err := c.discoverSvr.Cache().GetStore().
272+
if err := svr.Store().
271273
BatchSetInstanceHealthStatus(ids, model.StatusBoolToInt(false), utils.NewUUID()); err != nil {
272274
nacoslog.Error("[NACOS-V2][Checker] batch set instance health_status to unhealthy",
273275
zap.Any("instance-ids", ids), zap.Error(err))
@@ -281,7 +283,7 @@ func (c *Checker) realCheck() {
281283
}
282284
nacoslog.Info("[NACOS-V2][Checker] batch set instance health_status to healty",
283285
zap.Any("instance-ids", ids))
284-
if err := c.discoverSvr.Cache().GetStore().
286+
if err := svr.Store().
285287
BatchSetInstanceHealthStatus(ids, model.StatusBoolToInt(true), utils.NewUUID()); err != nil {
286288
nacoslog.Error("[NACOS-V2][Checker] batch set instance health_status to healty",
287289
zap.Any("instance-ids", ids), zap.Error(err))

auth/user/group.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (svr *Server) UpdateGroup(ctx context.Context, req *apisecurity.ModifyUserG
124124
return errResp
125125
}
126126

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

388-
// updateGroupAttribute 更新计算用户组更新时的结构体数据,并判断是否需要执行更新操作
389-
func updateGroupAttribute(ctx context.Context, old *model.UserGroup, newUser *apisecurity.ModifyUserGroup) (
388+
// UpdateGroupAttribute 更新计算用户组更新时的结构体数据,并判断是否需要执行更新操作
389+
func UpdateGroupAttribute(ctx context.Context, old *model.UserGroup, newUser *apisecurity.ModifyUserGroup) (
390390
*model.ModifyUserGroup, bool) {
391391
var (
392392
needUpdate bool

auth/user/user_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"github.com/golang/mock/gomock"
2626
"github.com/golang/protobuf/ptypes/wrappers"
27+
apimodel "github.com/polarismesh/specification/source/go/api/v1/model"
2728
apisecurity "github.com/polarismesh/specification/source/go/api/v1/security"
2829
"github.com/stretchr/testify/assert"
2930

@@ -318,6 +319,32 @@ func Test_server_CreateUsers(t *testing.T) {
318319
})
319320
}
320321

322+
func Test_server_Login(t *testing.T) {
323+
324+
userTest := newUserTest(t)
325+
defer userTest.Clean()
326+
327+
t.Run("正常登陆", func(t *testing.T) {
328+
rsp := userTest.svr.Login(&apisecurity.LoginRequest{
329+
Name: &wrappers.StringValue{Value: userTest.users[0].Name},
330+
Password: &wrappers.StringValue{Value: "polaris"},
331+
})
332+
333+
assert.True(t, api.IsSuccess(rsp), rsp.GetInfo().GetValue())
334+
})
335+
336+
t.Run("错误的密码", func(t *testing.T) {
337+
rsp := userTest.svr.Login(&apisecurity.LoginRequest{
338+
Name: &wrappers.StringValue{Value: userTest.users[0].Name},
339+
Password: &wrappers.StringValue{Value: "polaris_123"},
340+
})
341+
342+
assert.False(t, api.IsSuccess(rsp), rsp.GetInfo().GetValue())
343+
assert.Equal(t, uint32(apimodel.Code_NotAllowedAccess), rsp.GetCode().GetValue())
344+
assert.Contains(t, rsp.GetInfo().GetValue(), model.ErrorWrongUsernameOrPassword.Error())
345+
})
346+
}
347+
321348
func Test_server_UpdateUser(t *testing.T) {
322349

323350
userTest := newUserTest(t)

bootstrap/server.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ func polarisServiceRegister(polarisService *boot_config.PolarisService, apiServe
569569
// selfRegister 服务自注册
570570
func selfRegister(
571571
host string, port uint32, protocol string, isolated bool, polarisService *boot_config.Service, hbInterval int) error {
572-
server, err := service.GetOriginServer()
572+
server, err := service.GetServer()
573573
if err != nil {
574574
return err
575575
}
@@ -609,7 +609,7 @@ func selfRegister(
609609
Metadata: metadata,
610610
}
611611

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

0 commit comments

Comments
 (0)