diff --git a/src/common/backbone/configcenter/viper.go b/src/common/backbone/configcenter/viper.go index 77a6704985..a4524b7e39 100644 --- a/src/common/backbone/configcenter/viper.go +++ b/src/common/backbone/configcenter/viper.go @@ -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() @@ -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 diff --git a/src/common/definitions.go b/src/common/definitions.go index 6bbe0f56ba..124a98df15 100644 --- a/src/common/definitions.go +++ b/src/common/definitions.go @@ -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 diff --git a/src/scene_server/admin_server/app/server.go b/src/scene_server/admin_server/app/server.go index 640c82374a..18bf2be006 100644 --- a/src/scene_server/admin_server/app/server.go +++ b/src/scene_server/admin_server/app/server.go @@ -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") diff --git a/src/source_controller/coreservice/app/server.go b/src/source_controller/coreservice/app/server.go index e6e53841b4..919706548f 100644 --- a/src/source_controller/coreservice/app/server.go +++ b/src/source_controller/coreservice/app/server.go @@ -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