File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
internal/prometheus_adapter/config Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -42,9 +42,27 @@ type ServerConfig struct {
4242
4343// LoadConfig 加载配置文件
4444func LoadConfig (configPath string ) (* PrometheusAdapterConfig , error ) {
45- // 如果没有指定配置文件,使用默认路径
45+ // 如果没有指定配置文件,尝试多个默认路径
4646 if configPath == "" {
47- configPath = "internal/prometheus_adapter/config/prometheus_adapter.yml"
47+ // 尝试的路径列表(按优先级)
48+ possiblePaths := []string {
49+ "config/prometheus_adapter.yml" , // 部署环境:相对于工作目录
50+ "internal/prometheus_adapter/config/prometheus_adapter.yml" , // 开发环境:源码目录
51+ "./prometheus_adapter.yml" , // 当前目录
52+ }
53+
54+ for _ , path := range possiblePaths {
55+ if _ , err := os .Stat (path ); err == nil {
56+ configPath = path
57+ log .Info ().Str ("path" , path ).Msg ("Found config file" )
58+ break
59+ }
60+ }
61+
62+ // 如果都找不到,使用第一个路径(稍后会返回默认配置)
63+ if configPath == "" {
64+ configPath = possiblePaths [0 ]
65+ }
4866 }
4967
5068 // 读取配置文件
You can’t perform that action at this time.
0 commit comments