mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-02-19 15:30:17 +00:00
lib/promscrape: properly expose statuses for targets with duplicate scrape urls at /targets
page
Previously targets with duplicate scrape urls were merged into a single line on the page. Now each target with duplicate scrape url is displayed on a separate line.
This commit is contained in:
parent
09f796e2ab
commit
88366cad15
3 changed files with 14 additions and 6 deletions
|
@ -7,6 +7,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
||||||
|
@ -474,6 +475,7 @@ func appendScrapeWork(dst []ScrapeWork, swc *scrapeWorkConfig, target string, ex
|
||||||
scrapeURL, swc.scheme, schemeRelabeled, target, targetRelabeled, swc.metricsPath, metricsPathRelabeled, swc.jobName, err)
|
scrapeURL, swc.scheme, schemeRelabeled, target, targetRelabeled, swc.metricsPath, metricsPathRelabeled, swc.jobName, err)
|
||||||
}
|
}
|
||||||
dst = append(dst, ScrapeWork{
|
dst = append(dst, ScrapeWork{
|
||||||
|
ID: atomic.AddUint64(&nextScrapeWorkID, 1),
|
||||||
ScrapeURL: scrapeURL,
|
ScrapeURL: scrapeURL,
|
||||||
ScrapeInterval: swc.scrapeInterval,
|
ScrapeInterval: swc.scrapeInterval,
|
||||||
ScrapeTimeout: swc.scrapeTimeout,
|
ScrapeTimeout: swc.scrapeTimeout,
|
||||||
|
@ -487,6 +489,9 @@ func appendScrapeWork(dst []ScrapeWork, swc *scrapeWorkConfig, target string, ex
|
||||||
return dst, nil
|
return dst, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Each ScrapeWork has an ID, which is used for locating it when updating its status.
|
||||||
|
var nextScrapeWorkID uint64
|
||||||
|
|
||||||
func getParamsFromLabels(labels []prompbmarshal.Label, paramsOrig map[string][]string) map[string][]string {
|
func getParamsFromLabels(labels []prompbmarshal.Label, paramsOrig map[string][]string) map[string][]string {
|
||||||
// See https://www.robustperception.io/life-of-a-label
|
// See https://www.robustperception.io/life-of-a-label
|
||||||
m := make(map[string][]string)
|
m := make(map[string][]string)
|
||||||
|
|
|
@ -15,6 +15,9 @@ import (
|
||||||
|
|
||||||
// ScrapeWork represents a unit of work for scraping Prometheus metrics.
|
// ScrapeWork represents a unit of work for scraping Prometheus metrics.
|
||||||
type ScrapeWork struct {
|
type ScrapeWork struct {
|
||||||
|
// Unique ID for the ScrapeWork.
|
||||||
|
ID uint64
|
||||||
|
|
||||||
// Full URL (including query args) for the scrape.
|
// Full URL (including query args) for the scrape.
|
||||||
ScrapeURL string
|
ScrapeURL string
|
||||||
|
|
||||||
|
|
|
@ -20,18 +20,18 @@ func WriteHumanReadableTargetsStatus(w io.Writer) {
|
||||||
|
|
||||||
type targetStatusMap struct {
|
type targetStatusMap struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
m map[string]targetStatus
|
m map[uint64]targetStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTargetStatusMap() *targetStatusMap {
|
func newTargetStatusMap() *targetStatusMap {
|
||||||
return &targetStatusMap{
|
return &targetStatusMap{
|
||||||
m: make(map[string]targetStatus),
|
m: make(map[uint64]targetStatus),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tsm *targetStatusMap) Reset() {
|
func (tsm *targetStatusMap) Reset() {
|
||||||
tsm.mu.Lock()
|
tsm.mu.Lock()
|
||||||
tsm.m = make(map[string]targetStatus)
|
tsm.m = make(map[uint64]targetStatus)
|
||||||
tsm.mu.Unlock()
|
tsm.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ func (tsm *targetStatusMap) RegisterAll(sws []ScrapeWork) {
|
||||||
tsm.mu.Lock()
|
tsm.mu.Lock()
|
||||||
for i := range sws {
|
for i := range sws {
|
||||||
sw := &sws[i]
|
sw := &sws[i]
|
||||||
tsm.m[sw.ScrapeURL] = targetStatus{
|
tsm.m[sw.ID] = targetStatus{
|
||||||
sw: sw,
|
sw: sw,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,14 +49,14 @@ func (tsm *targetStatusMap) RegisterAll(sws []ScrapeWork) {
|
||||||
func (tsm *targetStatusMap) UnregisterAll(sws []ScrapeWork) {
|
func (tsm *targetStatusMap) UnregisterAll(sws []ScrapeWork) {
|
||||||
tsm.mu.Lock()
|
tsm.mu.Lock()
|
||||||
for i := range sws {
|
for i := range sws {
|
||||||
delete(tsm.m, sws[i].ScrapeURL)
|
delete(tsm.m, sws[i].ID)
|
||||||
}
|
}
|
||||||
tsm.mu.Unlock()
|
tsm.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tsm *targetStatusMap) Update(sw *ScrapeWork, up bool, scrapeTime, scrapeDuration int64, err error) {
|
func (tsm *targetStatusMap) Update(sw *ScrapeWork, up bool, scrapeTime, scrapeDuration int64, err error) {
|
||||||
tsm.mu.Lock()
|
tsm.mu.Lock()
|
||||||
tsm.m[sw.ScrapeURL] = targetStatus{
|
tsm.m[sw.ID] = targetStatus{
|
||||||
sw: sw,
|
sw: sw,
|
||||||
up: up,
|
up: up,
|
||||||
scrapeTime: scrapeTime,
|
scrapeTime: scrapeTime,
|
||||||
|
|
Loading…
Reference in a new issue