Make sure we never call trackStaleness with nil cache entry

Signed-off-by: Lukasz Mierzwa <l.mierzwa@gmail.com>
This commit is contained in:
Lukasz Mierzwa 2025-04-29 09:24:27 +01:00
parent 6687bf5653
commit bb690a23b9

View File

@ -1820,8 +1820,9 @@ loop:
// it in the scrape cache because we don't need to emit StaleNaNs for it when it disappears. // it in the scrape cache because we don't need to emit StaleNaNs for it when it disappears.
if !seriesCached && sampleAdded { if !seriesCached && sampleAdded {
ce = sl.cache.addRef(met, ref, lset, hash) ce = sl.cache.addRef(met, ref, lset, hash)
if parsedTimestamp == nil || sl.trackTimestampsStaleness { if ce != nil && (parsedTimestamp == nil || sl.trackTimestampsStaleness) {
// Bypass staleness logic if there is an explicit timestamp. // Bypass staleness logic if there is an explicit timestamp.
// But make sure we only do this if we have a cache entry (ce) for our series.
sl.cache.trackStaleness(hash, ce) sl.cache.trackStaleness(hash, ce)
} }
if sampleAdded && sampleLimitErr == nil && bucketLimitErr == nil { if sampleAdded && sampleLimitErr == nil && bucketLimitErr == nil {