diff --git a/pkg/value/value.go b/pkg/value/value.go index df847db6d..d0b4942af 100644 --- a/pkg/value/value.go +++ b/pkg/value/value.go @@ -13,7 +13,15 @@ package value -var ( +import ( + "math" +) + +const ( NormalNaN uint64 = 0x7ff8000000000001 // A quiet NaN. This is also math.NaN(). StaleNaN uint64 = 0x7ff4000000000000 // A signalling NaN, starting 01 to allow for expansion. ) + +func IsStaleNaN(v float64) bool { + return math.Float64bits(v) == StaleNaN +} diff --git a/promql/engine.go b/promql/engine.go index 9ea3ab3f0..5fbc2dd1d 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -757,7 +757,7 @@ func (ev *evaluator) vectorSelector(node *VectorSelector) Vector { continue } } - if math.Float64bits(v) == value.StaleNaN { + if value.IsStaleNaN(v) { continue } vec = append(vec, Sample{ @@ -830,7 +830,7 @@ func (ev *evaluator) matrixSelector(node *MatrixSelector) Matrix { buf := it.Buffer() for buf.Next() { t, v := buf.At() - if math.Float64bits(v) == value.StaleNaN { + if value.IsStaleNaN(v) { continue } // Values in the buffer are guaranteed to be smaller than maxt. @@ -840,7 +840,7 @@ func (ev *evaluator) matrixSelector(node *MatrixSelector) Matrix { } // The seeked sample might also be in the range. t, v = it.Values() - if t == maxt && math.Float64bits(v) != value.StaleNaN { + if t == maxt && !value.IsStaleNaN(v) { allPoints = append(allPoints, Point{T: t, V: v}) } diff --git a/retrieval/scrape.go b/retrieval/scrape.go index 4cdcf5a28..ad89b6a85 100644 --- a/retrieval/scrape.go +++ b/retrieval/scrape.go @@ -423,6 +423,7 @@ type scrapeLoop struct { appender func() storage.Appender reportAppender func() storage.Appender + // TODO: Keep only the values from the last scrape to avoid a memory leak. refCache map[string]uint64 // Parsed string to ref. lsetCache map[uint64]lsetCacheEntry // Ref to labelset and string samplesInPreviousScrape map[string]labels.Labels