mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Move consistent NaN logic into the parser.
This commit is contained in:
parent
76acf7b9b1
commit
beaa7d5a43
|
@ -18,6 +18,8 @@ import (
|
|||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
|
||||
"github.com/prometheus/prometheus/pkg/value"
|
||||
)
|
||||
|
||||
|
||||
|
@ -85,8 +87,9 @@ M [a-zA-Z_:]
|
|||
l.offsets = append(l.offsets, l.i-1)
|
||||
|
||||
<lstateValue>[ \t]+ l.vstart = l.i
|
||||
<lstateValue>(NaN) l.val = math.NaN()
|
||||
<lstateValue>(NaN) l.val = math.Float64frombits(value.NormalNaN)
|
||||
s = lstateTimestamp
|
||||
|
||||
<lstateValue>[^\n \t\r]+ // We don't parse strictly correct floats as the conversion
|
||||
// repeats the effort anyway.
|
||||
l.val, l.err = strconv.ParseFloat(yoloString(l.b[l.vstart:l.i]), 64)
|
||||
|
|
|
@ -19,6 +19,8 @@ import (
|
|||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
|
||||
"github.com/prometheus/prometheus/pkg/value"
|
||||
)
|
||||
|
||||
// Lex is called by the parser generated by "go tool yacc" to obtain each
|
||||
|
@ -426,7 +428,7 @@ yyrule12: // [ \t]+
|
|||
}
|
||||
yyrule13: // (NaN)
|
||||
{
|
||||
l.val = math.NaN()
|
||||
l.val = math.Float64frombits(value.NormalNaN)
|
||||
s = lstateTimestamp
|
||||
goto yystate0
|
||||
}
|
||||
|
|
|
@ -14,6 +14,6 @@
|
|||
package value
|
||||
|
||||
var (
|
||||
normalNaN uint64 = 0x7ff8000000000001 // A quiet NaN. This is also math.NaN().
|
||||
staleNaN uint64 = 0x7ff4000000000000 // A signalling NaN, starting 01 to allow for expansion.
|
||||
NormalNaN uint64 = 0x7ff8000000000001 // A quiet NaN. This is also math.NaN().
|
||||
StaleNaN uint64 = 0x7ff4000000000000 // A signalling NaN, starting 01 to allow for expansion.
|
||||
)
|
||||
|
|
|
@ -19,7 +19,6 @@ import (
|
|||
"compress/gzip"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -47,11 +46,6 @@ const (
|
|||
samplesPostRelabelMetricName = "scrape_samples_post_metric_relabeling"
|
||||
)
|
||||
|
||||
var (
|
||||
normalNaN uint64 = 0x7ff8000000000001 // A quiet NaN. This is also math.NaN().
|
||||
staleNaN uint64 = 0x7ff4000000000000 // A signalling NaN, starting 01 to allow for expansion.
|
||||
)
|
||||
|
||||
var (
|
||||
targetIntervalLength = prometheus.NewSummaryVec(
|
||||
prometheus.SummaryOpts{
|
||||
|
@ -542,10 +536,6 @@ loop:
|
|||
|
||||
t := defTime
|
||||
met, tp, v := p.At()
|
||||
// Normalise actual NaNs to one bit representation.
|
||||
if math.IsNaN(v) {
|
||||
v = math.Float64frombits(normalNaN)
|
||||
}
|
||||
if tp != nil {
|
||||
t = *tp
|
||||
}
|
||||
|
|
|
@ -18,10 +18,10 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"math"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
|
@ -35,6 +35,7 @@ import (
|
|||
"github.com/prometheus/prometheus/config"
|
||||
"github.com/prometheus/prometheus/pkg/labels"
|
||||
"github.com/prometheus/prometheus/pkg/timestamp"
|
||||
"github.com/prometheus/prometheus/pkg/value"
|
||||
"github.com/prometheus/prometheus/storage"
|
||||
)
|
||||
|
||||
|
@ -451,8 +452,8 @@ func TestScrapeLoopAppend(t *testing.T) {
|
|||
}
|
||||
|
||||
ingestedNaN := math.Float64bits(app.result[1].v)
|
||||
if ingestedNaN != normalNaN {
|
||||
t.Fatalf("Appended NaN samples wasn't as expected. Wanted: %x Got: %x", normalNaN, ingestedNaN)
|
||||
if ingestedNaN != value.NormalNaN {
|
||||
t.Fatalf("Appended NaN samples wasn't as expected. Wanted: %x Got: %x", value.NormalNaN, ingestedNaN)
|
||||
}
|
||||
|
||||
// DeepEqual will report NaNs as being different, so replace with a different value.
|
||||
|
|
Loading…
Reference in a new issue