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

Function TestAvgOverTimeForDuration

pkg/traceql/engine_metrics_test.go:1427–1466  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1425}
1426
1427func TestAvgOverTimeForDuration(t *testing.T) {
1428 req := &tempopb.QueryRangeRequest{
1429 Start: 1,
1430 End: uint64(3 * time.Second),
1431 Step: uint64(1 * time.Second),
1432 Query: "{ } | avg_over_time(duration) by (span.foo)",
1433 }
1434
1435 // A variety of spans across times, durations, and series. All durations are powers of 2 for simplicity
1436 in := []Span{
1437 newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithDuration(100),
1438 newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithDuration(100),
1439 newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithDuration(100),
1440
1441 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithDuration(100),
1442 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithDuration(100),
1443 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithDuration(100),
1444 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithDuration(500),
1445
1446 newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithDuration(100),
1447 newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithDuration(200),
1448 newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithDuration(300),
1449 }
1450
1451 result, seriesCount, err := runTraceQLMetric(req, in)
1452 require.NoError(t, err)
1453 require.Equal(t, len(result), seriesCount)
1454
1455 fooBaz := result[LabelsFromArgs("span.foo", "baz").MapKey()]
1456 fooBar := result[LabelsFromArgs("span.foo", "bar").MapKey()]
1457
1458 // We cannot compare with require.Equal because NaN != NaN
1459 assert.True(t, math.IsNaN(fooBaz.Values[0]))
1460 assert.True(t, math.IsNaN(fooBaz.Values[1]))
1461 assert.Equal(t, 200., fooBaz.Values[2]*float64(time.Second))
1462
1463 assert.Equal(t, 100., fooBar.Values[0]*float64(time.Second))
1464 assert.Equal(t, 200., fooBar.Values[1]*float64(time.Second))
1465 assert.True(t, math.IsNaN(fooBar.Values[2]))
1466}
1467
1468func TestAvgOverTimeForDurationWithSecondStage(t *testing.T) {
1469 req := &tempopb.QueryRangeRequest{

Callers

nothing calls this directly

Calls 8

newMockSpanFunction · 0.85
runTraceQLMetricFunction · 0.85
LabelsFromArgsFunction · 0.85
WithDurationMethod · 0.80
WithSpanStringMethod · 0.80
WithStartTimeMethod · 0.80
EqualMethod · 0.45
MapKeyMethod · 0.45

Tested by

no test coverage detected