Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

去除主机采集通道名称中的业务ID #8257

Open
wants to merge 1 commit into
base: feature-tenant
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/common/backbone/configcenter/viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,15 @@ func Mongo(prefix string) (mongo.Config, error) {
c.MaxOpenConns = parser.getUint64(maxOpenConns)
}

if c.MaxIdleConns > mongo.MaximumMaxOpenConns {
if c.MaxOpenConns < mongo.MinimumMaxIdleOpenConns {
blog.Errorf("config %s less than minimum value, use minimum value %d", maxOpenConns,
mongo.MinimumMaxIdleOpenConns)
c.MaxOpenConns = mongo.MinimumMaxIdleOpenConns
}

if c.MaxOpenConns > mongo.MaximumMaxOpenConns {
blog.Errorf("config %s exceeds maximum value, use maximum value %d", maxOpenConns, mongo.MaximumMaxOpenConns)
c.MaxIdleConns = mongo.MaximumMaxOpenConns
c.MaxOpenConns = mongo.MaximumMaxOpenConns
}

maxIdleConns := prefix + ".maxIdleConns"
Expand Down
3 changes: 3 additions & 0 deletions src/common/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1792,3 +1792,6 @@ const (

// ShardingDBConfID is sharding db config identifier
const ShardingDBConfID = "sharding_db_config"

// SnapshotChannelName is host snapshot channel name
const SnapshotChannelName = "cmdb_snapshot"
16 changes: 3 additions & 13 deletions src/common/metadata/configadmin.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,10 @@ func (s GlobalModule) Validate() error {
// AdminBackendCfg TODO
type AdminBackendCfg struct {
MaxBizTopoLevel int64 `json:"max_biz_topo_level"`
SnapshotBizID int64 `json:"snapshot_biz_id"`
}

// Validate validate the fields of BackendCfg.
func (b AdminBackendCfg) Validate() error {

if b.SnapshotBizID <= 0 {
return fmt.Errorf("snapshot biz id can't be empty")
}

if b.MaxBizTopoLevel < minBizTopoLevel || b.MaxBizTopoLevel > maxBizTopoLevel {
return fmt.Errorf("max biz topo level value must in range [%d-%d]", minBizTopoLevel, maxBizTopoLevel)
}
Expand Down Expand Up @@ -663,16 +657,12 @@ type BusinessTopoInstNamesItem struct {
type OldAdminBackendCfg struct {
MaxBizTopoLevel int64 `json:"max_biz_topo_level"`
SnapshotBizName string `json:"snapshot_biz_name"`
SnapshotBizID int64 `json:"snapshot_biz_id"`
}

// Validate validate the fields of BackendCfg.
func (o OldAdminBackendCfg) Validate() error {

if strings.TrimSpace(o.SnapshotBizName) == "" {
return fmt.Errorf("snapshot biz name can't be empty")
}

if o.MaxBizTopoLevel < minBizTopoLevel || o.MaxBizTopoLevel > maxBizTopoLevel {
func (b OldAdminBackendCfg) Validate() error {
if b.MaxBizTopoLevel < minBizTopoLevel || b.MaxBizTopoLevel > maxBizTopoLevel {
return fmt.Errorf("max biz topo level value must in range [%d-%d]", minBizTopoLevel, maxBizTopoLevel)
}
return nil
Expand Down
16 changes: 0 additions & 16 deletions src/scene_server/admin_server/service/configadmin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
idgen "configcenter/pkg/id-gen"
"configcenter/src/common"
"configcenter/src/common/blog"
"configcenter/src/common/errors"
httpheader "configcenter/src/common/http/header"
"configcenter/src/common/metadata"
"configcenter/src/storage/dal/mongo/local"
Expand Down Expand Up @@ -256,21 +255,6 @@ func (s *Service) savePlatformSettingUpdateAudit(preConf, curConf *metadata.Plat
func (s *Service) updatePlatformSetting(config *metadata.PlatformSettingConfig, rid string) error {
config.IDGenerator.CurrentID = nil

// 校验业务是否存在
bizCountCond := map[string]interface{}{
common.BKAppIDField: config.Backend.SnapshotBizID,
}
count, err := s.db.IgnoreTenant().Table(common.BKTableNameBaseApp).Find(bizCountCond).Count(s.ctx)
if err != nil {
blog.Errorf("update config to db failed, count biz error, err: %v, condition: %v, rid: %s", err,
bizCountCond, rid)
return err
}
if count == 0 {
blog.Errorf("update config to db failed, can not find biz, condition: %v, rid: %s", bizCountCond, rid)
return errors.New(common.CCErrCommParamsIsInvalid, "snapshot_biz_id")
}

bytes, err := json.Marshal(config)
if err != nil {
return err
Expand Down
54 changes: 7 additions & 47 deletions src/scene_server/admin_server/service/dataid.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"configcenter/src/common/blog"
"configcenter/src/common/errors"
httpheader "configcenter/src/common/http/header"
"configcenter/src/common/json"
"configcenter/src/common/metadata"
"configcenter/src/storage/driver/mongodb"

Expand Down Expand Up @@ -67,7 +66,7 @@ func (s *Service) migrateDataID(req *restful.Request, resp *restful.Response) {
}

// upsert config channel to gse
channel, err := s.generateGseConfigChannel(streamToID, s.Config.SnapDataID, rid, newVersion)
channel, err := s.generateGseConfigChannel(streamToID, s.Config.SnapDataID, newVersion)
if err != nil {
_ = resp.WriteError(http.StatusOK, err)
return
Expand Down Expand Up @@ -147,7 +146,7 @@ func (s *Service) migrateOldVersionDataID(header http.Header, user string, defEr
blog.Errorf("query gse channel failed, ** skip this error for not exist case **, err: %v, rid: %s", err, rid)
}

oldChannel, err := s.generateGseConfigChannel(streamToID, oldDataID, rid, oldVersion)
oldChannel, err := s.generateGseConfigChannel(streamToID, oldDataID, oldVersion)
if err != nil {
blog.Errorf("generate gse channel failed, err: %v, stream to id: %d, rid: %s", err, streamToID, rid)
return err
Expand Down Expand Up @@ -196,11 +195,6 @@ func (s *Service) migrateOldVersionDataID(header http.Header, user string, defEr
func (s *Service) isOldDataIDChannelExist(channels []metadata.GseConfigChannel, streamToID int64, rid string) (bool,
metadata.GseConfigPlatName, error) {

bizID, err := s.getSnapBizID(rid)
if err != nil {
return false, "", err
}

var platName metadata.GseConfigPlatName
// check if channel name is snapshot+snap biz id to confirm if it is registered by cc, skip in this situation
for _, channel := range channels {
Expand All @@ -214,8 +208,7 @@ func (s *Service) isOldDataIDChannelExist(channels []metadata.GseConfigChannel,
continue
}

if route.StreamTo.Redis.ChannelName == fmt.Sprintf("snapshot%d", bizID) ||
(route.StreamTo.Redis.BizID == bizID && route.StreamTo.Redis.DataSet == "snapshot") {
if route.StreamTo.Redis.ChannelName == common.SnapshotChannelName {
blog.Infof("old gse data id is already exist, skip registering it, rid: %s", rid)
return true, platName, nil
}
Expand Down Expand Up @@ -456,36 +449,9 @@ func (s *Service) gseConfigUpdateStreamTo(streamTo *metadata.GseConfigStreamTo,
return nil
}

// getSnapBizID get the biz id that host snap uses
func (s *Service) getSnapBizID(rid string) (int64, error) {
cfgCond := map[string]interface{}{
"_id": common.ConfigAdminID,
}
cfg := make(map[string]string)
err := s.db.IgnoreTenant().Table(common.BKTableNameSystem).Find(cfgCond).Fields(common.ConfigAdminValueField).
One(s.ctx, &cfg)
if nil != err {
blog.Errorf("get config admin failed, err: %v, rid: %s", err, rid)
return 0, err
}

configAdmin := new(metadata.PlatformSettingConfig)
if err := json.Unmarshal([]byte(cfg[common.ConfigAdminValueField]), configAdmin); err != nil {
blog.Errorf("unmarshal config admin(%s) failed, err: %v, rid: %s", cfg[common.ConfigAdminValueField], err, rid)
return 0, err
}

return configAdmin.Backend.SnapshotBizID, nil
}

// generateGseConfigChannel generate host snap stream to config by snap redis config
func (s *Service) generateGseConfigChannel(streamToID, dataID int64, rid string,
version snapshotVersion) (*metadata.GseConfigChannel, error) {

bizID, err := s.getSnapBizID(rid)
if err != nil {
return nil, err
}
func (s *Service) generateGseConfigChannel(streamToID, dataID int64, version snapshotVersion) (
*metadata.GseConfigChannel, error) {

snapChannel := &metadata.GseConfigChannel{
Metadata: metadata.GseConfigAddRouteMetadata{
Expand All @@ -504,20 +470,14 @@ func (s *Service) generateGseConfigChannel(streamToID, dataID int64, rid string,
metadata.GseConfigReportMode(s.Config.SnapReportMode) == metadata.GseConfigReportModeRedis {

snapChannel.Route[0].StreamTo.Redis = &metadata.GseConfigRouteRedis{
ChannelName: fmt.Sprintf("snapshot%d", bizID),
// compatible for the older version of gse that uses DataSet+BizID as channel name
DataSet: "snapshot",
BizID: bizID,
ChannelName: common.SnapshotChannelName,
}
return snapChannel, nil
}

if metadata.GseConfigReportMode(s.Config.SnapReportMode) == metadata.GseConfigReportModeKafka {
snapChannel.Route[0].StreamTo.Kafka = &metadata.GseConfigRouteKafka{
TopicName: fmt.Sprintf("snapshot%d", bizID),
// compatible for the older version of gse that uses DataSet+BizID as channel name
DataSet: "snapshot",
BizID: bizID,
TopicName: common.SnapshotChannelName,
Partition: s.Config.SnapKafka.Partition,
}
return snapChannel, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,10 @@ func updatePlatformConfigAdmin(ctx context.Context, db dal.RDB, conf *upgrader.C
return errors.New("can not get biz in db")
}

newCfg := new(metadata.PlatformSettingConfig)
newCfg.Backend.SnapshotBizID = bizInfo.BizID
newCfg.Backend.MaxBizTopoLevel = dbCfg.Backend.MaxBizTopoLevel
newCfg.BuiltInModuleConfig = dbCfg.BuiltInModuleConfig
newCfg.BuiltInSetName = dbCfg.BuiltInSetName
newCfg.ValidationRules = dbCfg.ValidationRules
newCfg.IDGenerator = dbCfg.IDGenerator
dbCfg.Backend.SnapshotBizID = bizInfo.BizID
dbCfg.Backend.SnapshotBizName = ""

bytes, err := json.Marshal(newCfg)
bytes, err := json.Marshal(dbCfg)
if err != nil {
return err
}
Expand All @@ -102,7 +97,7 @@ func updatePlatformConfigAdmin(ctx context.Context, db dal.RDB, conf *upgrader.C
type adminBackendCfg struct {
MaxBizTopoLevel int64 `json:"max_biz_topo_level"`
SnapshotBizID int64 `json:"snapshot_biz_id"`
SnapshotBizName string `json:"snapshot_biz_name"`
SnapshotBizName string `json:"snapshot_biz_name,omitempty"`
}

// platformSettingConfig platform setting config
Expand Down
Loading