diff --git a/lib/promscrape/scrapework.go b/lib/promscrape/scrapework.go index 28b28530f..155e5f15e 100644 --- a/lib/promscrape/scrapework.go +++ b/lib/promscrape/scrapework.go @@ -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) } } diff --git a/lib/promscrape/targetstatus.go b/lib/promscrape/targetstatus.go index 0c3759006..b362d9a84 100644 --- a/lib/promscrape/targetstatus.go +++ b/lib/promscrape/targetstatus.go @@ -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()