mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 16:30:55 +01:00
lib/promscrape: print all the labels for the target on error message for failed scrape
This should improve debuggability. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/420
This commit is contained in:
parent
266bbec52d
commit
70104f3fb1
@ -1,7 +1,9 @@
|
||||
package promscrape
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil"
|
||||
@ -65,6 +67,15 @@ func (sw *ScrapeWork) Job() string {
|
||||
return promrelabel.GetLabelValueByName(sw.Labels, "job")
|
||||
}
|
||||
|
||||
// LabelsString returns labels in Prometheus format for the given sw.
|
||||
func (sw *ScrapeWork) LabelsString() string {
|
||||
labels := make([]string, 0, len(sw.Labels))
|
||||
for _, label := range promrelabel.FinalizeLabels(nil, sw.Labels) {
|
||||
labels = append(labels, fmt.Sprintf("%s=%q", label.Name, label.Value))
|
||||
}
|
||||
return "{" + strings.Join(labels, ", ") + "}"
|
||||
}
|
||||
|
||||
type scrapeWork struct {
|
||||
// Config for the scrape.
|
||||
Config ScrapeWork
|
||||
@ -119,12 +130,12 @@ func (sw *scrapeWork) run(stopCh <-chan struct{}) {
|
||||
}
|
||||
|
||||
func (sw *scrapeWork) logError(s string) {
|
||||
logger.ErrorfSkipframes(1, "error when scraping %q from job %q: %s", sw.Config.ScrapeURL, sw.Config.Job(), s)
|
||||
logger.ErrorfSkipframes(1, "error when scraping %q from job %q with labels %s: %s", sw.Config.ScrapeURL, sw.Config.Job(), sw.Config.LabelsString(), s)
|
||||
}
|
||||
|
||||
func (sw *scrapeWork) scrapeAndLogError(timestamp int64) {
|
||||
if err := sw.scrapeInternal(timestamp); err != nil {
|
||||
logger.Errorf("error when scraping %q from job %q: %s", sw.Config.ScrapeURL, sw.Config.Job(), err)
|
||||
logger.Errorf("error when scraping %q from job %q with labels %s: %s", sw.Config.ScrapeURL, sw.Config.Job(), sw.Config.LabelsString(), err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,11 +4,8 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promrelabel"
|
||||
)
|
||||
|
||||
var tsmGlobal = newTargetStatusMap()
|
||||
@ -104,11 +101,7 @@ func (tsm *targetStatusMap) WriteHumanReadable(w io.Writer) {
|
||||
if !st.up {
|
||||
state = "down"
|
||||
}
|
||||
var labels []string
|
||||
for _, label := range promrelabel.FinalizeLabels(nil, st.sw.Labels) {
|
||||
labels = append(labels, fmt.Sprintf("%s=%q", label.Name, label.Value))
|
||||
}
|
||||
labelsStr := "{" + strings.Join(labels, ", ") + "}"
|
||||
labelsStr := st.sw.LabelsString()
|
||||
lastScrape := st.getDurationFromLastScrape()
|
||||
errMsg := ""
|
||||
if st.err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user