Skip to content

Commit 911a435

Browse files
committed
chore:添加枚举值配置项 --story=125661369
1 parent cc45f93 commit 911a435

File tree

4 files changed

+71
-3
lines changed

4 files changed

+71
-3
lines changed

src/common/backbone/configcenter/viper.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,46 @@ func Mongo(prefix string) (mongo.Config, error) {
389389
return c, nil
390390
}
391391

392+
type enum struct {
393+
Limit int `json:"limit" yaml:"limit" mapstructure:"limit"`
394+
}
395+
type objAttDes struct {
396+
Enum enum `json:"enum" yaml:"enum" mapstructure:"enum"`
397+
}
398+
399+
// ExtraConfig extral.yaml config
400+
type ExtraConfig struct {
401+
ObjAttDes objAttDes `json:"objAttDes" yaml:"objAttDes" mapstructure:"objAttDes"`
402+
}
403+
404+
// Extra return extra configuration information according to the prefix.
405+
func Extra(prefix string) (ExtraConfig, error) {
406+
confLock.RLock()
407+
defer confLock.RUnlock()
408+
var parser *viperParser
409+
for sleepCnt := 0; sleepCnt < common.APPConfigWaitTime; sleepCnt++ {
410+
parser = getExtraParser()
411+
if parser != nil {
412+
break
413+
}
414+
blog.Warn("the configuration of extra is not ready yet")
415+
time.Sleep(time.Duration(1) * time.Second)
416+
}
417+
418+
if parser == nil {
419+
blog.Errorf("can't find extra configuration")
420+
return ExtraConfig{}, errors.New("can't find extra configuration")
421+
}
422+
423+
return ExtraConfig{
424+
ObjAttDes: objAttDes{
425+
Enum: enum{
426+
Limit: parser.getInt(prefix + ".enum.limit"),
427+
},
428+
},
429+
}, nil
430+
}
431+
392432
// Kafka return kafka configuration information according to the prefix.
393433
func Kafka(prefix string) (kafka.Config, error) {
394434
confLock.RLock()
@@ -568,6 +608,14 @@ func getMongodbParser() *viperParser {
568608
return localParser
569609
}
570610

611+
func getExtraParser() *viperParser {
612+
if extraParser != nil {
613+
return extraParser
614+
}
615+
616+
return localParser
617+
}
618+
571619
func getCommonParser() *viperParser {
572620
if commonParser != nil {
573621
return commonParser

src/common/definitions.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,12 +1559,22 @@ const (
15591559
AttributeUnitMaxLength = 20
15601560
// AttributeOptionValueMaxLength TODO
15611561
AttributeOptionValueMaxLength = 128
1562-
// AttributeOptionArrayMaxLength TODO
1563-
AttributeOptionArrayMaxLength = 200
15641562
// ServiceCategoryMaxLength TODO
15651563
ServiceCategoryMaxLength = 128
15661564
)
15671565

1566+
var (
1567+
// AttributeOptionArrayMaxLength TODO
1568+
AttributeOptionArrayMaxLength = 200
1569+
)
1570+
1571+
// SetEnumLimit set AttributeOptionArrayMaxLength value,max:1000
1572+
func SetEnumLimit(l int) {
1573+
if l > 0 {
1574+
AttributeOptionArrayMaxLength = int(math.Min(float64(l), float64(1000)))
1575+
}
1576+
}
1577+
15681578
const (
15691579
// NameFieldMaxLength TODO
15701580
NameFieldMaxLength = 256

src/scene_server/admin_server/app/server.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ func parseSeverConfig(ctx context.Context, op *options.ServerOption) (*MigrateSe
166166
return nil, fmt.Errorf("parse common config from file[%s] failed, err: %v", commonPath, err)
167167
}
168168

169+
extraPath := process.Config.Configures.Dir + "/" + types.CCConfigureExtra
170+
if err := cc.SetExtraFromFile(extraPath); err != nil {
171+
return nil, fmt.Errorf("parse extra config from file[%s] failed, err: %v", extraPath, err)
172+
}
173+
169174
process.Config.SnapReportMode, _ = cc.String("datacollection.hostsnap.reportMode")
170175
process.Config.SnapKafka, _ = cc.Kafka("kafka.snap")
171176

src/source_controller/coreservice/app/server.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,12 @@ func Run(ctx context.Context, cancel context.CancelFunc, op *options.ServerOptio
112112
}
113113

114114
func initResource(coreSvr *CoreServer, op *options.ServerOption) error {
115-
var err error
115+
enumLimit, err := cc.Extra("objAttDes")
116+
if err != nil {
117+
return fmt.Errorf("read extraConfig with key limit err:%w", err)
118+
}
119+
common.SetEnumLimit(enumLimit.ObjAttDes.Enum.Limit)
120+
116121
coreSvr.Config.Mongo, err = coreSvr.Core.WithMongo()
117122
if err != nil {
118123
return err

0 commit comments

Comments
 (0)