@@ -1962,12 +1962,24 @@ func isSeriesPartOfFamily(mName string, mfName []byte, typ model.MetricType) boo
19621962
19631963// Adds samples to the appender, checking the error, and then returns the # of samples added,
19641964// whether the caller should continue to process more samples, and any sample or bucket limit errors.
1965+ // Switch error cases for Sample and Bucket limits are checked first since they're more common
1966+ // during normal operation (e.g., accidental cardinality explosion, sudden traffic spikes).
1967+ // Current case ordering prevents exercising other cases when limits are exceeded.
1968+ // Remaining error cases typically occur only a few times, often during initial setup.
19651969func (sl * scrapeLoop ) checkAddError (met []byte , err error , sampleLimitErr , bucketLimitErr * error , appErrs * appendErrors ) (bool , error ) {
19661970 switch {
19671971 case err == nil :
19681972 return true , nil
1969- case errors .Is (err , storage .ErrNotFound ):
1970- return false , storage .ErrNotFound
1973+ case errors .Is (err , errSampleLimit ):
1974+ // Keep on parsing output if we hit the limit, so we report the correct
1975+ // total number of samples scraped.
1976+ * sampleLimitErr = err
1977+ return false , nil
1978+ case errors .Is (err , errBucketLimit ):
1979+ // Keep on parsing output if we hit the limit, so we report the bucket
1980+ // total number of samples scraped.
1981+ * bucketLimitErr = err
1982+ return false , nil
19711983 case errors .Is (err , storage .ErrOutOfOrderSample ):
19721984 appErrs .numOutOfOrder ++
19731985 sl .l .Debug ("Out of order sample" , "series" , string (met ))
@@ -1983,16 +1995,8 @@ func (sl *scrapeLoop) checkAddError(met []byte, err error, sampleLimitErr, bucke
19831995 sl .l .Debug ("Out of bounds metric" , "series" , string (met ))
19841996 sl .metrics .targetScrapeSampleOutOfBounds .Inc ()
19851997 return false , nil
1986- case errors .Is (err , errSampleLimit ):
1987- // Keep on parsing output if we hit the limit, so we report the correct
1988- // total number of samples scraped.
1989- * sampleLimitErr = err
1990- return false , nil
1991- case errors .Is (err , errBucketLimit ):
1992- // Keep on parsing output if we hit the limit, so we report the correct
1993- // total number of samples scraped.
1994- * bucketLimitErr = err
1995- return false , nil
1998+ case errors .Is (err , storage .ErrNotFound ):
1999+ return false , storage .ErrNotFound
19962000 default :
19972001 return false , err
19982002 }
0 commit comments