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

Fix TraceQL results caching bug for floats ending in .0 #4539

Merged
merged 1 commit into from
Jan 16, 2025
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* [BUGFIX] Choose a default step for a gRPC streaming query range request if none is provided. [#4546](https://github.com/grafana/tempo/pull/4546) (@joe-elliott)
Fix an issue where the tempo-cli was not correctly dumping exemplar results.
* [BUGFIX] Fix performance bottleneck and file cleanup in block builder [#4550](https://github.com/grafana/tempo/pull/4550) (@mdisibio)
* [BUGFIX] TraceQL results caching bug for floats ending in .0 [#4539](https://github.com/grafana/tempo/pull/4539) (@carles-grafana)


# v2.7.0

Expand Down
7 changes: 6 additions & 1 deletion pkg/traceql/ast_stringer.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ func (s Static) EncodeToString(quotes bool) string {
i, _ := s.Int()
return strconv.Itoa(i)
case TypeFloat:
return strconv.FormatFloat(s.Float(), 'g', -1, 64)
f := strconv.FormatFloat(s.Float(), 'g', -1, 64)
// if the float string doesn't contain e or ., then append .0 to distinguish it from an int
if !strings.ContainsAny(f, "e.") {
f = f + ".0"
}
return f
case TypeString:
var str string
if len(s.valBytes) > 0 {
Expand Down
9 changes: 6 additions & 3 deletions pkg/traceql/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,12 @@ func TestStatic_String(t *testing.T) {
{arg: nil, want: "nil"},
{arg: 101, want: "101"},
{arg: -10, want: "-10"},
{arg: -1.0, want: "-1"},
{arg: 0.0, want: "0"},
{arg: 10.0, want: "10"},
{arg: -1.0, want: "-1.0"},
{arg: 0.0, want: "0.0"},
{arg: 10.0, want: "10.0"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a few more cases: not ending in .0, and something with the e scientific notation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry my comment wasn't clear. The cases I meant were a value like 12.34 to test the ., and something huge that outputs the e to test that case. 12.34 is halfway covered by the second case, but let's get clear cases where input == output. The 0 case isn't needed cause that's testing the int path which is already covered.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the 2 test cases and another one I think wasn't covered

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

12.34e+2 Nice catch 👍

{arg: 12.34, want: "12.34"},
{arg: 1.23e+23, want: "1.23e+23"},
{arg: 12.34e+2, want: "1234.0"},
{arg: "test", want: "`test`"},
{arg: true, want: "true"},
{arg: StatusOk, want: "ok"},
Expand Down
8 changes: 4 additions & 4 deletions pkg/traceql/engine_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func TestQuantileOverTime(t *testing.T) {
// Output series with quantiles per foo
// Prom labels are sorted alphabetically, traceql labels maintain original order.
out := SeriesSet{
`{p="0", span.foo="bar"}`: TimeSeries{
`{p="0.0", span.foo="bar"}`: TimeSeries{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this is wanted @mdisibio

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah interesting side effect. It's ok. The actual label value is the same NewStaticFloat(0)

Labels: []Label{
{Name: "span.foo", Value: NewStaticString("bar")},
{Name: "p", Value: NewStaticFloat(0)},
Expand All @@ -374,14 +374,14 @@ func TestQuantileOverTime(t *testing.T) {
0,
},
},
`{p="1", span.foo="bar"}`: TimeSeries{
`{p="1.0", span.foo="bar"}`: TimeSeries{
Labels: []Label{
{Name: "span.foo", Value: NewStaticString("bar")},
{Name: "p", Value: NewStaticFloat(1)},
},
Values: []float64{_512ns, _256ns, 0},
},
`{p="0", span.foo="baz"}`: TimeSeries{
`{p="0.0", span.foo="baz"}`: TimeSeries{
Labels: []Label{
{Name: "span.foo", Value: NewStaticString("baz")},
{Name: "p", Value: NewStaticFloat(0)},
Expand All @@ -401,7 +401,7 @@ func TestQuantileOverTime(t *testing.T) {
percentileHelper(0.5, _512ns, _512ns, _512ns),
},
},
`{p="1", span.foo="baz"}`: TimeSeries{
`{p="1.0", span.foo="baz"}`: TimeSeries{
Labels: []Label{
{Name: "span.foo", Value: NewStaticString("baz")},
{Name: "p", Value: NewStaticFloat(1)},
Expand Down
3 changes: 2 additions & 1 deletion pkg/traceql/test_examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ valid:
- '{ event.foo = "bar" }'
- '{ link.foo = "bar" }'
- '{ instrumentation.foo = "bar" }'
- '{ span.foo != 3.0 }'
# scoped intrinsics
- '{ trace:duration > 2s }'
- '{ trace:rootName = "a" }'
Expand Down Expand Up @@ -151,7 +152,7 @@ valid:
# undocumented - nested set
- '{ nestedSetLeft > 3 }'
- '{ } >> { kind = server } | select(nestedSetLeft, nestedSetRight, nestedSetParent)'

# parse_fails throw an error when parsing
parse_fails:
- 'true'
Expand Down