Browse Source

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>
pull/6300/head
Harkishen Singh 5 years ago committed by Julius Volz
parent
commit
37d666949c
  1. 11
      promql/lex.go
  2. 30
      promql/lex_test.go

11
promql/lex.go

@ -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:

30
promql/lex_test.go

@ -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…
Cancel
Save