Skip to content

Commit

Permalink
[ISSUE #429] Registration & Heartbeat Performance Optimization (#440)
Browse files Browse the repository at this point in the history
* feat: none

* perf: perf regis instance to async

* fix: fix duplicate healthcheck plugin init

* chore: remove polaris-server.yaml from docker

* refactor: remove unuseless config

* fix: fix config_center uint test

* refactor: remove async report heartbeat

* feat: update cache refactor

* test: fix unit test

* test: add user-group unit test

* test: fix unit test stability

* test: fix unit test stability

* test: fix unit test stability

* refactor: fix pr issue

* fix: fix pr issue

\

* fix: fix instanceFuture not set needWait

* test: add unit test for auth
  • Loading branch information
chuntaojun committed Jun 21, 2022
1 parent 45462e2 commit 3ad2b60
Show file tree
Hide file tree
Showing 74 changed files with 1,895 additions and 1,212 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ jobs:
echo "work_dir is $work_dir"
cd $work_dir
sed -i 's/consoleOpen: \(true\|false\)/consoleOpen: false/g' polaris-server.yaml
if["$(uname)"=="Darwin"];then
# Mac OS X 操作系统
sed -i '' 's/consoleOpen: \(true\|false\)/consoleOpen: false/g' polaris-server.yaml
elif["$(expr substr $(uname -s) 1 5)"=="Linux"];then
# GNU/Linux操作系统
sed -i 's/consoleOpen: \(true\|false\)/consoleOpen: false/g' polaris-server.yaml
fi
cat polaris-server.yaml
Expand Down
2 changes: 1 addition & 1 deletion README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ README:

#### 准备golang编译环境

北极星服务端编译需要golang编译环境,版本号要求>=1.12,可以在这里进行下载:https://golang.org/dl/#featured
北极星服务端编译需要golang编译环境,版本号要求>=1.17,可以在这里进行下载:https://golang.org/dl/#featured

### 编译构建

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Point Script: ./store/sqldb/scripts/polaris_server.sql, one can import through m

#### Prepare golang compile environment

Polaris server end needs golang compile environment, version number needs >=1.12, download available
Polaris server end needs golang compile environment, version number needs >=1.17, download available
here: https://golang.org/dl/#featured.

### Build
Expand Down
4 changes: 4 additions & 0 deletions apiserver/grpcserver/discover/client_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func (g *GRPCServer) RegisterInstance(ctx context.Context, in *api.Instance) (*a
rCtx = context.WithValue(rCtx, utils.ContextAuthTokenKey, in.GetServiceToken().GetValue())
}

if in.GetHealthCheck().GetHeartbeat().GetTtl() != nil {
rCtx = context.WithValue(rCtx, utils.ContextOpenAsyncRegis, true)
}

out := g.namingServer.RegisterInstance(rCtx, in)
return out, nil
}
Expand Down
4 changes: 2 additions & 2 deletions auth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
// AuthServer 鉴权 Server
type AuthServer interface {
// Initialize 初始化
Initialize(authOpt *Config, storage store.Store, cacheMgn *cache.NamingCache) error
Initialize(authOpt *Config, storage store.Store, cacheMgn *cache.CacheManager) error

// Name 获取服务名称
Name() string
Expand All @@ -56,7 +56,7 @@ type AuthServer interface {
// AuthChecker 权限管理通用接口定义
type AuthChecker interface {
// Initialize 执行初始化动作
Initialize(options *Config, cacheMgn *cache.NamingCache) error
Initialize(options *Config, cacheMgn *cache.CacheManager) error
// VerifyToken 验证令牌
VerifyCredential(preCtx *model.AcquireContext) error
// CheckClientPermission 执行检查客户端动作判断是否有权限,并且对 RequestContext 注入操作者数据
Expand Down
4 changes: 2 additions & 2 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func GetAuthServer() (AuthServer, error) {
}

// Initialize 初始化
func Initialize(ctx context.Context, authOpt *Config, storage store.Store, cacheMgn *cache.NamingCache) error {
func Initialize(ctx context.Context, authOpt *Config, storage store.Store, cacheMgn *cache.CacheManager) error {
var err error
once.Do(func() {
err = initialize(ctx, authOpt, storage, cacheMgn)
Expand All @@ -76,7 +76,7 @@ func Initialize(ctx context.Context, authOpt *Config, storage store.Store, cache
}

// initialize 包裹了初始化函数,在 Initialize 的时候会在自动调用,全局初始化一次
func initialize(ctx context.Context, authOpt *Config, storage store.Store, cacheMgn *cache.NamingCache) error {
func initialize(ctx context.Context, authOpt *Config, storage store.Store, cacheMgn *cache.CacheManager) error {
name := authOpt.Name
if name == "" {
return errors.New("auth manager Name is empty")
Expand Down
6 changes: 3 additions & 3 deletions auth/defaultauth/auth_mgn.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ import (

// defaultAuthChecker 北极星自带的默认鉴权中心
type defaultAuthChecker struct {
cacheMgn *cache.NamingCache
cacheMgn *cache.CacheManager
authPlugin plugin.Auth
}

// Initialize 执行初始化动作
func (d *defaultAuthChecker) Initialize(options *auth.Config, cacheMgn *cache.NamingCache) error {
func (d *defaultAuthChecker) Initialize(options *auth.Config, cacheMgn *cache.CacheManager) error {
contentBytes, err := json.Marshal(options.Option)
if err != nil {
return err
Expand Down Expand Up @@ -75,6 +75,6 @@ func (d *defaultAuthChecker) Initialize(options *auth.Config, cacheMgn *cache.Na
}

// Cache 获取缓存统一管理
func (d *defaultAuthChecker) Cache() *cache.NamingCache {
func (d *defaultAuthChecker) Cache() *cache.CacheManager {
return d.cacheMgn
}
1 change: 1 addition & 0 deletions auth/defaultauth/auth_mgn_core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func Test_defaultAuthChecker_VerifyCredential(t *testing.T) {

storage := storemock.NewMockStore(ctrl)

storage.EXPECT().GetUnixSecond().AnyTimes().Return(time.Now().Unix(), nil)
storage.EXPECT().GetUsersForCache(gomock.Any(), gomock.Any()).AnyTimes().Return(users, nil)
storage.EXPECT().GetGroupsForCache(gomock.Any(), gomock.Any()).AnyTimes().Return([]*model.UserGroupDetail{}, nil)

Expand Down
13 changes: 10 additions & 3 deletions auth/defaultauth/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ func initCache(ctrl *gomock.Controller) (*cache.Config, *storemock.MockStore) {

storage := storemock.NewMockStore(ctrl)

storage.EXPECT().GetUnixSecond().AnyTimes().Return(time.Now().Unix(), nil)

return cfg, storage
}

Expand Down Expand Up @@ -125,21 +127,26 @@ func createMockService(namespaces []*model.Namespace) []*model.Service {
}

// createMockUser 默认 users[0] 为 owner 用户
func createMockUser(total int) []*model.User {
func createMockUser(total int, prefix ...string) []*model.User {
users := make([]*model.User, 0, total)

ownerId := utils.NewUUID()

nameTemp := "user-%d"
if len(prefix) != 0 {
nameTemp = prefix[0] + nameTemp
}

for i := 0; i < total; i++ {
id := utils.NewUUID()
id := fmt.Sprintf("fake-user-id-%d-%s", i, utils.NewUUID())
if i == 0 {
id = ownerId
}
pwd, _ := bcrypt.GenerateFromPassword([]byte("polaris"), bcrypt.DefaultCost)
token, _ := createToken(id, "")
users = append(users, &model.User{
ID: id,
Name: fmt.Sprintf("user-%d", i),
Name: fmt.Sprintf(nameTemp, i),
Password: string(pwd),
Owner: func() string {
if id == ownerId {
Expand Down
Loading

0 comments on commit 3ad2b60

Please sign in to comment.