mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 08:23:34 +01:00
lib/promscrape: mention job name in error messages when target cannot be scraped
This should improve debuggability
This commit is contained in:
parent
66da177fe9
commit
3945bf9dec
@ -60,6 +60,15 @@ type ScrapeWork struct {
|
||||
SampleLimit int
|
||||
}
|
||||
|
||||
// Job returns job for the ScrapeWork
|
||||
func (sw *ScrapeWork) Job() string {
|
||||
label := promrelabel.GetLabelByName(sw.Labels, "job")
|
||||
if label == nil {
|
||||
return ""
|
||||
}
|
||||
return label.Value
|
||||
}
|
||||
|
||||
type scrapeWork struct {
|
||||
// Config for the scrape.
|
||||
Config ScrapeWork
|
||||
@ -114,12 +123,12 @@ func (sw *scrapeWork) run(stopCh <-chan struct{}) {
|
||||
}
|
||||
|
||||
func (sw *scrapeWork) logError(s string) {
|
||||
logger.ErrorfSkipframes(1, "error when scraping %q: %s", sw.Config.ScrapeURL, s)
|
||||
logger.ErrorfSkipframes(1, "error when scraping %q from job %q: %s", sw.Config.ScrapeURL, sw.Config.Job(), s)
|
||||
}
|
||||
|
||||
func (sw *scrapeWork) scrapeAndLogError(timestamp int64) {
|
||||
if err := sw.scrapeInternal(timestamp); err != nil {
|
||||
logger.Errorf("error when scraping %q: %s", sw.Config.ScrapeURL, err)
|
||||
logger.Errorf("error when scraping %q from job %q: %s", sw.Config.ScrapeURL, sw.Config.Job(), err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,11 +70,7 @@ func (tsm *targetStatusMap) WriteHumanReadable(w io.Writer) {
|
||||
byJob := make(map[string][]targetStatus)
|
||||
tsm.mu.Lock()
|
||||
for _, st := range tsm.m {
|
||||
job := ""
|
||||
label := promrelabel.GetLabelByName(st.sw.Labels, "job")
|
||||
if label != nil {
|
||||
job = label.Value
|
||||
}
|
||||
job := st.sw.Job()
|
||||
byJob[job] = append(byJob[job], st)
|
||||
}
|
||||
tsm.mu.Unlock()
|
||||
|
Loading…
Reference in New Issue
Block a user