Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support float as duration in traceql #2304

Merged
merged 4 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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