Skip to content

Commit

Permalink
fixes space issue in duration range promql (prometheus#6295)
Browse files Browse the repository at this point in the history
* fix space issue in duration range promql

Signed-off-by: Harkishen-Singh <[email protected]>

* updated logic

Signed-off-by: Harkishen-Singh <[email protected]>

* fixed lexer to skip over the spaces

Signed-off-by: Harkishen-Singh <[email protected]>

* added unittests for updated lexer

Signed-off-by: Harkishen-Singh <[email protected]>

* added unittests for updated lexer

Signed-off-by: Harkishen-Singh <[email protected]>
  • Loading branch information
Harkishen-Singh authored and juliusv committed Nov 11, 2019
1 parent 2d8b6c7 commit 37d6669
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
11 changes: 11 additions & 0 deletions promql/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == ']':
Expand Down Expand Up @@ -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:
Expand Down
30 changes: 30 additions & 0 deletions promql/lex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 37d6669

Please sign in to comment.