(t *testing.T)
| 5528 | } |
| 5529 | |
| 5530 | func TestIngesterCompactIdleBlock(t *testing.T) { |
| 5531 | cfg := defaultIngesterTestConfig(t) |
| 5532 | cfg.LifecyclerConfig.JoinAfter = 0 |
| 5533 | cfg.BlocksStorageConfig.TSDB.ShipConcurrency = 1 |
| 5534 | cfg.BlocksStorageConfig.TSDB.HeadCompactionInterval = 1 * time.Hour // Long enough to not be reached during the test. |
| 5535 | cfg.BlocksStorageConfig.TSDB.HeadCompactionIdleTimeout = 1 * time.Second // Testing this. |
| 5536 | |
| 5537 | r := prometheus.NewRegistry() |
| 5538 | |
| 5539 | // Create ingester |
| 5540 | i, err := prepareIngesterWithBlocksStorage(t, cfg, r) |
| 5541 | require.NoError(t, err) |
| 5542 | |
| 5543 | require.NoError(t, services.StartAndAwaitRunning(context.Background(), i)) |
| 5544 | t.Cleanup(func() { |
| 5545 | _ = services.StopAndAwaitTerminated(context.Background(), i) |
| 5546 | }) |
| 5547 | |
| 5548 | // Wait until it's ACTIVE |
| 5549 | test.Poll(t, 1*time.Second, ring.ACTIVE, func() any { |
| 5550 | return i.lifecycler.GetState() |
| 5551 | }) |
| 5552 | |
| 5553 | pushSingleSampleWithMetadata(t, i) |
| 5554 | |
| 5555 | i.compactBlocks(context.Background(), false, nil) |
| 5556 | verifyCompactedHead(t, i, false) |
| 5557 | require.NoError(t, testutil.GatherAndCompare(r, strings.NewReader(` |
| 5558 | # HELP cortex_ingester_memory_series_created_total The total number of series that were created per user. |
| 5559 | # TYPE cortex_ingester_memory_series_created_total counter |
| 5560 | cortex_ingester_memory_series_created_total{user="1"} 1 |
| 5561 | |
| 5562 | # HELP cortex_ingester_memory_series_removed_total The total number of series that were removed per user. |
| 5563 | # TYPE cortex_ingester_memory_series_removed_total counter |
| 5564 | cortex_ingester_memory_series_removed_total{user="1"} 0 |
| 5565 | |
| 5566 | # HELP cortex_ingester_memory_users The current number of users in memory. |
| 5567 | # TYPE cortex_ingester_memory_users gauge |
| 5568 | cortex_ingester_memory_users 1 |
| 5569 | `), memSeriesCreatedTotalName, memSeriesRemovedTotalName, "cortex_ingester_memory_users")) |
| 5570 | |
| 5571 | // wait one second (plus maximum jitter) -- TSDB is now idle. |
| 5572 | time.Sleep(time.Duration(float64(cfg.BlocksStorageConfig.TSDB.HeadCompactionIdleTimeout) * (1 + compactionIdleTimeoutJitter))) |
| 5573 | |
| 5574 | i.compactBlocks(context.Background(), false, nil) |
| 5575 | verifyCompactedHead(t, i, true) |
| 5576 | require.NoError(t, testutil.GatherAndCompare(r, strings.NewReader(` |
| 5577 | # HELP cortex_ingester_memory_series_created_total The total number of series that were created per user. |
| 5578 | # TYPE cortex_ingester_memory_series_created_total counter |
| 5579 | cortex_ingester_memory_series_created_total{user="1"} 1 |
| 5580 | |
| 5581 | # HELP cortex_ingester_memory_series_removed_total The total number of series that were removed per user. |
| 5582 | # TYPE cortex_ingester_memory_series_removed_total counter |
| 5583 | cortex_ingester_memory_series_removed_total{user="1"} 1 |
| 5584 | |
| 5585 | # HELP cortex_ingester_memory_users The current number of users in memory. |
| 5586 | # TYPE cortex_ingester_memory_users gauge |
| 5587 | cortex_ingester_memory_users 1 |
nothing calls this directly
no test coverage detected