Skip to content
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
@@ -1,6 +1,7 @@
## main / unreleased

* [CHANGE] Set default `max_result_limit` for search to 256*1024 [#6525](https://github.com/grafana/tempo/pull/6525) (@zhxiaogg)
* [BUGFIX] avoided unbounded mem by capping exemplars hint [#6792](https://github.com/grafana/tempo/pull/6792) (@zhxiaogg)

# v2.8.3

Expand Down
4 changes: 3 additions & 1 deletion pkg/traceql/engine_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const (
internalLabelBucket = "__bucket"
maxExemplars = 100
maxExemplarsPerBucket = 2
// This is a safety cap applied on the exemplars hint from traceql
maxExemplarsHint = 100000
// NormalNaN is a quiet NaN. This is also math.NaN().
normalNaN uint64 = 0x7ff8000000000001
)
Expand Down Expand Up @@ -895,7 +897,7 @@ func (e *Engine) CompileMetricsQueryRange(req *tempopb.QueryRangeRequest, exempl
}

if v, ok := expr.Hints.GetInt(HintExemplars, allowUnsafeQueryHints); ok {
exemplars = v
exemplars = min(v, maxExemplarsHint)
}

// This initializes all step buffers, counters, etc
Expand Down
45 changes: 45 additions & 0 deletions pkg/traceql/engine_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,51 @@ func TestCompileMetricsQueryRange(t *testing.T) {
}
}

func TestCompileMetricsQueryRangeExemplarsHint(t *testing.T) {
tc := []struct {
name string
q string
defaultExemplars int
allowUnsafe bool
expectedExemplars int
}{
{
name: "hint below maxExemplarsHint uses maxExemplarsHint as floor",
q: `{} | rate() with(exemplars=5000)`,
defaultExemplars: 0,
allowUnsafe: true,
expectedExemplars: 5000,
},
{
name: "hint above maxExemplarsHint uses hint value",
q: `{} | rate() with(exemplars=500000)`,
defaultExemplars: 0,
allowUnsafe: true,
expectedExemplars: maxExemplarsHint,
},
{
name: "no exemplars hint uses default",
q: `{} | rate()`,
defaultExemplars: 42,
allowUnsafe: false,
expectedExemplars: 42,
},
}

for _, c := range tc {
t.Run(c.name, func(t *testing.T) {
eval, err := NewEngine().CompileMetricsQueryRange(&tempopb.QueryRangeRequest{
Query: c.q,
Start: 1,
End: 2,
Step: 3,
}, c.defaultExemplars, 0, c.allowUnsafe)
require.NoError(t, err)
require.Equal(t, c.expectedExemplars, eval.maxExemplars)
})
}
}

func TestCompileMetricsQueryRangeFetchSpansRequest(t *testing.T) {
tc := map[string]struct {
q string
Expand Down
Loading