TestAvgOverTimeExemplarLimit verifies that avgOverTimeSpanAggregator caps per-series exemplar collection at req.Exemplars (set via q.Exemplars).
(t *testing.T)
| 12 | // TestAvgOverTimeExemplarLimit verifies that avgOverTimeSpanAggregator caps |
| 13 | // per-series exemplar collection at req.Exemplars (set via q.Exemplars). |
| 14 | func TestAvgOverTimeExemplarLimit(t *testing.T) { |
| 15 | const limit = uint32(5) |
| 16 | req := &tempopb.QueryRangeRequest{ |
| 17 | Start: uint64(1 * time.Second), |
| 18 | End: uint64(100 * time.Second), |
| 19 | Step: uint64(10 * time.Second), |
| 20 | Query: "{ } | avg_over_time(duration) by (span.service)", |
| 21 | Exemplars: limit, |
| 22 | } |
| 23 | |
| 24 | a := newAverageOverTimeMetricsAggregator(IntrinsicDurationAttribute, []Attribute{NewAttribute("service")}) |
| 25 | a.init(req, AggregateModeRaw) |
| 26 | |
| 27 | // Send limit*3 spans, all for service=a, with distinct timestamps spread across the range. |
| 28 | for i := 0; i < int(limit)*3; i++ { |
| 29 | ts := uint64(i+1) * uint64(time.Second) |
| 30 | span := newMockSpan(nil).WithStartTime(ts).WithSpanString("service", "a").WithDuration(uint64(time.Second)) |
| 31 | a.observe(span) |
| 32 | a.observeExemplar(span) |
| 33 | } |
| 34 | |
| 35 | result := a.result(1.0) |
| 36 | serviceA, ok := result[LabelsFromArgs(".service", "a").MapKey()] |
| 37 | require.True(t, ok, "series for service=a must exist") |
| 38 | require.LessOrEqual(t, len(serviceA.Exemplars), int(limit), "exemplars must be capped at req.Exemplars") |
| 39 | require.Greater(t, len(serviceA.Exemplars), 0, "at least one exemplar must be collected") |
| 40 | } |
| 41 | |
| 42 | func TestAvgOverTime(t *testing.T) { |
| 43 | req := &tempopb.QueryRangeRequest{ |
nothing calls this directly
no test coverage detected