lib/promscrape: allow scraping targets with responses equal to c.maxScrapeSize

Return "too big response size" error only for responses bigger than c.maxScrapeSize
(this option can be set either via max_scrape_size option inside scrape config
or via -promscrape.maxScrapeSize command-line flag).

Previously responses with sizes equal to c.maxScrapeSize were incorrectly rejected.
This commit is contained in:
Aliaksandr Valialkin
2025-12-11 16:13:24 +01:00
parent 1dc71212f8
commit 712b7cfeeb

View File

@@ -167,7 +167,7 @@ func (c *client) ReadData(dst *chunkedbuffer.Buffer) (bool, error) {
scrapesOK.Inc()
// Read the data from resp.Body
lr := ioutil.GetLimitedReader(resp.Body, c.maxScrapeSize)
lr := ioutil.GetLimitedReader(resp.Body, c.maxScrapeSize+1)
_, err = dst.ReadFrom(lr)
ioutil.PutLimitedReader(lr)
if err != nil {
@@ -176,7 +176,7 @@ func (c *client) ReadData(dst *chunkedbuffer.Buffer) (bool, error) {
}
return false, fmt.Errorf("cannot read data from %s: %w", c.scrapeURL, err)
}
if int64(dst.Len()) >= c.maxScrapeSize {
if int64(dst.Len()) > c.maxScrapeSize {
maxScrapeSizeExceeded.Inc()
return false, fmt.Errorf("the response from %q exceeds -promscrape.maxScrapeSize or max_scrape_size in the scrape config (%d bytes). "+
"Possible solutions are: reduce the response size for the target, increase -promscrape.maxScrapeSize command-line flag, "+