Skip to content

Commit

Permalink
Fix TraceQL results caching bug for floats ending in .0
Browse files Browse the repository at this point in the history
  • Loading branch information
carles-grafana committed Jan 16, 2025
1 parent 7cda43b commit 4bf18b9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
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
8 changes: 5 additions & 3 deletions pkg/traceql/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ 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"},
{arg: 0, want: "0"},
{arg: 1.234e+1, want: "12.34"},
{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{
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

0 comments on commit 4bf18b9

Please sign in to comment.