This commit is contained in:
Bryan Boreham 2025-03-05 18:45:18 +00:00 committed by GitHub
commit ede5b574be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 2 deletions

View file

@ -1034,9 +1034,8 @@ func (c *scrapeCache) iterDone(flushCache bool) {
}
}
c.metaMtx.Unlock()
c.iter++
}
c.iter++
// Swap current and previous series.
c.seriesPrev, c.seriesCur = c.seriesCur, c.seriesPrev

View file

@ -5153,3 +5153,38 @@ func TestScrapePoolScrapeAfterReload(t *testing.T) {
<-time.After(1 * time.Second)
}
// Regression test against https://github.com/prometheus/prometheus/issues/16160.
func TestScrapeAppendWithParseError(t *testing.T) {
const (
scrape1 = `metric_a 1
`
scrape2 = `metric_a 11
# EOF`
)
sl := newBasicScrapeLoop(t, context.Background(), nil, nil, 0)
sl.cache = newScrapeCache(sl.metrics)
now := time.Now()
capp := &collectResultAppender{next: nopAppender{}}
_, _, _, err := sl.append(capp, []byte(scrape1), "application/openmetrics-text", now)
require.Error(t, err)
_, _, _, err = sl.append(capp, nil, "application/openmetrics-text", now)
require.NoError(t, err)
require.Empty(t, capp.resultFloats)
capp = &collectResultAppender{next: nopAppender{}}
_, _, _, err = sl.append(capp, []byte(scrape2), "application/openmetrics-text", now.Add(15*time.Second))
require.NoError(t, err)
require.NoError(t, capp.Commit())
want := []floatSample{
{
metric: labels.FromStrings(model.MetricNameLabel, "metric_a"),
t: timestamp.FromTime(now.Add(15 * time.Second)),
f: 11,
},
}
requireEqual(t, want, capp.resultFloats, "Appended samples not as expected:\n%s", capp)
}