(t *testing.T)
| 1167 | } |
| 1168 | |
| 1169 | func TestRateCutoff(t *testing.T) { |
| 1170 | start := 1*time.Second + 300*time.Nanosecond // additional 300ns that can be accidentally dropped by ms conversion |
| 1171 | end := 3 * time.Second |
| 1172 | step := end - start |
| 1173 | cutoff := 2*time.Second + 300*time.Nanosecond |
| 1174 | |
| 1175 | req := tempopb.QueryRangeRequest{ |
| 1176 | Start: uint64(start), |
| 1177 | End: uint64(end), |
| 1178 | Step: uint64(step), |
| 1179 | Query: "{ } | rate()", |
| 1180 | } |
| 1181 | for _, tc := range []struct { |
| 1182 | name string |
| 1183 | setInstant func(req tempopb.QueryRangeRequest) tempopb.QueryRangeRequest |
| 1184 | expectedResult []float64 |
| 1185 | }{ |
| 1186 | { |
| 1187 | "legacy request (no instant param)", |
| 1188 | func(req tempopb.QueryRangeRequest) tempopb.QueryRangeRequest { |
| 1189 | req.Step = req.End - req.Start |
| 1190 | return req |
| 1191 | }, |
| 1192 | // BUG: without instant query provided, instant rate is calculated incorrectly as sum of rates for each sub-interval |
| 1193 | []float64{(4 / (cutoff - start).Seconds()) + (4 / (end - cutoff).Seconds())}, |
| 1194 | }, |
| 1195 | { |
| 1196 | "instant query", |
| 1197 | func(req tempopb.QueryRangeRequest) tempopb.QueryRangeRequest { |
| 1198 | req.SetInstant(true) |
| 1199 | return req |
| 1200 | }, |
| 1201 | []float64{8 / step.Seconds()}, |
| 1202 | }, |
| 1203 | { |
| 1204 | "not instant query", |
| 1205 | func(req tempopb.QueryRangeRequest) tempopb.QueryRangeRequest { |
| 1206 | req.SetInstant(false) |
| 1207 | return req |
| 1208 | }, |
| 1209 | // consumes all spans due to step alignment |
| 1210 | []float64{11 / step.Seconds(), 3 / step.Seconds()}, |
| 1211 | }, |
| 1212 | } { |
| 1213 | t.Run(tc.name, func(t *testing.T) { |
| 1214 | req = tc.setInstant(req) |
| 1215 | |
| 1216 | // from start to cutoff |
| 1217 | req1 := req |
| 1218 | req1.End = uint64(cutoff) |
| 1219 | req1 = tc.setInstant(req1) |
| 1220 | // from cutoff to end |
| 1221 | req2 := req |
| 1222 | req2.Start = uint64(cutoff) |
| 1223 | req2 = tc.setInstant(req2) |
| 1224 | |
| 1225 | in1 := []Span{ |
| 1226 | // outside of the range but within the range for ms. Should be ignored for instant queries. |
nothing calls this directly
no test coverage detected