Skip to content

Commit ad887d7

Browse files
authored
TraceQL: fix queries like {.foo && true} and {.foo || false} (#4855)
* Add test cases for {.foo && true} and {.foo || false} * Fix behavior for queries like {.foo && true} and {.foo || false} * CHANGELOG.md
1 parent 0853943 commit ad887d7

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

‎CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ configurable via the throughput_bytes_slo field, and it will populate op="traces
5252
* [ENHANCEMENT] distributor: add IPv6 support [#4840](https://github.com/grafana/tempo/pull/4840) (@gjacquet)
5353
* [BUGFIX] Choose a default step for a gRPC streaming query range request if none is provided. [#4546](https://github.com/grafana/tempo/pull/4576) (@joe-elliott)
5454
Correctly copy exemplars for metrics like `| rate()` when gRPC streaming.
55+
* [BUGFIX] Fix behavior for queries like {.foo && true} and {.foo || false} [#4855](https://github.com/grafana/tempo/pull/4855) (@stoewer)
5556
* [BUGFIX] Fix performance bottleneck and file cleanup in block builder [#4550](https://github.com/grafana/tempo/pull/4550) (@mdisibio)
5657
* [BUGFIX] TraceQL incorrect results for additional spanset filters after a select operation [#4600](https://github.com/grafana/tempo/pull/4600) (@mdisibio)
5758
* [BUGFIX] TraceQL results caching bug for floats ending in .0 [#4539](https://github.com/grafana/tempo/pull/4539) (@carles-grafana)

‎pkg/traceql/ast_conditions.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ func (o *BinaryOperation) extractConditions(request *FetchSpansRequest) {
5454
Op: OpNone,
5555
Operands: nil,
5656
})
57+
} else if o.RHS.(Static).Type == TypeBoolean && (o.Op == OpOr || o.Op == OpAnd) {
58+
request.appendCondition(Condition{
59+
Attribute: o.LHS.(Attribute),
60+
Op: OpNone,
61+
Operands: nil,
62+
})
5763
} else {
5864
request.appendCondition(Condition{
5965
Attribute: o.LHS.(Attribute),
@@ -94,6 +100,12 @@ func (o *BinaryOperation) extractConditions(request *FetchSpansRequest) {
94100
Op: OpNone,
95101
Operands: nil,
96102
})
103+
} else if o.LHS.(Static).Type == TypeBoolean && (o.Op == OpOr || o.Op == OpAnd) {
104+
request.appendCondition(Condition{
105+
Attribute: o.RHS.(Attribute),
106+
Op: OpNone,
107+
Operands: nil,
108+
})
97109
} else {
98110
request.appendCondition(Condition{
99111
Attribute: o.RHS.(Attribute),

‎pkg/traceql/ast_conditions_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ func TestSpansetFilter_extractConditions(t *testing.T) {
105105
},
106106
allConditions: true,
107107
},
108+
{
109+
query: `{ .foo && true }`,
110+
conditions: []Condition{
111+
newCondition(NewAttribute("foo"), OpNone),
112+
},
113+
allConditions: true,
114+
},
115+
{
116+
query: `{ true || .foo }`,
117+
conditions: []Condition{
118+
newCondition(NewAttribute("foo"), OpNone),
119+
},
120+
allConditions: true,
121+
},
108122
}
109123
for _, tt := range tests {
110124
t.Run(tt.query, func(t *testing.T) {

‎tempodb/encoding/vparquet4/block_traceql_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ func TestBackendBlockSearchTraceQL(t *testing.T) {
214214
{"service.name present on span", traceql.MustExtractFetchSpansRequestWithMetadata(`{.` + LabelServiceName + ` = "spanservicename"}`)},
215215
{"http.status_code doesn't match type of dedicated column", traceql.MustExtractFetchSpansRequestWithMetadata(`{.` + LabelHTTPStatusCode + ` = "500ouch"}`)},
216216
{`.foo = "def"`, traceql.MustExtractFetchSpansRequestWithMetadata(`{.foo = "def"}`)},
217+
{".bool && true", traceql.MustExtractFetchSpansRequestWithMetadata(`{.bool && true}`)},
218+
{"false || .bool", traceql.MustExtractFetchSpansRequestWithMetadata(`{false || .bool}`)},
217219
{
218220
name: "Range at unscoped",
219221
req: traceql.FetchSpansRequest{

0 commit comments

Comments
 (0)