@@ -1294,6 +1294,43 @@ func TestAvgOverTimeForDurationWithoutAggregation(t *testing.T) {
12941294 assert .Equal (t , 200. , avg .Values [2 ]* float64 (time .Second ))
12951295}
12961296
1297+ func TestAvgOverTimeCombine (t * testing.T ) {
1298+ req := & tempopb.QueryRangeRequest {
1299+ Start : 1 ,
1300+ End : uint64 (3 * time .Second ),
1301+ Step : uint64 (1 * time .Second ),
1302+ Query : "{ } | avg_over_time(duration)" ,
1303+ }
1304+
1305+ // Three set of spans with different data for a single time interval
1306+ // Each set will be passed to level 2 independently
1307+ in1 := []Span {
1308+ newMockSpan (nil ).WithStartTime (uint64 (1 * time .Second )).WithDuration (uint64 (100 * time .Second )),
1309+ }
1310+
1311+ in2 := []Span {
1312+ newMockSpan (nil ).WithStartTime (uint64 (1 * time .Second )).WithDuration (uint64 (200 * time .Second )),
1313+ newMockSpan (nil ).WithStartTime (uint64 (1 * time .Second )).WithDuration (uint64 (400 * time .Second )),
1314+ }
1315+
1316+ in3 := []Span {
1317+ newMockSpan (nil ).WithStartTime (uint64 (1 * time .Second )).WithDuration (uint64 (500 * time .Second )),
1318+ newMockSpan (nil ).WithStartTime (uint64 (1 * time .Second )).WithDuration (uint64 (600 * time .Second )),
1319+ newMockSpan (nil ).WithStartTime (uint64 (1 * time .Second )).WithDuration (uint64 (700 * time .Second )),
1320+ }
1321+
1322+ result , seriesCount , err := runTraceQLMetric (req , in1 , in2 , in3 )
1323+ require .NoError (t , err )
1324+ require .Equal (t , len (result ), seriesCount )
1325+
1326+ avg := result [LabelsFromArgs ("__name__" , "avg_over_time" ).MapKey ()]
1327+
1328+ expectedResult := (100 + 200 + 400 + 500 + 600 + 700 ) / 6.
1329+ assert .Equal (t , expectedResult , avg .Values [0 ])
1330+ assert .True (t , math .IsNaN (avg .Values [1 ]), "expected NaN, got %f" , avg .Values [1 ])
1331+ assert .True (t , math .IsNaN (avg .Values [2 ]), "expected NaN, got %f" , avg .Values [2 ])
1332+ }
1333+
12971334func TestAvgOverTimeForSpanAttribute (t * testing.T ) {
12981335 req := & tempopb.QueryRangeRequest {
12991336 Start : 1 ,
0 commit comments