lib/promscrape: cosmetic changes after 3ac44baebe

- Rename mustLoadScrapeConfigFiles() to loadScrapeConfigFiles(), since now it may return error.
- Split too long line with the error message into two lines in order to improve readability a bit.

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5508
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5560
This commit is contained in:
Aliaksandr Valialkin 2024-01-16 22:29:05 +02:00
parent c830064c2f
commit 41932db848
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB

View file

@ -438,7 +438,7 @@ func loadConfig(path string) (*Config, error) {
return &c, nil
}
func mustLoadScrapeConfigFiles(baseDir string, scrapeConfigFiles []string, isStrict bool) ([]*ScrapeConfig, error) {
func loadScrapeConfigFiles(baseDir string, scrapeConfigFiles []string, isStrict bool) ([]*ScrapeConfig, error) {
var scrapeConfigs []*ScrapeConfig
for _, filePath := range scrapeConfigFiles {
filePath := fs.GetFilepath(baseDir, filePath)
@ -466,7 +466,8 @@ func mustLoadScrapeConfigFiles(baseDir string, scrapeConfigFiles []string, isStr
var scs []*ScrapeConfig
if isStrict {
if err = yaml.UnmarshalStrict(data, &scs); err != nil {
return nil, fmt.Errorf("cannot unmarshal data from `scrape_config_files` %s: %w; pass -promscrape.config.strictParse=false command-line flag for ignoring unknown fields in yaml config", path, err)
return nil, fmt.Errorf("cannot unmarshal data from `scrape_config_files` %s: %w; "+
"pass -promscrape.config.strictParse=false command-line flag for ignoring invalid scrape_config_files", path, err)
}
} else {
if err = yaml.Unmarshal(data, &scs); err != nil {
@ -498,7 +499,7 @@ func (cfg *Config) parseData(data []byte, path string) error {
cfg.baseDir = filepath.Dir(absPath)
// Load cfg.ScrapeConfigFiles into c.ScrapeConfigs
scs, err := mustLoadScrapeConfigFiles(cfg.baseDir, cfg.ScrapeConfigFiles, *strictParse)
scs, err := loadScrapeConfigFiles(cfg.baseDir, cfg.ScrapeConfigFiles, *strictParse)
if err != nil {
return err
}