From 6055a897130b1f958100b0dbd887eb94be3491f7 Mon Sep 17 00:00:00 2001 From: smellthemoon <64083300+smellthemoon@users.noreply.github.com> Date: Fri, 15 Mar 2024 21:35:04 +0800 Subject: [PATCH] enhance: support merge multi yaml files (#30910) related with: #22556 Signed-off-by: lixinguo Co-authored-by: lixinguo --- pkg/util/paramtable/base_table.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/pkg/util/paramtable/base_table.go b/pkg/util/paramtable/base_table.go index daa0b363515ad..15afbfe378cbb 100644 --- a/pkg/util/paramtable/base_table.go +++ b/pkg/util/paramtable/base_table.go @@ -19,7 +19,6 @@ import ( "sync" "time" - "github.com/samber/lo" "go.uber.org/zap" config "github.com/milvus-io/milvus/pkg/config" @@ -60,7 +59,9 @@ func globalConfigPrefixs() []string { return []string{"metastore", "localStorage", "etcd", "tikv", "minio", "pulsar", "kafka", "rocksmq", "log", "grpc", "common", "quotaAndLimits"} } -var defaultYaml = []string{"milvus.yaml"} +// support read "milvus.yaml", "default.yaml", "user.yaml" as this order. +// order: milvus.yaml < default.yaml < user.yaml, do not change the order below +var defaultYaml = []string{"milvus.yaml", "default.yaml", "user.yaml"} // BaseTable the basics of paramtable type BaseTable struct { @@ -152,10 +153,22 @@ func (bt *BaseTable) init() { func (bt *BaseTable) initConfigsFromLocal() { refreshInterval := bt.config.refreshInterval + var files []string + for _, file := range bt.config.yamlFiles { + _, err := os.Stat(path.Join(bt.config.configDir, file)) + // not found + if os.IsNotExist(err) { + continue + } + if err != nil { + log.Warn("failed to check file", zap.String("file", file), zap.Error(err)) + panic(err) + } + files = append(files, path.Join(bt.config.configDir, file)) + } + err := bt.mgr.AddSource(config.NewFileSource(&config.FileInfo{ - Files: lo.Map(bt.config.yamlFiles, func(file string, _ int) string { - return path.Join(bt.config.configDir, file) - }), + Files: files, RefreshInterval: time.Duration(refreshInterval) * time.Second, })) if err != nil {