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

Function TestSumOverTimeForSpanAttribute

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

Source from the content-addressed store, hash-verified

2023}
2024
2025func TestSumOverTimeForSpanAttribute(t *testing.T) {
2026 req := &tempopb.QueryRangeRequest{
2027 Start: 1,
2028 End: uint64(3 * time.Second),
2029 Step: uint64(1 * time.Second),
2030 Query: "{ } | sum_over_time(span.kafka.lag) by (span.foo)",
2031 }
2032
2033 // A variety of spans across times, durations, and series.
2034 in := []Span{
2035 newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithSpanInt("kafka.lag", 100).WithDuration(100),
2036 newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithSpanInt("kafka.lag", 200).WithDuration(256),
2037 newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithSpanInt("kafka.lag", 300).WithDuration(512),
2038
2039 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithSpanInt("kafka.lag", 200).WithDuration(256),
2040 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithSpanInt("kafka.lag", 200).WithDuration(64),
2041 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithSpanInt("kafka.lag", 200).WithDuration(256),
2042 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithSpanInt("kafka.lag", 200).WithDuration(8),
2043
2044 newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithSpanInt("kafka.lag", 200).WithDuration(512),
2045 newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithSpanInt("kafka.lag", 400).WithDuration(1024),
2046 newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithSpanInt("kafka.lag", 200).WithDuration(512),
2047 }
2048
2049 in2 := []Span{
2050 newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithSpanInt("kafka.lag", 100).WithDuration(128),
2051 newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithSpanInt("kafka.lag", 200).WithDuration(256),
2052 newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithSpanInt("kafka.lag", 300).WithDuration(512),
2053 newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "baz").WithSpanInt("kafka.lag", 200).WithDuration(512),
2054
2055 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithSpanInt("kafka.lag", 400).WithDuration(256),
2056 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithSpanInt("kafka.lag", 400).WithDuration(64),
2057 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithSpanInt("kafka.lag", 400).WithDuration(256),
2058 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithSpanInt("kafka.lag", 400).WithDuration(8),
2059
2060 newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithSpanInt("kafka.lag", 200).WithDuration(512),
2061 newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithSpanInt("kafka.lag", 300).WithDuration(1024),
2062 newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithSpanInt("kafka.lag", 400).WithDuration(512),
2063 }
2064
2065 result, seriesCount, err := runTraceQLMetric(req, in, in2)
2066 require.NoError(t, err)
2067 require.Equal(t, len(result), seriesCount)
2068
2069 fooBaz := result[LabelsFromArgs("span.foo", "baz").MapKey()]
2070 fooBar := result[LabelsFromArgs("span.foo", "bar").MapKey()]
2071
2072 // Alas,we cannot compare with require.Equal because NaN != NaN
2073 // foo.baz = (200, NaN, 1700)
2074 assert.Equal(t, 200.0, fooBaz.Values[0])
2075 assert.True(t, math.IsNaN(fooBaz.Values[1]))
2076 assert.Equal(t, 1700.0, fooBaz.Values[2])
2077
2078 // foo.bar = (1200,2400, NaN)
2079 assert.Equal(t, 1200.0, fooBar.Values[0])
2080 assert.Equal(t, 2400.0, fooBar.Values[1])
2081 assert.True(t, math.IsNaN(fooBar.Values[2]))
2082

Callers

nothing calls this directly

Calls 12

newMockSpanFunction · 0.85
runTraceQLMetricFunction · 0.85
LabelsFromArgsFunction · 0.85
LabelsFromProtoFunction · 0.85
WithDurationMethod · 0.80
WithSpanIntMethod · 0.80
WithSpanStringMethod · 0.80
WithStartTimeMethod · 0.80
ToProtoMethod · 0.80
EqualMethod · 0.45
MapKeyMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected