Skip to content

Commit

Permalink
Support float as duration in traceql (#2304)
Browse files Browse the repository at this point in the history
* fix float time duration

* fix float duration

* CHANGELOG.md

* fix test
  • Loading branch information
ie-pham authored Apr 6, 2023
1 parent 97daaac commit 0a3c35d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
This prevents invalid values from showing up for intrinsics like `status` [#2219](https://github.com/grafana/tempo/pull/2152) (@joe-elliott)
* [BUGFIX] Correctly return unique spans when &&ing and ||ing spansets. [#2254](https://github.com/grafana/tempo/pull/2254) (@joe-elliott)
* [BUGFIX] Support negative values on aggregate filters like `count() > -1`. [#2289](https://github.com/grafana/tempo/pull/2289) (@joe-elliott)
* [BUGFIX] Support float as duration like `{duration > 1.5s}` [#2304]https://github.com/grafana/tempo/pull/2304 (@ie-pham)

## v2.0.1 / 2023-03-03

Expand Down
11 changes: 10 additions & 1 deletion pkg/traceql/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,17 @@ func (l *lexer) Lex(lval *yySymType) int {
return INTEGER

case scanner.Float:
numberText := l.TokenText()

// first try to parse as duration
duration, ok := tryScanDuration(numberText, &l.Scanner)
if ok {
lval.staticDuration = duration
return DURATION
}

var err error
lval.staticFloat, err = strconv.ParseFloat(l.TokenText(), 64)
lval.staticFloat, err = strconv.ParseFloat(numberText, 64)
if err != nil {
l.Error(err.Error())
return 0
Expand Down
2 changes: 1 addition & 1 deletion pkg/traceql/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestLexerAttributes(t *testing.T) {
{`. foo`, []int{DOT, END_ATTRIBUTE, IDENTIFIER}},
// not attributes
{`.3`, []int{FLOAT}},
{`.24h`, []int{FLOAT, IDENTIFIER}},
{`.24h`, []int{DURATION}},
}))
}

Expand Down
1 change: 1 addition & 0 deletions pkg/traceql/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ func TestSpansetFilterStatics(t *testing.T) {
{in: "{ 1.234 }", expected: NewStaticFloat(1.234)},
{in: "{ nil }", expected: NewStaticNil()},
{in: "{ 3h }", expected: NewStaticDuration(3 * time.Hour)},
{in: "{ 1.5m }", expected: NewStaticDuration(1*time.Minute + 30*time.Second)},
{in: "{ error }", expected: NewStaticStatus(StatusError)},
{in: "{ ok }", expected: NewStaticStatus(StatusOk)},
{in: "{ unset }", expected: NewStaticStatus(StatusUnset)},
Expand Down

0 comments on commit 0a3c35d

Please sign in to comment.