mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Add scrape_samples_post_metric_relabeling
This reports the number of samples post any keep/drop from metric relabelling.
This commit is contained in:
parent
06b9df65ec
commit
c8de1484d5
|
@ -33,9 +33,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
scrapeHealthMetricName = "up"
|
scrapeHealthMetricName = "up"
|
||||||
scrapeDurationMetricName = "scrape_duration_seconds"
|
scrapeDurationMetricName = "scrape_duration_seconds"
|
||||||
scrapeSamplesMetricName = "scrape_samples_scraped"
|
scrapeSamplesMetricName = "scrape_samples_scraped"
|
||||||
|
samplesPostRelabelMetricName = "scrape_samples_post_metric_relabeling"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -451,9 +452,9 @@ func (sl *scrapeLoop) stop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sl *scrapeLoop) processScrapeResult(samples model.Samples, scrapeErr error, start time.Time) error {
|
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 {
|
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)
|
app := sl.mutator(buf)
|
||||||
for _, sample := range samples {
|
for _, sample := range samples {
|
||||||
app.Append(sample)
|
app.Append(sample)
|
||||||
|
@ -463,7 +464,7 @@ func (sl *scrapeLoop) processScrapeResult(samples model.Samples, scrapeErr error
|
||||||
sl.append(buf.buffer)
|
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
|
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)
|
sl.scraper.report(start, duration, err)
|
||||||
|
|
||||||
ts := model.TimeFromUnixNano(start.UnixNano())
|
ts := model.TimeFromUnixNano(start.UnixNano())
|
||||||
|
@ -526,6 +527,13 @@ func (sl *scrapeLoop) report(start time.Time, duration time.Duration, scrapedSam
|
||||||
Timestamp: ts,
|
Timestamp: ts,
|
||||||
Value: model.SampleValue(scrapedSamples),
|
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 {
|
if err := sl.reportAppender.Append(healthSample); err != nil {
|
||||||
log.With("sample", healthSample).With("error", err).Warn("Scrape health sample discarded")
|
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 {
|
if err := sl.reportAppender.Append(countSample); err != nil {
|
||||||
log.With("sample", durationSample).With("error", err).Warn("Scrape sample count sample discarded")
|
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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -332,6 +332,10 @@ func TestScrapeLoopSampleProcessing(t *testing.T) {
|
||||||
Metric: model.Metric{"__name__": "scrape_samples_scraped"},
|
Metric: model.Metric{"__name__": "scrape_samples_scraped"},
|
||||||
Value: 2,
|
Value: 2,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Metric: model.Metric{"__name__": "scrape_samples_post_metric_relabeling"},
|
||||||
|
Value: 2,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
expectedIngestedSamplesCount: 2,
|
expectedIngestedSamplesCount: 2,
|
||||||
},
|
},
|
||||||
|
@ -357,6 +361,10 @@ func TestScrapeLoopSampleProcessing(t *testing.T) {
|
||||||
Metric: model.Metric{"__name__": "scrape_samples_scraped"},
|
Metric: model.Metric{"__name__": "scrape_samples_scraped"},
|
||||||
Value: 2,
|
Value: 2,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Metric: model.Metric{"__name__": "scrape_samples_post_metric_relabeling"},
|
||||||
|
Value: 1,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
expectedIngestedSamplesCount: 1,
|
expectedIngestedSamplesCount: 1,
|
||||||
},
|
},
|
||||||
|
@ -376,6 +384,10 @@ func TestScrapeLoopSampleProcessing(t *testing.T) {
|
||||||
Metric: model.Metric{"__name__": "scrape_samples_scraped"},
|
Metric: model.Metric{"__name__": "scrape_samples_scraped"},
|
||||||
Value: 0,
|
Value: 0,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Metric: model.Metric{"__name__": "scrape_samples_post_metric_relabeling"},
|
||||||
|
Value: 0,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
expectedIngestedSamplesCount: 0,
|
expectedIngestedSamplesCount: 0,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue