Skip to content

Commit

Permalink
Fix Auto metrics relabeled errors (#593)
Browse files Browse the repository at this point in the history
* Fix Auto metrics relabeled errors

* Finalize auto-genenated  Labels

* Fix Test Errors

Co-authored-by: xinyulong <xinyulong@kuaishou.com>
  • Loading branch information
2 people authored and valyala committed Jun 29, 2020
1 parent 156c83d commit b42cf33
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
12 changes: 8 additions & 4 deletions lib/promscrape/scrapework.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
sw.labels = promrelabel.ApplyRelabelConfigs(sw.labels, labelsLen, sw.Config.MetricRelabelConfigs, true)
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
Expand Down
9 changes: 5 additions & 4 deletions lib/promscrape/scrapework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b42cf33

Please sign in to comment.