解析Prometheus配置文件出现:kubernetes_sd_configs not found in type config.ScrapeConfig
import (
...
"github.com/prometheus/prometheus/config"
...
)
func Unmarshal() {
cfg, err := config.Load(string("config string data"))
cfg, err := config.LoadFile(string("config file ptah"))
}
引用 "github.com/prometheus/prometheus/config"
解析Prometheus配置文件时会如下错误出现:
line 21: field kubernetes_sd_configs not found in type config.ScrapeConfig
line 49: field kubernetes_sd_configs not found in type config.ScrapeConfig
解决办法:
导入_ "github.com/prometheus/prometheus/discovery/install"
初始化动态发现服务,该方法适用于其他动态发现服务的同类报错。
import (
...
_ "github.com/prometheus/prometheus/discovery/install
"github.com/prometheus/prometheus/config"
...
)
func Unmarshal() {
cfg, err := config.Load(string("config string data"))
cfg, err := config.LoadFile(string("config file ptah"))
}