Skip to content
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
48 changes: 48 additions & 0 deletions src/common/backbone/configcenter/viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,46 @@ func Mongo(prefix string) (mongo.Config, error) {
return c, nil
}

type enum struct {
Limit int `json:"limit" yaml:"limit" mapstructure:"limit"`
}
type objAttDes struct {
Enum enum `json:"enum" yaml:"enum" mapstructure:"enum"`
}

// ExtraConfig extral.yaml config
type ExtraConfig struct {
ObjAttDes objAttDes `json:"objAttDes" yaml:"objAttDes" mapstructure:"objAttDes"`
}

// Extra return extra configuration information according to the prefix.
func Extra(prefix string) (ExtraConfig, error) {
confLock.RLock()
defer confLock.RUnlock()
var parser *viperParser
for sleepCnt := 0; sleepCnt < common.APPConfigWaitTime; sleepCnt++ {
parser = getExtraParser()
if parser != nil {
break
}
blog.Warn("the configuration of extra is not ready yet")
time.Sleep(time.Duration(1) * time.Second)
}

if parser == nil {
blog.Errorf("can't find extra configuration")
return ExtraConfig{}, errors.New("can't find extra configuration")
}

return ExtraConfig{
ObjAttDes: objAttDes{
Enum: enum{
Limit: parser.getInt(prefix + ".enum.limit"),
},
},
}, nil
}

// Kafka return kafka configuration information according to the prefix.
func Kafka(prefix string) (kafka.Config, error) {
confLock.RLock()
Expand Down Expand Up @@ -568,6 +608,14 @@ func getMongodbParser() *viperParser {
return localParser
}

func getExtraParser() *viperParser {
if extraParser != nil {
return extraParser
}

return localParser
}

func getCommonParser() *viperParser {
if commonParser != nil {
return commonParser
Expand Down
14 changes: 12 additions & 2 deletions src/common/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1559,12 +1559,22 @@ const (
AttributeUnitMaxLength = 20
// AttributeOptionValueMaxLength TODO
AttributeOptionValueMaxLength = 128
// AttributeOptionArrayMaxLength TODO
AttributeOptionArrayMaxLength = 200
// ServiceCategoryMaxLength TODO
ServiceCategoryMaxLength = 128
)

var (
// AttributeOptionArrayMaxLength TODO
AttributeOptionArrayMaxLength = 200
)

// SetEnumLimit set AttributeOptionArrayMaxLength value,max:1000
func SetEnumLimit(l int) {
if l > 0 {
AttributeOptionArrayMaxLength = int(math.Min(float64(l), float64(1000)))
}
}

const (
// NameFieldMaxLength TODO
NameFieldMaxLength = 256
Expand Down
5 changes: 5 additions & 0 deletions src/scene_server/admin_server/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ func parseSeverConfig(ctx context.Context, op *options.ServerOption) (*MigrateSe
return nil, fmt.Errorf("parse common config from file[%s] failed, err: %v", commonPath, err)
}

extraPath := process.Config.Configures.Dir + "/" + types.CCConfigureExtra
if err := cc.SetExtraFromFile(extraPath); err != nil {
return nil, fmt.Errorf("parse extra config from file[%s] failed, err: %v", extraPath, err)
}

process.Config.SnapReportMode, _ = cc.String("datacollection.hostsnap.reportMode")
process.Config.SnapKafka, _ = cc.Kafka("kafka.snap")

Expand Down
7 changes: 6 additions & 1 deletion src/source_controller/coreservice/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ func Run(ctx context.Context, cancel context.CancelFunc, op *options.ServerOptio
}

func initResource(coreSvr *CoreServer, op *options.ServerOption) error {
var err error
enumLimit, err := cc.Extra("objAttDes")
if err != nil {
return fmt.Errorf("read extraConfig with key limit err:%w", err)
}
common.SetEnumLimit(enumLimit.ObjAttDes.Enum.Limit)

coreSvr.Config.Mongo, err = coreSvr.Core.WithMongo()
if err != nil {
return err
Expand Down