mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-21 03:16:00 -08:00
scrape: reorder the switch case of errors (#15991)
Change case order for switch scrapeLoop This commit changes the ordering in error identification switch cases for better production performance and adds reasonings behind error switch case order as comments. --------- Signed-off-by: Laimis Juzeliūnas <asnelaimis@gmail.com>
This commit is contained in:
parent
e936e419b0
commit
a5ffa83be8
|
@ -1962,12 +1962,24 @@ func isSeriesPartOfFamily(mName string, mfName []byte, typ model.MetricType) boo
|
||||||
|
|
||||||
// Adds samples to the appender, checking the error, and then returns the # of samples added,
|
// Adds samples to the appender, checking the error, and then returns the # of samples added,
|
||||||
// whether the caller should continue to process more samples, and any sample or bucket limit errors.
|
// whether the caller should continue to process more samples, and any sample or bucket limit errors.
|
||||||
|
// Switch error cases for Sample and Bucket limits are checked first since they're more common
|
||||||
|
// during normal operation (e.g., accidental cardinality explosion, sudden traffic spikes).
|
||||||
|
// Current case ordering prevents exercising other cases when limits are exceeded.
|
||||||
|
// Remaining error cases typically occur only a few times, often during initial setup.
|
||||||
func (sl *scrapeLoop) checkAddError(met []byte, err error, sampleLimitErr, bucketLimitErr *error, appErrs *appendErrors) (bool, error) {
|
func (sl *scrapeLoop) checkAddError(met []byte, err error, sampleLimitErr, bucketLimitErr *error, appErrs *appendErrors) (bool, error) {
|
||||||
switch {
|
switch {
|
||||||
case err == nil:
|
case err == nil:
|
||||||
return true, nil
|
return true, nil
|
||||||
case errors.Is(err, storage.ErrNotFound):
|
case errors.Is(err, errSampleLimit):
|
||||||
return false, storage.ErrNotFound
|
// Keep on parsing output if we hit the limit, so we report the correct
|
||||||
|
// total number of samples scraped.
|
||||||
|
*sampleLimitErr = err
|
||||||
|
return false, nil
|
||||||
|
case errors.Is(err, errBucketLimit):
|
||||||
|
// Keep on parsing output if we hit the limit, so we report the bucket
|
||||||
|
// total number of samples scraped.
|
||||||
|
*bucketLimitErr = err
|
||||||
|
return false, nil
|
||||||
case errors.Is(err, storage.ErrOutOfOrderSample):
|
case errors.Is(err, storage.ErrOutOfOrderSample):
|
||||||
appErrs.numOutOfOrder++
|
appErrs.numOutOfOrder++
|
||||||
sl.l.Debug("Out of order sample", "series", string(met))
|
sl.l.Debug("Out of order sample", "series", string(met))
|
||||||
|
@ -1983,16 +1995,8 @@ func (sl *scrapeLoop) checkAddError(met []byte, err error, sampleLimitErr, bucke
|
||||||
sl.l.Debug("Out of bounds metric", "series", string(met))
|
sl.l.Debug("Out of bounds metric", "series", string(met))
|
||||||
sl.metrics.targetScrapeSampleOutOfBounds.Inc()
|
sl.metrics.targetScrapeSampleOutOfBounds.Inc()
|
||||||
return false, nil
|
return false, nil
|
||||||
case errors.Is(err, errSampleLimit):
|
case errors.Is(err, storage.ErrNotFound):
|
||||||
// Keep on parsing output if we hit the limit, so we report the correct
|
return false, storage.ErrNotFound
|
||||||
// total number of samples scraped.
|
|
||||||
*sampleLimitErr = err
|
|
||||||
return false, nil
|
|
||||||
case errors.Is(err, errBucketLimit):
|
|
||||||
// Keep on parsing output if we hit the limit, so we report the correct
|
|
||||||
// total number of samples scraped.
|
|
||||||
*bucketLimitErr = err
|
|
||||||
return false, nil
|
|
||||||
default:
|
default:
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue