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

Function TestMaxOverTimeForDuration

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

Source from the content-addressed store, hash-verified

1830}
1831
1832func TestMaxOverTimeForDuration(t *testing.T) {
1833 req := &tempopb.QueryRangeRequest{
1834 Start: 1,
1835 End: uint64(3 * time.Second),
1836 Step: uint64(1 * time.Second),
1837 Query: "{ } | max_over_time(duration) by (span.foo)",
1838 }
1839
1840 // A variety of spans across times, durations, and series. All durations are powers of 2 for simplicity
1841 in := []Span{
1842 newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithDuration(128),
1843 newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithDuration(256),
1844 newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithDuration(512),
1845
1846 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithDuration(256),
1847 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithDuration(64),
1848 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithDuration(256),
1849 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithDuration(8),
1850
1851 newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithDuration(512),
1852 newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithDuration(1024),
1853 newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithDuration(512),
1854 }
1855
1856 result, seriesCount, err := runTraceQLMetric(req, in)
1857 require.NoError(t, err)
1858 require.Equal(t, len(result), seriesCount)
1859
1860 fooBaz := result[LabelsFromArgs("span.foo", "baz").MapKey()]
1861 fooBar := result[LabelsFromArgs("span.foo", "bar").MapKey()]
1862
1863 // We cannot compare with require.Equal because NaN != NaN
1864 // foo.baz = (NaN, NaN, 0.000000512)
1865 assert.True(t, math.IsNaN(fooBaz.Values[0]))
1866 assert.True(t, math.IsNaN(fooBaz.Values[1]))
1867 assert.Equal(t, 1024/float64(time.Second), fooBaz.Values[2])
1868
1869 // foo.bar = (0.000000128, 0.000000128, NaN)
1870 assert.Equal(t, 512/float64(time.Second), fooBar.Values[0])
1871 assert.Equal(t, 256/float64(time.Second), fooBar.Values[1])
1872 assert.True(t, math.IsNaN(fooBar.Values[2]))
1873}
1874
1875func TestMaxOverTimeWithNoMatch(t *testing.T) {
1876 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