MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestIngester_flushing

Function TestIngester_flushing

pkg/ingester/ingester_test.go:5055–5269  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

5053}
5054
5055func TestIngester_flushing(t *testing.T) {
5056 for name, tc := range map[string]struct {
5057 setupIngester func(cfg *Config)
5058 action func(t *testing.T, i *Ingester, reg *prometheus.Registry)
5059 }{
5060 "ingesterShutdown": {
5061 setupIngester: func(cfg *Config) {
5062 cfg.BlocksStorageConfig.TSDB.FlushBlocksOnShutdown = true
5063 cfg.BlocksStorageConfig.TSDB.KeepUserTSDBOpenOnShutdown = true
5064 },
5065 action: func(t *testing.T, i *Ingester, reg *prometheus.Registry) {
5066 pushSingleSampleWithMetadata(t, i)
5067
5068 // Nothing shipped yet.
5069 require.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(`
5070 # HELP cortex_ingester_shipper_uploads_total Total number of uploaded TSDB blocks
5071 # TYPE cortex_ingester_shipper_uploads_total counter
5072 cortex_ingester_shipper_uploads_total 0
5073 `), "cortex_ingester_shipper_uploads_total"))
5074
5075 // Shutdown ingester. This triggers flushing of the block.
5076 require.NoError(t, services.StopAndAwaitTerminated(context.Background(), i))
5077
5078 verifyCompactedHead(t, i, true)
5079
5080 // Verify that block has been shipped.
5081 require.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(`
5082 # HELP cortex_ingester_shipper_uploads_total Total number of uploaded TSDB blocks
5083 # TYPE cortex_ingester_shipper_uploads_total counter
5084 cortex_ingester_shipper_uploads_total 1
5085 `), "cortex_ingester_shipper_uploads_total"))
5086 },
5087 },
5088
5089 "shutdownHandler": {
5090 setupIngester: func(cfg *Config) {
5091 cfg.BlocksStorageConfig.TSDB.FlushBlocksOnShutdown = false
5092 cfg.BlocksStorageConfig.TSDB.KeepUserTSDBOpenOnShutdown = true
5093 },
5094
5095 action: func(t *testing.T, i *Ingester, reg *prometheus.Registry) {
5096 pushSingleSampleWithMetadata(t, i)
5097
5098 // Nothing shipped yet.
5099 require.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(`
5100 # HELP cortex_ingester_shipper_uploads_total Total number of uploaded TSDB blocks
5101 # TYPE cortex_ingester_shipper_uploads_total counter
5102 cortex_ingester_shipper_uploads_total 0
5103 `), "cortex_ingester_shipper_uploads_total"))
5104
5105 i.ShutdownHandler(httptest.NewRecorder(), httptest.NewRequest("POST", "/shutdown", nil))
5106
5107 verifyCompactedHead(t, i, true)
5108 require.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(`
5109 # HELP cortex_ingester_shipper_uploads_total Total number of uploaded TSDB blocks
5110 # TYPE cortex_ingester_shipper_uploads_total counter
5111 cortex_ingester_shipper_uploads_total 1
5112 `), "cortex_ingester_shipper_uploads_total"))

Callers

nothing calls this directly

Calls 15

StopAndAwaitTerminatedFunction · 0.92
StartAndAwaitRunningFunction · 0.92
PollFunction · 0.92
verifyCompactedHeadFunction · 0.85
pushSingleSampleAtTimeFunction · 0.85
getTSDBMethod · 0.80
BlocksMethod · 0.80
ShutdownHandlerMethod · 0.65
FlushHandlerMethod · 0.65

Tested by

no test coverage detected