(t *testing.T)
| 1425 | } |
| 1426 | |
| 1427 | func 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 | |
| 1468 | func TestAvgOverTimeForDurationWithSecondStage(t *testing.T) { |
| 1469 | req := &tempopb.QueryRangeRequest{ |
nothing calls this directly
no test coverage detected