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

Function TestMinOverTimeForDuration

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

Source from the content-addressed store, hash-verified

1276}
1277
1278func TestMinOverTimeForDuration(t *testing.T) {
1279 req := &tempopb.QueryRangeRequest{
1280 Start: 1,
1281 End: uint64(3 * time.Second),
1282 Step: uint64(1 * time.Second),
1283 Query: "{ } | min_over_time(duration) by (span.foo)",
1284 }
1285
1286 // A variety of spans across times, durations, and series. All durations are powers of 2 for simplicity
1287 in := []Span{
1288 newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithDuration(128),
1289 newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithDuration(256),
1290 newMockSpan(nil).WithStartTime(uint64(1*time.Second)).WithSpanString("foo", "bar").WithDuration(512),
1291
1292 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithDuration(256),
1293 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithDuration(64),
1294 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithDuration(256),
1295 newMockSpan(nil).WithStartTime(uint64(2*time.Second)).WithSpanString("foo", "bar").WithDuration(8),
1296
1297 newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithDuration(512),
1298 newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithDuration(1024),
1299 newMockSpan(nil).WithStartTime(uint64(3*time.Second)).WithSpanString("foo", "baz").WithDuration(512),
1300 }
1301
1302 result, seriesCount, err := runTraceQLMetric(req, in)
1303 require.NoError(t, err)
1304
1305 fooBaz := result[LabelsFromArgs("span.foo", "baz").MapKey()]
1306 fooBar := result[LabelsFromArgs("span.foo", "bar").MapKey()]
1307
1308 // We cannot compare with require.Equal because NaN != NaN
1309 // foo.baz = (NaN, NaN, 0.000000512)
1310 assert.True(t, math.IsNaN(fooBaz.Values[0]))
1311 assert.True(t, math.IsNaN(fooBaz.Values[1]))
1312 assert.Equal(t, 512/float64(time.Second), fooBaz.Values[2])
1313
1314 // foo.bar = (0.000000128, 0.000000128, NaN)
1315 assert.Equal(t, 128/float64(time.Second), fooBar.Values[0])
1316 assert.Equal(t, 8/float64(time.Second), fooBar.Values[1])
1317 assert.True(t, math.IsNaN(fooBar.Values[2]))
1318 require.Equal(t, len(result), seriesCount)
1319}
1320
1321func TestMinOverTimeWithNoMatch(t *testing.T) {
1322 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
MapKeyMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected