Skip to content

Commit

Permalink
includes Inf and NaN as numbers to histogram
Browse files Browse the repository at this point in the history
Signed-off-by: Neeraj Gartia <[email protected]>
  • Loading branch information
NeerajGartia21 committed Apr 10, 2024
1 parent 594b317 commit 9ac432a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
14 changes: 10 additions & 4 deletions promql/parser/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ func lexHistogram(l *Lexer) stateFn {
return lexHistogram
case r == '-':
l.emit(SUB)
return lexNumber
return lexHistogram
case r == 'x':
l.emit(TIMES)
return lexNumber
Expand Down Expand Up @@ -568,10 +568,16 @@ Loop:
return lexHistogram
}
l.errorf("missing `:` for histogram descriptor")
} else {
l.errorf("bad histogram descriptor found: %q", word)
break Loop
}

// current word is Inf or NaN
if desc, ok := key[strings.ToLower(word)]; ok {
if desc == NUMBER {
l.emit(desc)
return lexHistogram
}
}
l.errorf("bad histogram descriptor found: %q", word)
break Loop
}
}
Expand Down
29 changes: 29 additions & 0 deletions promql/parser/lex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,35 @@ var tests = []struct {
},
seriesDesc: true,
},
{ // series with sum as -Inf and count as NaN
input: `{} {{buckets: [5 10 7] sum:Inf count:NaN}}`,
expected: []Item{
{LEFT_BRACE, 0, `{`},
{RIGHT_BRACE, 1, `}`},
{SPACE, 2, ` `},
{OPEN_HIST, 3, `{{`},
{BUCKETS_DESC, 5, `buckets`},
{COLON, 12, `:`},
{SPACE, 13, ` `},
{LEFT_BRACKET, 14, `[`},
{NUMBER, 15, `5`},
{SPACE, 16, ` `},
{NUMBER, 17, `10`},
{SPACE, 19, ` `},
{NUMBER, 20, `7`},
{RIGHT_BRACKET, 21, `]`},
{SPACE, 22, ` `},
{SUM_DESC, 23, `sum`},
{COLON, 26, `:`},
{NUMBER, 27, `Inf`},
{SPACE, 30, ` `},
{COUNT_DESC, 31, `count`},
{COLON, 36, `:`},
{NUMBER, 37, `NaN`},
{CLOSE_HIST, 40, `}}`},
},
seriesDesc: true,
},
},
},
{
Expand Down

0 comments on commit 9ac432a

Please sign in to comment.