(t *testing.T)
| 327 | } |
| 328 | |
| 329 | func TestTrimToBlockOverlap(t *testing.T) { |
| 330 | tc := []struct { |
| 331 | start1, end1 string |
| 332 | step time.Duration |
| 333 | start2, end2 string |
| 334 | expectedStart, expectedEnd string |
| 335 | expectedStep time.Duration |
| 336 | }{ |
| 337 | { |
| 338 | // Block fully within range |
| 339 | // Left border is extended to the next step. |
| 340 | // Right border is extended to the next step. |
| 341 | "2024-01-01T01:00:00Z", "2024-01-01T02:00:00Z", 5 * time.Minute, |
| 342 | "2024-01-01T01:33:00Z", "2024-01-01T01:38:00Z", |
| 343 | "2024-01-01T01:30:00Z", "2024-01-01T01:40:00Z", 5 * time.Minute, |
| 344 | }, |
| 345 | { |
| 346 | // Block overlapping right border. |
| 347 | // Left border is extended to the next step. |
| 348 | // Right border preserved. |
| 349 | "2024-01-01T01:01:00Z", "2024-01-01T02:01:00.123Z", 5 * time.Minute, |
| 350 | "2024-01-01T01:31:00Z", "2024-01-01T02:31:00Z", |
| 351 | "2024-01-01T01:30:00Z", "2024-01-01T02:01:00.123Z", 5 * time.Minute, |
| 352 | }, |
| 353 | { |
| 354 | // Block overlapping left border. |
| 355 | // Left border preserved. |
| 356 | // Right border extended to the next step. |
| 357 | "2024-01-01T01:01:00.123Z", "2024-01-01T02:00:00Z", 5 * time.Minute, |
| 358 | "2024-01-01T00:31:00Z", "2024-01-01T01:31:00Z", |
| 359 | "2024-01-01T01:01:00.123Z", "2024-01-01T01:35:00Z", 5 * time.Minute, |
| 360 | }, |
| 361 | { |
| 362 | // Block larger than range |
| 363 | // Neither border is extended. Nanoseconds preserved. |
| 364 | "2024-01-01T01:00:01.123Z", "2024-01-01T01:15:01.123Z", 5 * time.Minute, |
| 365 | "2024-01-01T00:00:00Z", "2024-01-01T02:00:00Z", |
| 366 | "2024-01-01T01:00:01.123Z", "2024-01-01T01:15:01.123Z", 5 * time.Minute, |
| 367 | }, |
| 368 | { |
| 369 | // Instant query, block overlaps right border. |
| 370 | // Original range is 1h |
| 371 | // Right border isn't extended past request range. |
| 372 | // Left border is able to be extended. |
| 373 | "2024-01-01T01:00:00.123Z", "2024-01-01T02:00:00.123Z", time.Hour, |
| 374 | "2024-01-01T01:30:00.123Z", "2024-01-01T02:30:00.123Z", |
| 375 | // we subtract a nanosecond to the start to make sure it's before the block start |
| 376 | "2024-01-01T01:30:00.122999999Z", "2024-01-01T02:00:00.123Z", 30*time.Minute + time.Nanosecond, |
| 377 | }, |
| 378 | } |
| 379 | |
| 380 | for _, c := range tc { |
| 381 | start1, _ := time.Parse(time.RFC3339Nano, c.start1) |
| 382 | end1, _ := time.Parse(time.RFC3339Nano, c.end1) |
| 383 | start2, _ := time.Parse(time.RFC3339Nano, c.start2) |
| 384 | end2, _ := time.Parse(time.RFC3339Nano, c.end2) |
| 385 | |
| 386 | req := &tempopb.QueryRangeRequest{ |
nothing calls this directly
no test coverage detected