mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-02-09 15:27:11 +00: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
2 changed files with 12 additions and 7 deletions
|
@ -60,6 +60,15 @@ type ScrapeWork struct {
|
||||||
SampleLimit int
|
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 {
|
type scrapeWork struct {
|
||||||
// Config for the scrape.
|
// Config for the scrape.
|
||||||
Config ScrapeWork
|
Config ScrapeWork
|
||||||
|
@ -114,12 +123,12 @@ func (sw *scrapeWork) run(stopCh <-chan struct{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sw *scrapeWork) logError(s string) {
|
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) {
|
func (sw *scrapeWork) scrapeAndLogError(timestamp int64) {
|
||||||
if err := sw.scrapeInternal(timestamp); err != nil {
|
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)
|
byJob := make(map[string][]targetStatus)
|
||||||
tsm.mu.Lock()
|
tsm.mu.Lock()
|
||||||
for _, st := range tsm.m {
|
for _, st := range tsm.m {
|
||||||
job := ""
|
job := st.sw.Job()
|
||||||
label := promrelabel.GetLabelByName(st.sw.Labels, "job")
|
|
||||||
if label != nil {
|
|
||||||
job = label.Value
|
|
||||||
}
|
|
||||||
byJob[job] = append(byJob[job], st)
|
byJob[job] = append(byJob[job], st)
|
||||||
}
|
}
|
||||||
tsm.mu.Unlock()
|
tsm.mu.Unlock()
|
||||||
|
|
Loading…
Reference in a new issue