Skip to content

Commit 4444827

Browse files
Fix TraceQL results caching bug for floats ending in .0
1 parent 0112d87 commit 4444827

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

‎CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## main / unreleased
22

3+
* [BUGFIX] TraceQL results caching bug for floats ending in .0 [#4539](https://github.com/grafana/tempo/pull/4539) (@carles-grafana)
4+
35
# v2.7.0-rc.0
46

57
* [CHANGE] Disable gRPC compression in the querier and distributor for performance reasons [#4429](https://github.com/grafana/tempo/pull/4429) (@carles-grafana)

‎pkg/traceql/ast_stringer.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ func (s Static) EncodeToString(quotes bool) string {
8989
i, _ := s.Int()
9090
return strconv.Itoa(i)
9191
case TypeFloat:
92-
return strconv.FormatFloat(s.Float(), 'g', -1, 64)
92+
f := strconv.FormatFloat(s.Float(), 'g', -1, 64)
93+
// if the float string doesn't contain e or ., then append .0 to distinguish it from an int
94+
if !strings.ContainsAny(f, "e.") {
95+
f = f + ".0"
96+
}
97+
return f
9398
case TypeString:
9499
var str string
95100
if len(s.valBytes) > 0 {

‎pkg/traceql/ast_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ func TestStatic_String(t *testing.T) {
131131
{arg: nil, want: "nil"},
132132
{arg: 101, want: "101"},
133133
{arg: -10, want: "-10"},
134-
{arg: -1.0, want: "-1"},
135-
{arg: 0.0, want: "0"},
136-
{arg: 10.0, want: "10"},
134+
{arg: -1.0, want: "-1.0"},
135+
{arg: 0.0, want: "0.0"},
136+
{arg: 10.0, want: "10.0"},
137137
{arg: "test", want: "`test`"},
138138
{arg: true, want: "true"},
139139
{arg: StatusOk, want: "ok"},

‎pkg/traceql/engine_metrics_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ func TestQuantileOverTime(t *testing.T) {
352352
// Output series with quantiles per foo
353353
// Prom labels are sorted alphabetically, traceql labels maintain original order.
354354
out := SeriesSet{
355-
`{p="0", span.foo="bar"}`: TimeSeries{
355+
`{p="0.0", span.foo="bar"}`: TimeSeries{
356356
Labels: []Label{
357357
{Name: "span.foo", Value: NewStaticString("bar")},
358358
{Name: "p", Value: NewStaticFloat(0)},
@@ -374,14 +374,14 @@ func TestQuantileOverTime(t *testing.T) {
374374
0,
375375
},
376376
},
377-
`{p="1", span.foo="bar"}`: TimeSeries{
377+
`{p="1.0", span.foo="bar"}`: TimeSeries{
378378
Labels: []Label{
379379
{Name: "span.foo", Value: NewStaticString("bar")},
380380
{Name: "p", Value: NewStaticFloat(1)},
381381
},
382382
Values: []float64{_512ns, _256ns, 0},
383383
},
384-
`{p="0", span.foo="baz"}`: TimeSeries{
384+
`{p="0.0", span.foo="baz"}`: TimeSeries{
385385
Labels: []Label{
386386
{Name: "span.foo", Value: NewStaticString("baz")},
387387
{Name: "p", Value: NewStaticFloat(0)},
@@ -401,7 +401,7 @@ func TestQuantileOverTime(t *testing.T) {
401401
percentileHelper(0.5, _512ns, _512ns, _512ns),
402402
},
403403
},
404-
`{p="1", span.foo="baz"}`: TimeSeries{
404+
`{p="1.0", span.foo="baz"}`: TimeSeries{
405405
Labels: []Label{
406406
{Name: "span.foo", Value: NewStaticString("baz")},
407407
{Name: "p", Value: NewStaticFloat(1)},

‎pkg/traceql/test_examples.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ valid:
5454
- '{ event.foo = "bar" }'
5555
- '{ link.foo = "bar" }'
5656
- '{ instrumentation.foo = "bar" }'
57+
- '{ span.foo != 3.0 }'
5758
# scoped intrinsics
5859
- '{ trace:duration > 2s }'
5960
- '{ trace:rootName = "a" }'
@@ -151,7 +152,6 @@ valid:
151152
# undocumented - nested set
152153
- '{ nestedSetLeft > 3 }'
153154
- '{ } >> { kind = server } | select(nestedSetLeft, nestedSetRight, nestedSetParent)'
154-
155155
# parse_fails throw an error when parsing
156156
parse_fails:
157157
- 'true'

0 commit comments

Comments
 (0)