Add scrape_samples_post_metric_relabeling

This reports the number of samples post any keep/drop
from metric relabelling.
This commit is contained in:
Brian Brazil 2016-12-13 17:32:11 +00:00
parent 06b9df65ec
commit c8de1484d5
2 changed files with 30 additions and 7 deletions

View file

@ -33,9 +33,10 @@ import (
)
const (
scrapeHealthMetricName = "up"
scrapeDurationMetricName = "scrape_duration_seconds"
scrapeSamplesMetricName = "scrape_samples_scraped"
scrapeHealthMetricName = "up"
scrapeDurationMetricName = "scrape_duration_seconds"
scrapeSamplesMetricName = "scrape_samples_scraped"
samplesPostRelabelMetricName = "scrape_samples_post_metric_relabeling"
)
var (
@ -451,9 +452,9 @@ func (sl *scrapeLoop) stop() {
}
func (sl *scrapeLoop) processScrapeResult(samples model.Samples, scrapeErr error, start time.Time) error {
// Collect samples post-relabelling and label handling in a buffer.
buf := &bufferAppender{buffer: make(model.Samples, 0, len(samples))}
if scrapeErr == nil {
// Collect samples post-relabelling and label handling in a buffer.
buf := &bufferAppender{buffer: make(model.Samples, 0, len(samples))}
app := sl.mutator(buf)
for _, sample := range samples {
app.Append(sample)
@ -463,7 +464,7 @@ func (sl *scrapeLoop) processScrapeResult(samples model.Samples, scrapeErr error
sl.append(buf.buffer)
}
sl.report(start, time.Since(start), len(samples), scrapeErr)
sl.report(start, time.Since(start), len(samples), len(buf.buffer), scrapeErr)
return scrapeErr
}
@ -495,7 +496,7 @@ func (sl *scrapeLoop) append(samples model.Samples) {
}
}
func (sl *scrapeLoop) report(start time.Time, duration time.Duration, scrapedSamples int, err error) {
func (sl *scrapeLoop) report(start time.Time, duration time.Duration, scrapedSamples, postRelabelSamples int, err error) {
sl.scraper.report(start, duration, err)
ts := model.TimeFromUnixNano(start.UnixNano())
@ -526,6 +527,13 @@ func (sl *scrapeLoop) report(start time.Time, duration time.Duration, scrapedSam
Timestamp: ts,
Value: model.SampleValue(scrapedSamples),
}
postRelabelSample := &model.Sample{
Metric: model.Metric{
model.MetricNameLabel: samplesPostRelabelMetricName,
},
Timestamp: ts,
Value: model.SampleValue(postRelabelSamples),
}
if err := sl.reportAppender.Append(healthSample); err != nil {
log.With("sample", healthSample).With("error", err).Warn("Scrape health sample discarded")
@ -536,4 +544,7 @@ func (sl *scrapeLoop) report(start time.Time, duration time.Duration, scrapedSam
if err := sl.reportAppender.Append(countSample); err != nil {
log.With("sample", durationSample).With("error", err).Warn("Scrape sample count sample discarded")
}
if err := sl.reportAppender.Append(postRelabelSample); err != nil {
log.With("sample", durationSample).With("error", err).Warn("Scrape sample count post-relabelling sample discarded")
}
}

View file

@ -332,6 +332,10 @@ func TestScrapeLoopSampleProcessing(t *testing.T) {
Metric: model.Metric{"__name__": "scrape_samples_scraped"},
Value: 2,
},
{
Metric: model.Metric{"__name__": "scrape_samples_post_metric_relabeling"},
Value: 2,
},
},
expectedIngestedSamplesCount: 2,
},
@ -357,6 +361,10 @@ func TestScrapeLoopSampleProcessing(t *testing.T) {
Metric: model.Metric{"__name__": "scrape_samples_scraped"},
Value: 2,
},
{
Metric: model.Metric{"__name__": "scrape_samples_post_metric_relabeling"},
Value: 1,
},
},
expectedIngestedSamplesCount: 1,
},
@ -376,6 +384,10 @@ func TestScrapeLoopSampleProcessing(t *testing.T) {
Metric: model.Metric{"__name__": "scrape_samples_scraped"},
Value: 0,
},
{
Metric: model.Metric{"__name__": "scrape_samples_post_metric_relabeling"},
Value: 0,
},
},
expectedIngestedSamplesCount: 0,
},