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

Function TestAvgOverTimeExemplarLimit

pkg/traceql/engine_metrics_average_test.go:14–40  ·  view source on GitHub ↗

TestAvgOverTimeExemplarLimit verifies that avgOverTimeSpanAggregator caps per-series exemplar collection at req.Exemplars (set via q.Exemplars).

(t *testing.T)

Source from the content-addressed store, hash-verified

12// TestAvgOverTimeExemplarLimit verifies that avgOverTimeSpanAggregator caps
13// per-series exemplar collection at req.Exemplars (set via q.Exemplars).
14func 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
42func TestAvgOverTime(t *testing.T) {
43 req := &tempopb.QueryRangeRequest{

Callers

nothing calls this directly

Calls 12

NewAttributeFunction · 0.85
newMockSpanFunction · 0.85
LabelsFromArgsFunction · 0.85
WithDurationMethod · 0.80
WithSpanStringMethod · 0.80
WithStartTimeMethod · 0.80
initMethod · 0.65
observeMethod · 0.65
observeExemplarMethod · 0.65
resultMethod · 0.65
MapKeyMethod · 0.45

Tested by

no test coverage detected