@@ -12,9 +12,11 @@ import (
1212 "sync"
1313 "time"
1414
15+ "github.com/go-kit/log/level"
1516 "github.com/grafana/tempo/pkg/tempopb"
1617 commonv1proto "github.com/grafana/tempo/pkg/tempopb/common/v1"
1718 "github.com/grafana/tempo/pkg/util"
19+ "github.com/grafana/tempo/pkg/util/log"
1820 "github.com/prometheus/prometheus/model/labels"
1921)
2022
@@ -23,6 +25,9 @@ const (
2325 internalMetaTypeCount = "__count"
2426 internalLabelBucket = "__bucket"
2527 maxExemplarsPerBucket = 2
28+ // maxExemplars is a safety cap applied at the engine entry points to bound memory
29+ // usage regardless of what the caller requests.
30+ maxExemplars uint32 = 100000
2631 // NormalNaN is a quiet NaN. This is also math.NaN().
2732 normalNaN uint64 = 0x7ff8000000000001
2833)
@@ -930,6 +935,11 @@ func (u *UngroupedAggregator) Series() SeriesSet {
930935}
931936
932937func (e * Engine ) CompileMetricsQueryRangeNonRaw (req * tempopb.QueryRangeRequest , mode AggregateMode ) (* MetricsFrontendEvaluator , error ) {
938+ if req .Exemplars > maxExemplars {
939+ level .Warn (log .Logger ).Log ("msg" , "capping exemplars to safety limit" , "requested" , req .Exemplars , "cap" , maxExemplars )
940+ req .Exemplars = maxExemplars
941+ }
942+
933943 if req .Start <= 0 {
934944 return nil , fmt .Errorf ("start required" )
935945 }
@@ -973,6 +983,11 @@ func (e *Engine) CompileMetricsQueryRangeNonRaw(req *tempopb.QueryRangeRequest,
973983// example if the datasource is replication factor=1 or only a single block then we know there
974984// aren't duplicates, and we can make some optimizations.
975985func (e * Engine ) CompileMetricsQueryRange (req * tempopb.QueryRangeRequest , timeOverlapCutoff float64 , allowUnsafeQueryHints bool ) (* MetricsEvaluator , error ) {
986+ if req .Exemplars > maxExemplars {
987+ level .Warn (log .Logger ).Log ("msg" , "capping exemplars to safety limit" , "requested" , req .Exemplars , "cap" , maxExemplars )
988+ req .Exemplars = maxExemplars
989+ }
990+
976991 if req .Start <= 0 {
977992 return nil , fmt .Errorf ("start required" )
978993 }
0 commit comments