mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-24 21:24:05 -08:00
fixes space issue in duration range promql (#6295)
* fix space issue in duration range promql Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com> * updated logic Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com> * fixed lexer to skip over the spaces Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com> * added unittests for updated lexer Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com> * added unittests for updated lexer Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>
This commit is contained in:
parent
2d8b6c7792
commit
37d666949c
|
@ -550,6 +550,9 @@ func lexStatements(l *lexer) stateFn {
|
|||
}
|
||||
l.gotColon = false
|
||||
l.emit(ItemLeftBracket)
|
||||
if isSpace(l.peek()) {
|
||||
skipSpaces(l)
|
||||
}
|
||||
l.bracketOpen = true
|
||||
return lexDuration
|
||||
case r == ']':
|
||||
|
@ -715,6 +718,14 @@ func digitVal(ch rune) int {
|
|||
return 16 // Larger than any legal digit val.
|
||||
}
|
||||
|
||||
// skipSpaces skips the spaces until a non-space is encountered.
|
||||
func skipSpaces(l *lexer) {
|
||||
for isSpace(l.peek()) {
|
||||
l.next()
|
||||
}
|
||||
l.ignore()
|
||||
}
|
||||
|
||||
// lexString scans a quoted string. The initial quote has already been seen.
|
||||
func lexString(l *lexer) stateFn {
|
||||
Loop:
|
||||
|
|
|
@ -49,6 +49,27 @@ var tests = []struct {
|
|||
{ItemDuration, 1, `5m`},
|
||||
{ItemRightBracket, 3, `]`},
|
||||
},
|
||||
}, {
|
||||
input: "[ 5m]",
|
||||
expected: []item{
|
||||
{ItemLeftBracket, 0, `[`},
|
||||
{ItemDuration, 2, `5m`},
|
||||
{ItemRightBracket, 4, `]`},
|
||||
},
|
||||
}, {
|
||||
input: "[ 5m]",
|
||||
expected: []item{
|
||||
{ItemLeftBracket, 0, `[`},
|
||||
{ItemDuration, 3, `5m`},
|
||||
{ItemRightBracket, 5, `]`},
|
||||
},
|
||||
}, {
|
||||
input: "[ 5m ]",
|
||||
expected: []item{
|
||||
{ItemLeftBracket, 0, `[`},
|
||||
{ItemDuration, 3, `5m`},
|
||||
{ItemRightBracket, 6, `]`},
|
||||
},
|
||||
}, {
|
||||
input: "\r\n\r",
|
||||
expected: []item{},
|
||||
|
@ -633,6 +654,15 @@ var tests = []struct {
|
|||
{ItemRightBracket, 60, `]`},
|
||||
},
|
||||
},
|
||||
{
|
||||
input: `test:name[ 5m]`,
|
||||
expected: []item{
|
||||
{ItemMetricIdentifier, 0, `test:name`},
|
||||
{ItemLeftBracket, 9, `[`},
|
||||
{ItemDuration, 11, `5m`},
|
||||
{ItemRightBracket, 13, `]`},
|
||||
},
|
||||
},
|
||||
{
|
||||
input: `test:name{o:n!~"bar"}[4m:4s]`,
|
||||
fail: true,
|
||||
|
|
Loading…
Reference in a new issue