(t *testing.T)
| 1579 | } |
| 1580 | |
| 1581 | func TestAvgOverTimeForSpanAttribute(t *testing.T) { |
| 1582 | req := &tempopb.QueryRangeRequest{ |
| 1583 | Start: 1, |
| 1584 | End: uint64(3 * time.Second), |
| 1585 | Step: uint64(1 * time.Second), |
| 1586 | Query: "{ } | avg_over_time(span.http.status_code) by (span.foo)", |
| 1587 | } |
| 1588 | |
| 1589 | // A variety of spans across times, durations, and series. All durations are powers of 2 for simplicity |
| 1590 | in := []Span{ |
| 1591 | newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithSpanInt("http.status_code", 200).WithDuration(128), |
| 1592 | newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithSpanInt("http.status_code", 404).WithDuration(256), |
| 1593 | newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithSpanInt("http.status_code", 200).WithDuration(512), |
| 1594 | |
| 1595 | newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithSpanInt("http.status_code", 200).WithDuration(256), |
| 1596 | newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithSpanInt("http.status_code", 200).WithDuration(64), |
| 1597 | newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithSpanInt("http.status_code", 200).WithDuration(256), |
| 1598 | newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithSpanInt("http.status_code", 200).WithDuration(8), |
| 1599 | |
| 1600 | newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithSpanInt("http.status_code", 200).WithDuration(512), |
| 1601 | newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithSpanInt("http.status_code", 400).WithDuration(1024), |
| 1602 | newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithSpanInt("http.status_code", 300).WithDuration(512), |
| 1603 | } |
| 1604 | |
| 1605 | in2 := []Span{ |
| 1606 | newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithSpanInt("http.status_code", 200).WithDuration(128), |
| 1607 | newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithSpanInt("http.status_code", 200).WithDuration(256), |
| 1608 | newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithSpanInt("http.status_code", 200).WithDuration(512), |
| 1609 | |
| 1610 | newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithSpanInt("http.status_code", 200).WithDuration(256), |
| 1611 | newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithSpanInt("http.status_code", 200).WithDuration(64), |
| 1612 | newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithSpanInt("http.status_code", 200).WithDuration(256), |
| 1613 | newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithSpanInt("http.status_code", 200).WithDuration(8), |
| 1614 | |
| 1615 | newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithSpanInt("http.status_code", 200).WithDuration(512), |
| 1616 | newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithSpanInt("http.status_code", 200).WithDuration(1024), |
| 1617 | newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithSpanInt("http.status_code", 200).WithDuration(512), |
| 1618 | } |
| 1619 | |
| 1620 | result, seriesCount, err := runTraceQLMetric(req, in, in2) |
| 1621 | require.NoError(t, err) |
| 1622 | require.Equal(t, len(result), seriesCount) |
| 1623 | |
| 1624 | fooBaz := result[LabelsFromArgs("span.foo", "baz").MapKey()] |
| 1625 | fooBar := result[LabelsFromArgs("span.foo", "bar").MapKey()] |
| 1626 | |
| 1627 | // Alas,we cannot compare with require.Equal because NaN != NaN |
| 1628 | // foo.baz = (NaN, NaN, 250) |
| 1629 | assert.True(t, math.IsNaN(fooBaz.Values[0])) |
| 1630 | assert.True(t, math.IsNaN(fooBaz.Values[1])) |
| 1631 | assert.Equal(t, 250.0, fooBaz.Values[2]) |
| 1632 | |
| 1633 | // foo.bar = (234,200, NaN) |
| 1634 | assert.Equal(t, 234.0, fooBar.Values[0]) |
| 1635 | assert.Equal(t, 200.0, fooBar.Values[1]) |
| 1636 | assert.True(t, math.IsNaN(fooBar.Values[2])) |
| 1637 | |
| 1638 | // Test that NaN values are not included in the samples after casting to proto |
nothing calls this directly
no test coverage detected