Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Auto metrics relabeled errors #593

Merged
merged 3 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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