Skip to content

Commit

Permalink
codecov:1.18.0 (#1315)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntaojun authored Jan 8, 2024
1 parent 6ca3a58 commit fd23d40
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 35 deletions.
2 changes: 1 addition & 1 deletion bootstrap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func StartConfigCenterComponents(ctx context.Context, cfg *boot_config.Config, s
return err
}
cfg.Config.Interceptors = config_center.GetChainOrder()
return config_center.Initialize(ctx, cfg.Config, s, cacheMgn, namespaceOperator, userMgn, strategyMgn)
return config_center.Initialize(ctx, cfg.Config, s, cacheMgn, namespaceOperator)
}

// StartServers 启动server
Expand Down
2 changes: 1 addition & 1 deletion cache/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type CacheManager interface {
GetCacher(cacheIndex CacheIndex) Cache
// RegisterCacher
RegisterCacher(cacheIndex CacheIndex, item Cache)
//
// OpenResourceCache
OpenResourceCache(entries ...ConfigEntry) error
// Service 获取Service缓存信息
Service() ServiceCache
Expand Down
24 changes: 12 additions & 12 deletions config/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,37 @@ type (

// GetConfigFileWithCache 从缓存中获取配置文件,如果客户端的版本号大于服务端,则服务端重新加载缓存
func (s *Server) GetConfigFileWithCache(ctx context.Context,
client *apiconfig.ClientConfigFileInfo) *apiconfig.ConfigClientResponse {
namespace := client.GetNamespace().GetValue()
group := client.GetGroup().GetValue()
fileName := client.GetFileName().GetValue()
req *apiconfig.ClientConfigFileInfo) *apiconfig.ConfigClientResponse {
namespace := req.GetNamespace().GetValue()
group := req.GetGroup().GetValue()
fileName := req.GetFileName().GetValue()

if namespace == "" || group == "" || fileName == "" {
return api.NewConfigClientResponseWithInfo(
apimodel.Code_BadRequest, "namespace & group & fileName can not be empty")
}
client = formatClientRequest(ctx, client)
req = formatClientRequest(ctx, req)
// 从缓存中获取灰度文件
var release *model.ConfigFileRelease
var match = false
if len(client.GetTags()) > 0 {
if len(req.GetTags()) > 0 {
if release = s.fileCache.GetActiveGrayRelease(namespace, group, fileName); release != nil {
key := model.GetGrayConfigRealseKey(release.SimpleConfigFileRelease)
match = s.grayCache.HitGrayRule(key, model.ToTagMap(client.GetTags()))
match = s.grayCache.HitGrayRule(key, model.ToTagMap(req.GetTags()))
}
}
if !match {
if release = s.fileCache.GetActiveRelease(namespace, group, fileName); release == nil {
return api.NewConfigClientResponse(apimodel.Code_NotFoundResource, nil)
return api.NewConfigClientResponse(apimodel.Code_NotFoundResource, req)
}
}
// 客户端版本号大于等于服务端版本号,服务端不返回变更
if client.GetVersion().GetValue() >= release.Version {
return api.NewConfigClientResponse(apimodel.Code_DataNoChange, nil)
if req.GetVersion().GetValue() >= release.Version {
return api.NewConfigClientResponse(apimodel.Code_DataNoChange, req)
}
configFile, err := toClientInfo(client, release)
configFile, err := toClientInfo(req, release)
if err != nil {
log.Error("[Config][Service] get config file to client info", utils.RequestID(ctx), zap.Error(err))
log.Error("[Config][Service] get config file to client", utils.RequestID(ctx), zap.Error(err))
return api.NewConfigClientResponseWithInfo(apimodel.Code_ExecuteException, err.Error())
}
return api.NewConfigClientResponse(apimodel.Code_ExecuteSuccess, configFile)
Expand Down
24 changes: 11 additions & 13 deletions config/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (

apiconfig "github.com/polarismesh/specification/source/go/api/v1/config_manage"

"github.com/polarismesh/polaris/auth"
"github.com/polarismesh/polaris/cache"
cachetypes "github.com/polarismesh/polaris/cache/api"
"github.com/polarismesh/polaris/common/model"
"github.com/polarismesh/polaris/common/utils"
Expand Down Expand Up @@ -73,7 +71,7 @@ type Server struct {
fileCache cachetypes.ConfigFileCache
groupCache cachetypes.ConfigGroupCache
grayCache cachetypes.GrayCache
caches *cache.CacheManager
caches cachetypes.CacheManager
watchCenter *watchCenter
namespaceOperator namespace.NamespaceOperateServer
initialized bool
Expand All @@ -89,8 +87,8 @@ type Server struct {
}

// Initialize 初始化配置中心模块
func Initialize(ctx context.Context, config Config, s store.Store, cacheMgn *cache.CacheManager,
namespaceOperator namespace.NamespaceOperateServer, userMgn auth.UserServer, strategyMgn auth.StrategyServer) error {
func Initialize(ctx context.Context, config Config, s store.Store, cacheMgr cachetypes.CacheManager,
namespaceOperator namespace.NamespaceOperateServer) error {
if !config.Open {
originServer.initialized = true
return nil
Expand All @@ -100,10 +98,10 @@ func Initialize(ctx context.Context, config Config, s store.Store, cacheMgn *cac
return nil
}

if err := cacheMgn.OpenResourceCache(configCacheEntries...); err != nil {
if err := cacheMgr.OpenResourceCache(configCacheEntries...); err != nil {
return err
}
err := originServer.initialize(ctx, config, s, namespaceOperator, cacheMgn)
err := originServer.initialize(ctx, config, s, namespaceOperator, cacheMgr)
if err != nil {
return err
}
Expand All @@ -128,19 +126,19 @@ func Initialize(ctx context.Context, config Config, s store.Store, cacheMgn *cac
}

func (s *Server) initialize(ctx context.Context, config Config, ss store.Store,
namespaceOperator namespace.NamespaceOperateServer, cacheMgn *cache.CacheManager) error {
namespaceOperator namespace.NamespaceOperateServer, cacheMgr cachetypes.CacheManager) error {
var err error
s.cfg = &config
if s.cfg.ContentMaxLength <= 0 {
s.cfg.ContentMaxLength = fileContentMaxLength
}
s.storage = ss
s.namespaceOperator = namespaceOperator
s.fileCache = cacheMgn.ConfigFile()
s.groupCache = cacheMgn.ConfigGroup()
s.grayCache = cacheMgn.Gray()
s.fileCache = cacheMgr.ConfigFile()
s.groupCache = cacheMgr.ConfigGroup()
s.grayCache = cacheMgr.Gray()

s.watchCenter, err = NewWatchCenter(cacheMgn)
s.watchCenter, err = NewWatchCenter(cacheMgr)
if err != nil {
return err
}
Expand All @@ -156,7 +154,7 @@ func (s *Server) initialize(ctx context.Context, config Config, ss store.Store,
log.Warnf("Not Found Crypto Plugin")
}

s.caches = cacheMgn
s.caches = cacheMgr
s.chains = newConfigChains(s, []ConfigFileChain{
&CryptoConfigFileChain{},
&ReleaseConfigFileChain{},
Expand Down
56 changes: 56 additions & 0 deletions config/server_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Tencent is pleased to support the open source community by making Polaris available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package config

import (
"context"
"testing"

"github.com/golang/mock/gomock"
mockcache "github.com/polarismesh/polaris/cache/mock"
"github.com/polarismesh/polaris/common/eventhub"
mockstore "github.com/polarismesh/polaris/store/mock"
"github.com/stretchr/testify/assert"
)

func Test_Initialize(t *testing.T) {
t.SkipNow()
eventhub.InitEventHub()
ctrl := gomock.NewController(t)
mockStore := mockstore.NewMockStore(ctrl)
cacheMgr := mockcache.NewMockCacheManager(ctrl)

t.Cleanup(func() {
ctrl.Finish()
originServer.watchCenter.Close()
originServer.initialized = false
originServer = nil
server = nil
})

cacheMgr.EXPECT().OpenResourceCache(gomock.Any()).Return(nil).AnyTimes()
cacheMgr.EXPECT().ConfigFile().Return(nil).AnyTimes()
cacheMgr.EXPECT().Gray().Return(nil).AnyTimes()
cacheMgr.EXPECT().ConfigGroup().Return(nil).AnyTimes()

err := Initialize(context.Background(), Config{
Open: true,
}, mockStore, cacheMgr, nil)
assert.NoError(t, err)
assert.NotNil(t, originServer)
}
7 changes: 3 additions & 4 deletions test/data/cluster-polaris-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,9 @@ store:
txIsolationLevel: 2 #LevelReadCommitted
# 插件配置
plugin:
# whitelist:
# name: whitelist
# option:
# ip: [127.0.0.1]
crypto:
entries:
- name: AES
history:
entries:
- name: HistoryLogger
Expand Down
7 changes: 3 additions & 4 deletions test/data/polaris-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,9 @@ store:
txIsolationLevel: 2 #LevelReadCommitted
# 插件配置
plugin:
# whitelist:
# name: whitelist
# option:
# ip: [127.0.0.1]
crypto:
entries:
- name: AES
cmdb:
name: memory
option:
Expand Down

0 comments on commit fd23d40

Please sign in to comment.