mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
Fix Auto metrics relabeled errors (#593)
* Fix Auto metrics relabeled errors * Finalize auto-genenated Labels * Fix Test Errors Co-authored-by: xinyulong <xinyulong@kuaishou.com>
This commit is contained in:
parent
156c83d112
commit
b42cf33c4d
2 changed files with 13 additions and 8 deletions
|
@ -207,7 +207,7 @@ func (sw *scrapeWork) scrapeInternal(timestamp int64) error {
|
|||
samplesScraped := len(srcRows)
|
||||
scrapedSamples.Update(float64(samplesScraped))
|
||||
for i := range srcRows {
|
||||
sw.addRowToTimeseries(&srcRows[i], timestamp)
|
||||
sw.addRowToTimeseries(&srcRows[i], timestamp, true)
|
||||
}
|
||||
sw.rows.Reset()
|
||||
if sw.Config.SampleLimit > 0 && len(sw.writeRequest.Timeseries) > sw.Config.SampleLimit {
|
||||
|
@ -238,13 +238,17 @@ func (sw *scrapeWork) addAutoTimeseries(name string, value float64, timestamp in
|
|||
sw.tmpRow.Tags = nil
|
||||
sw.tmpRow.Value = value
|
||||
sw.tmpRow.Timestamp = timestamp
|
||||
sw.addRowToTimeseries(&sw.tmpRow, timestamp)
|
||||
sw.addRowToTimeseries(&sw.tmpRow, timestamp, false)
|
||||
}
|
||||
|
||||
func (sw *scrapeWork) addRowToTimeseries(r *parser.Row, timestamp int64) {
|
||||
func (sw *scrapeWork) addRowToTimeseries(r *parser.Row, timestamp int64, needRelabel bool) {
|
||||
labelsLen := len(sw.labels)
|
||||
sw.labels = appendLabels(sw.labels, r.Metric, r.Tags, sw.Config.Labels, sw.Config.HonorLabels)
|
||||
if needRelabel {
|
||||
sw.labels = promrelabel.ApplyRelabelConfigs(sw.labels, labelsLen, sw.Config.MetricRelabelConfigs, true)
|
||||
} else {
|
||||
sw.labels = promrelabel.FinalizeLabels(sw.labels[:labelsLen], sw.labels[labelsLen:])
|
||||
}
|
||||
if len(sw.labels) == labelsLen {
|
||||
// Skip row without labels.
|
||||
return
|
||||
|
|
|
@ -245,10 +245,10 @@ func TestScrapeWorkScrapeInternalSuccess(t *testing.T) {
|
|||
}, `
|
||||
foo{bar="baz",job="xx",instance="foo.com/xx"} 34.44 123
|
||||
bar{a="b",job="xx",instance="foo.com/xx"} -3e4 123
|
||||
up{job="xx",instance="foo.com/xx"} 1 123
|
||||
scrape_samples_scraped{job="xx",instance="foo.com/xx"} 2 123
|
||||
scrape_duration_seconds{job="xx",instance="foo.com/xx"} 0 123
|
||||
scrape_samples_post_metric_relabeling{job="xx",instance="foo.com/xx"} 2 123
|
||||
up{job="xx"} 1 123
|
||||
scrape_samples_scraped{job="xx"} 2 123
|
||||
scrape_duration_seconds{job="xx"} 0 123
|
||||
scrape_samples_post_metric_relabeling{job="xx"} 2 123
|
||||
`)
|
||||
f(`
|
||||
foo{bar="baz"} 34.44
|
||||
|
@ -281,6 +281,7 @@ func TestScrapeWorkScrapeInternalSuccess(t *testing.T) {
|
|||
},
|
||||
}, `
|
||||
foo{bar="baz",job="xx",instance="foo.com"} 34.44 123
|
||||
up{job="xx",instance="foo.com"} 1 123
|
||||
scrape_samples_scraped{job="xx",instance="foo.com"} 4 123
|
||||
scrape_duration_seconds{job="xx",instance="foo.com"} 0 123
|
||||
scrape_samples_post_metric_relabeling{job="xx",instance="foo.com"} 1 123
|
||||
|
|
Loading…
Reference in a new issue