mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-12 22:37:27 -08:00
Also support parsing float formats like "2.".
This commit is contained in:
parent
c2ab54e9a6
commit
0ac931aed1
|
@ -55,7 +55,7 @@ L [a-zA-Z_]
|
||||||
M [a-zA-Z_:]
|
M [a-zA-Z_:]
|
||||||
U [smhdwy]
|
U [smhdwy]
|
||||||
|
|
||||||
FLOAT [-+]?{D}*\.?{D}+{EXPONENT}?|[+-]?[iI][nN][fF]|[nN][aA][nN]
|
FLOAT [-+]?({D}*\.?{D}+|{D}+\.?{D}*){EXPONENT}?|[+-]?[iI][nN][fF]|[nN][aA][nN]
|
||||||
EXPONENT [eE][-+]?[0-9]+
|
EXPONENT [eE][-+]?[0-9]+
|
||||||
|
|
||||||
STR \"(\\.|[^\\"])*\"|\'(\\.|[^\\'])*\'
|
STR \"(\\.|[^\\"])*\"|\'(\\.|[^\\'])*\'
|
||||||
|
|
|
@ -288,7 +288,7 @@ yystate18:
|
||||||
default:
|
default:
|
||||||
goto yyrule21
|
goto yyrule21
|
||||||
case c == '.':
|
case c == '.':
|
||||||
goto yystate13
|
goto yystate14
|
||||||
case c == 'E' || c == 'e':
|
case c == 'E' || c == 'e':
|
||||||
goto yystate15
|
goto yystate15
|
||||||
case c >= '0' && c <= '9':
|
case c >= '0' && c <= '9':
|
||||||
|
@ -353,7 +353,7 @@ yystate26:
|
||||||
default:
|
default:
|
||||||
goto yyrule21
|
goto yyrule21
|
||||||
case c == '.':
|
case c == '.':
|
||||||
goto yystate13
|
goto yystate14
|
||||||
case c == 'E' || c == 'e':
|
case c == 'E' || c == 'e':
|
||||||
goto yystate15
|
goto yystate15
|
||||||
case c == 'd' || c == 'h' || c == 'm' || c == 's' || c == 'w' || c == 'y':
|
case c == 'd' || c == 'h' || c == 'm' || c == 's' || c == 'w' || c == 'y':
|
||||||
|
|
|
@ -36,7 +36,7 @@ var (
|
||||||
testEvalTime = testStartTime.Add(testSampleInterval * 10)
|
testEvalTime = testStartTime.Add(testSampleInterval * 10)
|
||||||
fixturesPath = "fixtures"
|
fixturesPath = "fixtures"
|
||||||
|
|
||||||
reSample = regexp.MustCompile(`^(.*)( \=\>|:) (\-?\d+\.?\d*e?\d*|[+-]Inf|NaN) \@\[(\d+)\]$`)
|
reSample = regexp.MustCompile(`^(.*)(?: \=\>|:) (\-?\d+\.?\d*e?\d*|[+-]Inf|NaN) \@\[(\d+)\]$`)
|
||||||
minNormal = math.Float64frombits(0x0010000000000000) // The smallest positive normal value of type float64.
|
minNormal = math.Float64frombits(0x0010000000000000) // The smallest positive normal value of type float64.
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -81,16 +81,16 @@ func samplesAlmostEqual(a, b string) bool {
|
||||||
if aMatches[1] != bMatches[1] {
|
if aMatches[1] != bMatches[1] {
|
||||||
return false // Labels don't match.
|
return false // Labels don't match.
|
||||||
}
|
}
|
||||||
if aMatches[4] != bMatches[4] {
|
if aMatches[3] != bMatches[3] {
|
||||||
return false // Timestamps don't match.
|
return false // Timestamps don't match.
|
||||||
}
|
}
|
||||||
// If we are here, we have the diff in the floats.
|
// If we are here, we have the diff in the floats.
|
||||||
// We have to check if they are almost equal.
|
// We have to check if they are almost equal.
|
||||||
aVal, err := strconv.ParseFloat(aMatches[3], 64)
|
aVal, err := strconv.ParseFloat(aMatches[2], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
bVal, err := strconv.ParseFloat(bMatches[3], 64)
|
bVal, err := strconv.ParseFloat(bMatches[2], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -947,8 +947,8 @@ func TestExpressions(t *testing.T) {
|
||||||
output: []string{`scalar: NaN @[%v]`},
|
output: []string{`scalar: NaN @[%v]`},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
expr: `2.`,
|
expr: `2.`,
|
||||||
shouldFail: true,
|
output: []string{`scalar: 2 @[%v]`},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
expr: `999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999`,
|
expr: `999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999`,
|
||||||
|
|
Loading…
Reference in a new issue