mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-11 13:57:36 -08:00
promql: fix parsing ambiguity for serial repetitions
This commit is contained in:
parent
f344ecba59
commit
319068a7a6
|
@ -666,7 +666,8 @@ func lexNumberOrDuration(l *lexer) stateFn {
|
||||||
// not necessarily a valid number. This case is caught by the parser.
|
// not necessarily a valid number. This case is caught by the parser.
|
||||||
func (l *lexer) scanNumber() bool {
|
func (l *lexer) scanNumber() bool {
|
||||||
digits := "0123456789"
|
digits := "0123456789"
|
||||||
if l.accept("0") && l.accept("xX") {
|
// Disallow hexal in series descriptions as the syntax is ambiguous.
|
||||||
|
if !l.seriesDesc && l.accept("0") && l.accept("xX") {
|
||||||
digits = "0123456789abcdefABCDEF"
|
digits = "0123456789abcdefABCDEF"
|
||||||
}
|
}
|
||||||
l.acceptRun(digits)
|
l.acceptRun(digits)
|
||||||
|
@ -677,11 +678,12 @@ func (l *lexer) scanNumber() bool {
|
||||||
l.accept("+-")
|
l.accept("+-")
|
||||||
l.acceptRun("0123456789")
|
l.acceptRun("0123456789")
|
||||||
}
|
}
|
||||||
// Next thing must not be alphanumeric.
|
// Next thing must not be alphanumeric unless it's the times token
|
||||||
if isAlphaNumeric(l.peek()) && !l.seriesDesc {
|
// for series repetitions.
|
||||||
return false
|
if r := l.peek(); (l.seriesDesc && r == 'x') || !isAlphaNumeric(r) {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
return true
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// lexIdentifier scans an alphanumeric identifier. The next character
|
// lexIdentifier scans an alphanumeric identifier. The next character
|
||||||
|
|
|
@ -1274,6 +1274,13 @@ var testSeries = []struct {
|
||||||
"a": "b",
|
"a": "b",
|
||||||
},
|
},
|
||||||
expectedValues: newSeq(1, 2, 3, -7, -17, -27, -37),
|
expectedValues: newSeq(1, 2, 3, -7, -17, -27, -37),
|
||||||
|
}, {
|
||||||
|
input: `my_metric{a="b"} 1 2 3-0x4`,
|
||||||
|
expectedMetric: clientmodel.Metric{
|
||||||
|
clientmodel.MetricNameLabel: "my_metric",
|
||||||
|
"a": "b",
|
||||||
|
},
|
||||||
|
expectedValues: newSeq(1, 2, 3, 3, 3, 3, 3),
|
||||||
}, {
|
}, {
|
||||||
input: `my_metric{a="b"} 1 3 _ 5 _x4`,
|
input: `my_metric{a="b"} 1 3 _ 5 _x4`,
|
||||||
expectedMetric: clientmodel.Metric{
|
expectedMetric: clientmodel.Metric{
|
||||||
|
|
Loading…
Reference in a new issue