mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-07 01:28:27 +08:00
feature: add a prefix on environment config (#40623)
fix #40622 Signed-off-by: xiaofanluan <xiaofan.luan@zilliz.com>
This commit is contained in:
parent
f6fb4bc442
commit
7210fc9780
@ -24,15 +24,20 @@ import (
|
|||||||
"github.com/milvus-io/milvus/pkg/v2/util/typeutil"
|
"github.com/milvus-io/milvus/pkg/v2/util/typeutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DefaultEnvPrefix is the default prefix for environment variables
|
||||||
|
const DefaultEnvPrefix = "MILVUS_CONF_"
|
||||||
|
|
||||||
type EnvSource struct {
|
type EnvSource struct {
|
||||||
configs *typeutil.ConcurrentMap[string, string]
|
configs *typeutil.ConcurrentMap[string, string]
|
||||||
KeyFormatter func(string) string
|
KeyFormatter func(string) string
|
||||||
|
prefix string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEnvSource(KeyFormatter func(string) string) EnvSource {
|
func NewEnvSource(KeyFormatter func(string) string) EnvSource {
|
||||||
es := EnvSource{
|
es := EnvSource{
|
||||||
configs: typeutil.NewConcurrentMap[string, string](),
|
configs: typeutil.NewConcurrentMap[string, string](),
|
||||||
KeyFormatter: KeyFormatter,
|
KeyFormatter: KeyFormatter,
|
||||||
|
prefix: DefaultEnvPrefix,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, value := range os.Environ() {
|
for _, value := range os.Environ() {
|
||||||
@ -43,6 +48,15 @@ func NewEnvSource(KeyFormatter func(string) string) EnvSource {
|
|||||||
envKey := KeyFormatter(key)
|
envKey := KeyFormatter(key)
|
||||||
es.configs.Insert(key, value)
|
es.configs.Insert(key, value)
|
||||||
es.configs.Insert(envKey, value)
|
es.configs.Insert(envKey, value)
|
||||||
|
|
||||||
|
// Handle prefixed environment variables
|
||||||
|
// e.g., MILVUS_MINIO_PORT will override MINIO_PORT
|
||||||
|
if strings.HasPrefix(key, es.prefix) {
|
||||||
|
originalKey := key[len(es.prefix):]
|
||||||
|
originalEnvKey := KeyFormatter(originalKey)
|
||||||
|
es.configs.Insert(originalKey, value)
|
||||||
|
es.configs.Insert(originalEnvKey, value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return es
|
return es
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user