From fd596945e7332f3d0927ad0cbae78a85fa89a2ec Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 8 Nov 2021 13:33:29 +0200 Subject: [PATCH] lib/promscrape: improve logging for `scrape_config_files` parse errors Log the actual file path, which led to the parse error. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1789 --- lib/promscrape/config.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/promscrape/config.go b/lib/promscrape/config.go index de2b5eebf7..ff49447715 100644 --- a/lib/promscrape/config.go +++ b/lib/promscrape/config.go @@ -262,7 +262,7 @@ func loadScrapeConfigFiles(baseDir string, scrapeConfigFiles []string) ([]Scrape if strings.Contains(filePath, "*") { ps, err := filepath.Glob(filePath) if err != nil { - return nil, nil, fmt.Errorf("invalid pattern %q in `scrape_config_files`: %w", filePath, err) + return nil, nil, fmt.Errorf("invalid pattern %q: %w", filePath, err) } sort.Strings(ps) paths = ps @@ -270,12 +270,12 @@ func loadScrapeConfigFiles(baseDir string, scrapeConfigFiles []string) ([]Scrape for _, path := range paths { data, err := ioutil.ReadFile(path) if err != nil { - return nil, nil, fmt.Errorf("cannot load %q from `scrape_config_files`: %w", filePath, err) + return nil, nil, fmt.Errorf("cannot load %q: %w", path, err) } data = envtemplate.Replace(data) var scs []ScrapeConfig if err = yaml.UnmarshalStrict(data, &scs); err != nil { - return nil, nil, fmt.Errorf("cannot parse %q from `scrape_config_files`: %w", filePath, err) + return nil, nil, fmt.Errorf("cannot parse %q: %w", path, err) } scrapeConfigs = append(scrapeConfigs, scs...) scsData = append(scsData, '\n')