MCPcopy
hub / github.com/grafana/tempo / TestSimpleAggregatorExemplarLimit

Function TestSimpleAggregatorExemplarLimit

pkg/traceql/engine_metrics_test.go:2849–2897  ·  view source on GitHub ↗

TestSimpleAggregatorExemplarLimit verifies that SimpleAggregator (used in AggregateModeSum) respects req.Exemplars, including values above the old hardcoded limit of 100.

(t *testing.T)

Source from the content-addressed store, hash-verified

2847// TestSimpleAggregatorExemplarLimit verifies that SimpleAggregator (used in AggregateModeSum)
2848// respects req.Exemplars, including values above the old hardcoded limit of 100.
2849func TestSimpleAggregatorExemplarLimit(t *testing.T) {
2850 tcs := []struct {
2851 name string
2852 exemplars uint32
2853 sendCount int
2854 minExpected int // at least this many exemplars must appear in the result
2855 }{
2856 {"below_old_limit", 50, 200, 1},
2857 {"at_old_limit", 100, 200, 1},
2858 // Proves the fix: before the change, this was capped at 100.
2859 {"above_old_limit", 150, 200, 101},
2860 {"large", 200, 300, 1},
2861 }
2862
2863 for _, tc := range tcs {
2864 t.Run(tc.name, func(t *testing.T) {
2865 req := &tempopb.QueryRangeRequest{
2866 Start: uint64(1 * time.Second),
2867 End: uint64(time.Duration(tc.sendCount+1) * time.Second),
2868 Step: uint64(time.Second),
2869 Exemplars: tc.exemplars,
2870 }
2871
2872 agg := NewSimpleCombiner(req, sumAggregation)
2873
2874 // Build exemplars spread evenly across the time range (ms timestamps).
2875 startMs := req.Start / uint64(time.Millisecond)
2876 endMs := req.End / uint64(time.Millisecond)
2877 exemplars := make([]tempopb.Exemplar, tc.sendCount)
2878 for i := range exemplars {
2879 ts := startMs + uint64(i)*(endMs-startMs)/uint64(tc.sendCount)
2880 exemplars[i] = tempopb.Exemplar{TimestampMs: int64(ts), Value: float64(i)} //nolint: gosec // G115
2881 }
2882
2883 agg.Combine([]*tempopb.TimeSeries{{
2884 Labels: []commonv1proto.KeyValue{{Key: "service", Value: &commonv1proto.AnyValue{Value: &commonv1proto.AnyValue_StringValue{StringValue: "test"}}}},
2885 Samples: []tempopb.Sample{{TimestampMs: int64(startMs), Value: 1.0}}, //nolint: gosec // G115
2886 Exemplars: exemplars,
2887 }})
2888
2889 total := 0
2890 for _, ts := range agg.Results() {
2891 total += len(ts.Exemplars)
2892 }
2893 require.LessOrEqual(t, total, int(tc.exemplars), "exemplar count must not exceed req.Exemplars")
2894 require.GreaterOrEqual(t, total, tc.minExpected, "exemplar count must meet minimum expected")
2895 })
2896 }
2897}
2898
2899func TestHistogramAggregator(t *testing.T) {
2900 req := &tempopb.QueryRangeRequest{

Callers

nothing calls this directly

Calls 5

NewSimpleCombinerFunction · 0.85
DurationMethod · 0.80
CombineMethod · 0.65
ResultsMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected