(t *testing.T)
| 5269 | } |
| 5270 | |
| 5271 | func TestIngester_ForFlush(t *testing.T) { |
| 5272 | cfg := defaultIngesterTestConfig(t) |
| 5273 | cfg.LifecyclerConfig.JoinAfter = 0 |
| 5274 | cfg.BlocksStorageConfig.TSDB.ShipConcurrency = 1 |
| 5275 | cfg.BlocksStorageConfig.TSDB.ShipInterval = 10 * time.Minute // Long enough to not be reached during the test. |
| 5276 | |
| 5277 | // Create ingester |
| 5278 | reg := prometheus.NewPedanticRegistry() |
| 5279 | i, err := prepareIngesterWithBlocksStorage(t, cfg, reg) |
| 5280 | require.NoError(t, err) |
| 5281 | |
| 5282 | require.NoError(t, services.StartAndAwaitRunning(context.Background(), i)) |
| 5283 | t.Cleanup(func() { |
| 5284 | _ = services.StopAndAwaitTerminated(context.Background(), i) |
| 5285 | }) |
| 5286 | |
| 5287 | // Wait until it's ACTIVE |
| 5288 | test.Poll(t, 1*time.Second, ring.ACTIVE, func() any { |
| 5289 | return i.lifecycler.GetState() |
| 5290 | }) |
| 5291 | |
| 5292 | // Push some data. |
| 5293 | pushSingleSampleWithMetadata(t, i) |
| 5294 | |
| 5295 | // Stop ingester. |
| 5296 | require.NoError(t, services.StopAndAwaitTerminated(context.Background(), i)) |
| 5297 | |
| 5298 | // Nothing shipped yet. |
| 5299 | require.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(` |
| 5300 | # HELP cortex_ingester_shipper_uploads_total Total number of uploaded TSDB blocks |
| 5301 | # TYPE cortex_ingester_shipper_uploads_total counter |
| 5302 | cortex_ingester_shipper_uploads_total 0 |
| 5303 | `), "cortex_ingester_shipper_uploads_total")) |
| 5304 | |
| 5305 | // Restart ingester in "For Flusher" mode. We reuse the same config (esp. same dir) |
| 5306 | reg = prometheus.NewPedanticRegistry() |
| 5307 | i, err = NewForFlusher(i.cfg, i.limits, reg, log.NewNopLogger()) |
| 5308 | require.NoError(t, err) |
| 5309 | require.NoError(t, services.StartAndAwaitRunning(context.Background(), i)) |
| 5310 | |
| 5311 | // Our single sample should be reloaded from WAL |
| 5312 | verifyCompactedHead(t, i, false) |
| 5313 | i.Flush() |
| 5314 | |
| 5315 | // Head should be empty after flushing. |
| 5316 | verifyCompactedHead(t, i, true) |
| 5317 | |
| 5318 | // Verify that block has been shipped. |
| 5319 | require.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(` |
| 5320 | # HELP cortex_ingester_shipper_uploads_total Total number of uploaded TSDB blocks |
| 5321 | # TYPE cortex_ingester_shipper_uploads_total counter |
| 5322 | cortex_ingester_shipper_uploads_total 1 |
| 5323 | `), "cortex_ingester_shipper_uploads_total")) |
| 5324 | |
| 5325 | require.NoError(t, services.StopAndAwaitTerminated(context.Background(), i)) |
| 5326 | } |
| 5327 | |
| 5328 | func mockUserShipper(t *testing.T, i *Ingester) *shipperMock { |
nothing calls this directly
no test coverage detected