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

Function TestHeadCompactionOnStartup

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

Source from the content-addressed store, hash-verified

5749}
5750
5751func TestHeadCompactionOnStartup(t *testing.T) {
5752 // Create a temporary directory for TSDB
5753 tempDir := t.TempDir()
5754
5755 // Build TSDB for user, with data covering 24 hours.
5756 {
5757 // Number of full chunks, 12 chunks for 24hrs.
5758 numFullChunks := 12
5759 chunkRange := 2 * time.Hour.Milliseconds()
5760
5761 userDir := filepath.Join(tempDir, userID)
5762 require.NoError(t, os.Mkdir(userDir, 0700))
5763
5764 db, err := tsdb.Open(userDir, nil, nil, &tsdb.Options{
5765 RetentionDuration: int64(time.Hour * 25 / time.Millisecond),
5766 NoLockfile: true,
5767 MinBlockDuration: chunkRange,
5768 MaxBlockDuration: chunkRange,
5769 }, nil)
5770 require.NoError(t, err)
5771
5772 db.DisableCompactions()
5773 head := db.Head()
5774
5775 l := labels.FromStrings("n", "v")
5776 for i := range numFullChunks {
5777 // Not using db.Appender() as it checks for compaction.
5778 app := head.Appender(context.Background())
5779 _, err := app.Append(0, l, int64(i)*chunkRange+1, 9.99)
5780 require.NoError(t, err)
5781 _, err = app.Append(0, l, int64(i+1)*chunkRange, 9.99)
5782 require.NoError(t, err)
5783 require.NoError(t, app.Commit())
5784 }
5785
5786 dur := time.Duration(head.MaxTime()-head.MinTime()) * time.Millisecond
5787 require.True(t, dur > 23*time.Hour)
5788 require.Equal(t, 0, len(db.Blocks()))
5789 require.NoError(t, db.Close())
5790 }
5791
5792 limits := defaultLimitsTestConfig()
5793
5794 overrides := validation.NewOverrides(limits, nil)
5795
5796 ingesterCfg := defaultIngesterTestConfig(t)
5797 ingesterCfg.BlocksStorageConfig.TSDB.Dir = tempDir
5798 ingesterCfg.BlocksStorageConfig.Bucket.Backend = "s3"
5799 ingesterCfg.BlocksStorageConfig.Bucket.S3.Endpoint = "localhost"
5800 ingesterCfg.BlocksStorageConfig.TSDB.Retention = 2 * 24 * time.Hour // Make sure that no newly created blocks are deleted.
5801
5802 ingester, err := New(ingesterCfg, overrides, prometheus.NewRegistry(), log.NewNopLogger(), nil)
5803 require.NoError(t, err)
5804 require.NoError(t, services.StartAndAwaitRunning(context.Background(), ingester))
5805
5806 defer services.StopAndAwaitTerminated(context.Background(), ingester) //nolint:errcheck
5807
5808 db, err := ingester.getTSDB(userID)

Callers

nothing calls this directly

Calls 15

NewOverridesFunction · 0.92
StartAndAwaitRunningFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
defaultLimitsTestConfigFunction · 0.85
JoinMethod · 0.80
HeadMethod · 0.80
AppendMethod · 0.80
BlocksMethod · 0.80
getTSDBMethod · 0.80
NewFunction · 0.70
EqualMethod · 0.65

Tested by

no test coverage detected