mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Merge pull request #10193 from Juneezee/refactor/testing.TempDir
refactor: use `T.TempDir()` and `B.TempDir` to create temporary directory
This commit is contained in:
commit
7c6595ed14
|
@ -53,12 +53,9 @@ type testRunner struct {
|
||||||
func newTestRunner(t *testing.T) *testRunner {
|
func newTestRunner(t *testing.T) *testRunner {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
tmpDir, err := ioutil.TempDir("", "prometheus-file-sd")
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
return &testRunner{
|
return &testRunner{
|
||||||
T: t,
|
T: t,
|
||||||
dir: tmpDir,
|
dir: t.TempDir(),
|
||||||
ch: make(chan []*targetgroup.Group),
|
ch: make(chan []*targetgroup.Group),
|
||||||
done: make(chan struct{}),
|
done: make(chan struct{}),
|
||||||
stopped: make(chan struct{}),
|
stopped: make(chan struct{}),
|
||||||
|
|
|
@ -913,11 +913,7 @@ func TestCalculateDesiredShardsDetail(t *testing.T) {
|
||||||
cfg := config.DefaultQueueConfig
|
cfg := config.DefaultQueueConfig
|
||||||
mcfg := config.DefaultMetadataConfig
|
mcfg := config.DefaultMetadataConfig
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "TestCalculateDesiredShards")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
metrics := newQueueManagerMetrics(nil, "", "")
|
metrics := newQueueManagerMetrics(nil, "", "")
|
||||||
samplesIn := newEWMARate(ewmaWeight, shardUpdateDuration)
|
samplesIn := newEWMARate(ewmaWeight, shardUpdateDuration)
|
||||||
|
|
|
@ -19,7 +19,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash/crc32"
|
"hash/crc32"
|
||||||
"io/ioutil"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -42,13 +41,9 @@ import (
|
||||||
// to 2. We had a migration in place resetting it to 1 but we should move immediately to
|
// to 2. We had a migration in place resetting it to 1 but we should move immediately to
|
||||||
// version 3 next time to avoid confusion and issues.
|
// version 3 next time to avoid confusion and issues.
|
||||||
func TestBlockMetaMustNeverBeVersion2(t *testing.T) {
|
func TestBlockMetaMustNeverBeVersion2(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "metaversion")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
_, err = writeMetaFile(log.NewNopLogger(), dir, &BlockMeta{})
|
_, err := writeMetaFile(log.NewNopLogger(), dir, &BlockMeta{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
meta, _, err := readMetaFile(dir)
|
meta, _, err := readMetaFile(dir)
|
||||||
|
@ -57,11 +52,7 @@ func TestBlockMetaMustNeverBeVersion2(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetCompactionFailed(t *testing.T) {
|
func TestSetCompactionFailed(t *testing.T) {
|
||||||
tmpdir, err := ioutil.TempDir("", "test")
|
tmpdir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(tmpdir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
blockDir := createBlock(t, tmpdir, genSeries(1, 1, 0, 1))
|
blockDir := createBlock(t, tmpdir, genSeries(1, 1, 0, 1))
|
||||||
b, err := OpenBlock(nil, blockDir, nil)
|
b, err := OpenBlock(nil, blockDir, nil)
|
||||||
|
@ -78,11 +69,7 @@ func TestSetCompactionFailed(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateBlock(t *testing.T) {
|
func TestCreateBlock(t *testing.T) {
|
||||||
tmpdir, err := ioutil.TempDir("", "test")
|
tmpdir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(tmpdir))
|
|
||||||
}()
|
|
||||||
b, err := OpenBlock(nil, createBlock(t, tmpdir, genSeries(1, 1, 0, 10)), nil)
|
b, err := OpenBlock(nil, createBlock(t, tmpdir, genSeries(1, 1, 0, 10)), nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
require.NoError(t, b.Close())
|
require.NoError(t, b.Close())
|
||||||
|
@ -173,11 +160,7 @@ func TestCorruptedChunk(t *testing.T) {
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
tmpdir, err := ioutil.TempDir("", "test_open_block_chunk_corrupted")
|
tmpdir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(tmpdir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
series := storage.NewListSeries(labels.FromStrings("a", "b"), []tsdbutil.Sample{sample{1, 1}})
|
series := storage.NewListSeries(labels.FromStrings("a", "b"), []tsdbutil.Sample{sample{1, 1}})
|
||||||
blockDir := createBlock(t, tmpdir, []storage.Series{series})
|
blockDir := createBlock(t, tmpdir, []storage.Series{series})
|
||||||
|
@ -215,11 +198,7 @@ func TestCorruptedChunk(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLabelValuesWithMatchers(t *testing.T) {
|
func TestLabelValuesWithMatchers(t *testing.T) {
|
||||||
tmpdir, err := ioutil.TempDir("", "test_block_label_values_with_matchers")
|
tmpdir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(tmpdir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
var seriesEntries []storage.Series
|
var seriesEntries []storage.Series
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
|
@ -288,16 +267,13 @@ func TestLabelValuesWithMatchers(t *testing.T) {
|
||||||
|
|
||||||
// TestBlockSize ensures that the block size is calculated correctly.
|
// TestBlockSize ensures that the block size is calculated correctly.
|
||||||
func TestBlockSize(t *testing.T) {
|
func TestBlockSize(t *testing.T) {
|
||||||
tmpdir, err := ioutil.TempDir("", "test_blockSize")
|
tmpdir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(tmpdir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
blockInit *Block
|
blockInit *Block
|
||||||
expSizeInit int64
|
expSizeInit int64
|
||||||
blockDirInit string
|
blockDirInit string
|
||||||
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
// Create a block and compare the reported size vs actual disk size.
|
// Create a block and compare the reported size vs actual disk size.
|
||||||
|
@ -376,11 +352,7 @@ func TestReadIndexFormatV1(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkLabelValuesWithMatchers(b *testing.B) {
|
func BenchmarkLabelValuesWithMatchers(b *testing.B) {
|
||||||
tmpdir, err := ioutil.TempDir("", "bench_block_label_values_with_matchers")
|
tmpdir := b.TempDir()
|
||||||
require.NoError(b, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(b, os.RemoveAll(tmpdir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
var seriesEntries []storage.Series
|
var seriesEntries []storage.Series
|
||||||
metricCount := 1000000
|
metricCount := 1000000
|
||||||
|
@ -419,9 +391,7 @@ func BenchmarkLabelValuesWithMatchers(b *testing.B) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLabelNamesWithMatchers(t *testing.T) {
|
func TestLabelNamesWithMatchers(t *testing.T) {
|
||||||
tmpdir, err := ioutil.TempDir("", "test_block_label_names_with_matchers")
|
tmpdir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
t.Cleanup(func() { require.NoError(t, os.RemoveAll(tmpdir)) })
|
|
||||||
|
|
||||||
var seriesEntries []storage.Series
|
var seriesEntries []storage.Series
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
|
|
|
@ -15,9 +15,7 @@ package tsdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
|
||||||
"math"
|
"math"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -30,9 +28,7 @@ import (
|
||||||
|
|
||||||
func TestBlockWriter(t *testing.T) {
|
func TestBlockWriter(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
outputDir, err := ioutil.TempDir(os.TempDir(), "output")
|
outputDir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() { require.NoError(t, os.RemoveAll(outputDir)) }()
|
|
||||||
w, err := NewBlockWriter(log.NewNopLogger(), outputDir, DefaultBlockDuration)
|
w, err := NewBlockWriter(log.NewNopLogger(), outputDir, DefaultBlockDuration)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|
|
@ -450,12 +450,7 @@ func TestHeadReadWriter_ReadRepairOnEmptyLastFile(t *testing.T) {
|
||||||
|
|
||||||
func createChunkDiskMapper(t *testing.T, dir string) *ChunkDiskMapper {
|
func createChunkDiskMapper(t *testing.T, dir string) *ChunkDiskMapper {
|
||||||
if dir == "" {
|
if dir == "" {
|
||||||
var err error
|
dir = t.TempDir()
|
||||||
dir, err = ioutil.TempDir("", "data")
|
|
||||||
require.NoError(t, err)
|
|
||||||
t.Cleanup(func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hrw, err := NewChunkDiskMapper(nil, dir, chunkenc.NewPool(), DefaultWriteBufferSize, DefaultWriteQueueSize)
|
hrw, err := NewChunkDiskMapper(nil, dir, chunkenc.NewPool(), DefaultWriteBufferSize, DefaultWriteQueueSize)
|
||||||
|
|
|
@ -16,7 +16,6 @@ package tsdb
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
@ -435,11 +434,7 @@ func TestCompactionFailWillCleanUpTempDir(t *testing.T) {
|
||||||
}, nil, nil)
|
}, nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
tmpdir, err := ioutil.TempDir("", "test")
|
tmpdir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(tmpdir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
require.Error(t, compactor.write(tmpdir, &BlockMeta{}, erringBReader{}))
|
require.Error(t, compactor.write(tmpdir, &BlockMeta{}, erringBReader{}))
|
||||||
_, err = os.Stat(filepath.Join(tmpdir, BlockMeta{}.ULID.String()) + tmpForCreationBlockDirSuffix)
|
_, err = os.Stat(filepath.Join(tmpdir, BlockMeta{}.ULID.String()) + tmpForCreationBlockDirSuffix)
|
||||||
|
@ -1049,11 +1044,7 @@ func BenchmarkCompaction(b *testing.B) {
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
nBlocks := len(c.ranges)
|
nBlocks := len(c.ranges)
|
||||||
b.Run(fmt.Sprintf("type=%s,blocks=%d,series=%d,samplesPerSeriesPerBlock=%d", c.compactionType, nBlocks, nSeries, c.ranges[0][1]-c.ranges[0][0]+1), func(b *testing.B) {
|
b.Run(fmt.Sprintf("type=%s,blocks=%d,series=%d,samplesPerSeriesPerBlock=%d", c.compactionType, nBlocks, nSeries, c.ranges[0][1]-c.ranges[0][0]+1), func(b *testing.B) {
|
||||||
dir, err := ioutil.TempDir("", "bench_compaction")
|
dir := b.TempDir()
|
||||||
require.NoError(b, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(b, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
blockDirs := make([]string, 0, len(c.ranges))
|
blockDirs := make([]string, 0, len(c.ranges))
|
||||||
var blocks []*Block
|
var blocks []*Block
|
||||||
for _, r := range c.ranges {
|
for _, r := range c.ranges {
|
||||||
|
@ -1080,20 +1071,12 @@ func BenchmarkCompaction(b *testing.B) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkCompactionFromHead(b *testing.B) {
|
func BenchmarkCompactionFromHead(b *testing.B) {
|
||||||
dir, err := ioutil.TempDir("", "bench_compaction_from_head")
|
dir := b.TempDir()
|
||||||
require.NoError(b, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(b, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
totalSeries := 100000
|
totalSeries := 100000
|
||||||
for labelNames := 1; labelNames < totalSeries; labelNames *= 10 {
|
for labelNames := 1; labelNames < totalSeries; labelNames *= 10 {
|
||||||
labelValues := totalSeries / labelNames
|
labelValues := totalSeries / labelNames
|
||||||
b.Run(fmt.Sprintf("labelnames=%d,labelvalues=%d", labelNames, labelValues), func(b *testing.B) {
|
b.Run(fmt.Sprintf("labelnames=%d,labelvalues=%d", labelNames, labelValues), func(b *testing.B) {
|
||||||
chunkDir, err := ioutil.TempDir("", "chunk_dir")
|
chunkDir := b.TempDir()
|
||||||
require.NoError(b, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(b, os.RemoveAll(chunkDir))
|
|
||||||
}()
|
|
||||||
opts := DefaultHeadOptions()
|
opts := DefaultHeadOptions()
|
||||||
opts.ChunkRange = 1000
|
opts.ChunkRange = 1000
|
||||||
opts.ChunkDirRoot = chunkDir
|
opts.ChunkDirRoot = chunkDir
|
||||||
|
@ -1175,11 +1158,7 @@ func TestDisableAutoCompactions(t *testing.T) {
|
||||||
// TestCancelCompactions ensures that when the db is closed
|
// TestCancelCompactions ensures that when the db is closed
|
||||||
// any running compaction is cancelled to unblock closing the db.
|
// any running compaction is cancelled to unblock closing the db.
|
||||||
func TestCancelCompactions(t *testing.T) {
|
func TestCancelCompactions(t *testing.T) {
|
||||||
tmpdir, err := ioutil.TempDir("", "testCancelCompaction")
|
tmpdir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(tmpdir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
// Create some blocks to fall within the compaction range.
|
// Create some blocks to fall within the compaction range.
|
||||||
createBlock(t, tmpdir, genSeries(1, 10000, 0, 1000))
|
createBlock(t, tmpdir, genSeries(1, 10000, 0, 1000))
|
||||||
|
@ -1188,7 +1167,7 @@ func TestCancelCompactions(t *testing.T) {
|
||||||
|
|
||||||
// Copy the db so we have an exact copy to compare compaction times.
|
// Copy the db so we have an exact copy to compare compaction times.
|
||||||
tmpdirCopy := tmpdir + "Copy"
|
tmpdirCopy := tmpdir + "Copy"
|
||||||
err = fileutil.CopyDirs(tmpdir, tmpdirCopy)
|
err := fileutil.CopyDirs(tmpdir, tmpdirCopy)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer func() {
|
defer func() {
|
||||||
require.NoError(t, os.RemoveAll(tmpdirCopy))
|
require.NoError(t, os.RemoveAll(tmpdirCopy))
|
||||||
|
|
153
tsdb/db_test.go
153
tsdb/db_test.go
|
@ -64,8 +64,8 @@ func TestMain(m *testing.M) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func openTestDB(t testing.TB, opts *Options, rngs []int64) (db *DB) {
|
func openTestDB(t testing.TB, opts *Options, rngs []int64) (db *DB) {
|
||||||
tmpdir, err := ioutil.TempDir("", "test")
|
tmpdir := t.TempDir()
|
||||||
require.NoError(t, err)
|
var err error
|
||||||
|
|
||||||
if len(rngs) == 0 {
|
if len(rngs) == 0 {
|
||||||
db, err = Open(tmpdir, nil, nil, opts, nil)
|
db, err = Open(tmpdir, nil, nil, opts, nil)
|
||||||
|
@ -76,9 +76,6 @@ func openTestDB(t testing.TB, opts *Options, rngs []int64) (db *DB) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Do not Close() the test database by default as it will deadlock on test failures.
|
// Do not Close() the test database by default as it will deadlock on test failures.
|
||||||
t.Cleanup(func() {
|
|
||||||
require.NoError(t, os.RemoveAll(tmpdir))
|
|
||||||
})
|
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -573,17 +570,12 @@ func TestDB_Snapshot(t *testing.T) {
|
||||||
require.NoError(t, app.Commit())
|
require.NoError(t, app.Commit())
|
||||||
|
|
||||||
// create snapshot
|
// create snapshot
|
||||||
snap, err := ioutil.TempDir("", "snap")
|
snap := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(snap))
|
|
||||||
}()
|
|
||||||
require.NoError(t, db.Snapshot(snap, true))
|
require.NoError(t, db.Snapshot(snap, true))
|
||||||
require.NoError(t, db.Close())
|
require.NoError(t, db.Close())
|
||||||
|
|
||||||
// reopen DB from snapshot
|
// reopen DB from snapshot
|
||||||
db, err = Open(snap, nil, nil, nil, nil)
|
db, err := Open(snap, nil, nil, nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer func() { require.NoError(t, db.Close()) }()
|
defer func() { require.NoError(t, db.Close()) }()
|
||||||
|
|
||||||
|
@ -622,20 +614,16 @@ func TestDB_Snapshot_ChunksOutsideOfCompactedRange(t *testing.T) {
|
||||||
}
|
}
|
||||||
require.NoError(t, app.Commit())
|
require.NoError(t, app.Commit())
|
||||||
|
|
||||||
snap, err := ioutil.TempDir("", "snap")
|
snap := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Hackingly introduce "race", by having lower max time then maxTime in last chunk.
|
// Hackingly introduce "race", by having lower max time then maxTime in last chunk.
|
||||||
db.head.maxTime.Sub(10)
|
db.head.maxTime.Sub(10)
|
||||||
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(snap))
|
|
||||||
}()
|
|
||||||
require.NoError(t, db.Snapshot(snap, true))
|
require.NoError(t, db.Snapshot(snap, true))
|
||||||
require.NoError(t, db.Close())
|
require.NoError(t, db.Close())
|
||||||
|
|
||||||
// Reopen DB from snapshot.
|
// Reopen DB from snapshot.
|
||||||
db, err = Open(snap, nil, nil, nil, nil)
|
db, err := Open(snap, nil, nil, nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer func() { require.NoError(t, db.Close()) }()
|
defer func() { require.NoError(t, db.Close()) }()
|
||||||
|
|
||||||
|
@ -696,12 +684,8 @@ Outer:
|
||||||
}
|
}
|
||||||
|
|
||||||
// create snapshot
|
// create snapshot
|
||||||
snap, err := ioutil.TempDir("", "snap")
|
snap := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(snap))
|
|
||||||
}()
|
|
||||||
require.NoError(t, db.Snapshot(snap, true))
|
require.NoError(t, db.Snapshot(snap, true))
|
||||||
|
|
||||||
// reopen DB from snapshot
|
// reopen DB from snapshot
|
||||||
|
@ -1124,17 +1108,12 @@ func TestTombstoneClean(t *testing.T) {
|
||||||
// Delete the ranges.
|
// Delete the ranges.
|
||||||
|
|
||||||
// Create snapshot.
|
// Create snapshot.
|
||||||
snap, err := ioutil.TempDir("", "snap")
|
snap := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(snap))
|
|
||||||
}()
|
|
||||||
require.NoError(t, db.Snapshot(snap, true))
|
require.NoError(t, db.Snapshot(snap, true))
|
||||||
require.NoError(t, db.Close())
|
require.NoError(t, db.Close())
|
||||||
|
|
||||||
// Reopen DB from snapshot.
|
// Reopen DB from snapshot.
|
||||||
db, err = Open(snap, nil, nil, nil, nil)
|
db, err := Open(snap, nil, nil, nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
|
@ -1213,17 +1192,12 @@ func TestTombstoneCleanResultEmptyBlock(t *testing.T) {
|
||||||
intervals := tombstones.Intervals{{Mint: 0, Maxt: numSamples}}
|
intervals := tombstones.Intervals{{Mint: 0, Maxt: numSamples}}
|
||||||
|
|
||||||
// Create snapshot.
|
// Create snapshot.
|
||||||
snap, err := ioutil.TempDir("", "snap")
|
snap := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(snap))
|
|
||||||
}()
|
|
||||||
require.NoError(t, db.Snapshot(snap, true))
|
require.NoError(t, db.Snapshot(snap, true))
|
||||||
require.NoError(t, db.Close())
|
require.NoError(t, db.Close())
|
||||||
|
|
||||||
// Reopen DB from snapshot.
|
// Reopen DB from snapshot.
|
||||||
db, err = Open(snap, nil, nil, nil, nil)
|
db, err := Open(snap, nil, nil, nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
|
@ -1847,11 +1821,7 @@ func TestQuerierWithBoundaryChunks(t *testing.T) {
|
||||||
// - with blocks with WAL: same as above
|
// - with blocks with WAL: same as above
|
||||||
func TestInitializeHeadTimestamp(t *testing.T) {
|
func TestInitializeHeadTimestamp(t *testing.T) {
|
||||||
t.Run("clean", func(t *testing.T) {
|
t.Run("clean", func(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test_head_init")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
db, err := Open(dir, nil, nil, nil, nil)
|
db, err := Open(dir, nil, nil, nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -1871,11 +1841,7 @@ func TestInitializeHeadTimestamp(t *testing.T) {
|
||||||
require.Equal(t, int64(1000), db.head.MaxTime())
|
require.Equal(t, int64(1000), db.head.MaxTime())
|
||||||
})
|
})
|
||||||
t.Run("wal-only", func(t *testing.T) {
|
t.Run("wal-only", func(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test_head_init")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
require.NoError(t, os.MkdirAll(path.Join(dir, "wal"), 0o777))
|
require.NoError(t, os.MkdirAll(path.Join(dir, "wal"), 0o777))
|
||||||
w, err := wal.New(nil, nil, path.Join(dir, "wal"), false)
|
w, err := wal.New(nil, nil, path.Join(dir, "wal"), false)
|
||||||
|
@ -1903,11 +1869,7 @@ func TestInitializeHeadTimestamp(t *testing.T) {
|
||||||
require.Equal(t, int64(15000), db.head.MaxTime())
|
require.Equal(t, int64(15000), db.head.MaxTime())
|
||||||
})
|
})
|
||||||
t.Run("existing-block", func(t *testing.T) {
|
t.Run("existing-block", func(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test_head_init")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
createBlock(t, dir, genSeries(1, 1, 1000, 2000))
|
createBlock(t, dir, genSeries(1, 1, 1000, 2000))
|
||||||
|
|
||||||
|
@ -1919,11 +1881,7 @@ func TestInitializeHeadTimestamp(t *testing.T) {
|
||||||
require.Equal(t, int64(2000), db.head.MaxTime())
|
require.Equal(t, int64(2000), db.head.MaxTime())
|
||||||
})
|
})
|
||||||
t.Run("existing-block-and-wal", func(t *testing.T) {
|
t.Run("existing-block-and-wal", func(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test_head_init")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
createBlock(t, dir, genSeries(1, 1, 1000, 6000))
|
createBlock(t, dir, genSeries(1, 1, 1000, 6000))
|
||||||
|
|
||||||
|
@ -2214,8 +2172,7 @@ func TestBlockRanges(t *testing.T) {
|
||||||
logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr))
|
logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr))
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "test_storage")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Test that the compactor doesn't create overlapping blocks
|
// Test that the compactor doesn't create overlapping blocks
|
||||||
// when a non standard block already exists.
|
// when a non standard block already exists.
|
||||||
|
@ -2225,9 +2182,7 @@ func TestBlockRanges(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
rangeToTriggerCompaction := db.compactor.(*LeveledCompactor).ranges[0]/2*3 + 1
|
rangeToTriggerCompaction := db.compactor.(*LeveledCompactor).ranges[0]/2*3 + 1
|
||||||
defer func() {
|
|
||||||
os.RemoveAll(dir)
|
|
||||||
}()
|
|
||||||
app := db.Appender(ctx)
|
app := db.Appender(ctx)
|
||||||
lbl := labels.Labels{{Name: "a", Value: "b"}}
|
lbl := labels.Labels{{Name: "a", Value: "b"}}
|
||||||
_, err = app.Append(0, lbl, firstBlockMaxT-1, rand.Float64())
|
_, err = app.Append(0, lbl, firstBlockMaxT-1, rand.Float64())
|
||||||
|
@ -2314,12 +2269,7 @@ func TestDBReadOnly(t *testing.T) {
|
||||||
|
|
||||||
// Bootstrap the db.
|
// Bootstrap the db.
|
||||||
{
|
{
|
||||||
dbDir, err = ioutil.TempDir("", "test")
|
dbDir = t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dbDir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
dbBlocks := []*BlockMeta{
|
dbBlocks := []*BlockMeta{
|
||||||
// Create three 2-sample blocks.
|
// Create three 2-sample blocks.
|
||||||
|
@ -2408,12 +2358,7 @@ func TestDBReadOnly(t *testing.T) {
|
||||||
// TestDBReadOnlyClosing ensures that after closing the db
|
// TestDBReadOnlyClosing ensures that after closing the db
|
||||||
// all api methods return an ErrClosed.
|
// all api methods return an ErrClosed.
|
||||||
func TestDBReadOnlyClosing(t *testing.T) {
|
func TestDBReadOnlyClosing(t *testing.T) {
|
||||||
dbDir, err := ioutil.TempDir("", "test")
|
dbDir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dbDir))
|
|
||||||
}()
|
|
||||||
db, err := OpenDBReadOnly(dbDir, log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)))
|
db, err := OpenDBReadOnly(dbDir, log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, db.Close())
|
require.NoError(t, db.Close())
|
||||||
|
@ -2435,12 +2380,7 @@ func TestDBReadOnly_FlushWAL(t *testing.T) {
|
||||||
|
|
||||||
// Bootstrap the db.
|
// Bootstrap the db.
|
||||||
{
|
{
|
||||||
dbDir, err = ioutil.TempDir("", "test")
|
dbDir = t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dbDir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
// Append data to the WAL.
|
// Append data to the WAL.
|
||||||
db, err := Open(dbDir, logger, nil, nil, nil)
|
db, err := Open(dbDir, logger, nil, nil, nil)
|
||||||
|
@ -2460,12 +2400,7 @@ func TestDBReadOnly_FlushWAL(t *testing.T) {
|
||||||
db, err := OpenDBReadOnly(dbDir, logger)
|
db, err := OpenDBReadOnly(dbDir, logger)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
flush, err := ioutil.TempDir("", "flush")
|
flush := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(flush))
|
|
||||||
}()
|
|
||||||
require.NoError(t, db.FlushWAL(flush))
|
require.NoError(t, db.FlushWAL(flush))
|
||||||
require.NoError(t, db.Close())
|
require.NoError(t, db.Close())
|
||||||
|
|
||||||
|
@ -2503,10 +2438,7 @@ func TestDBCannotSeePartialCommits(t *testing.T) {
|
||||||
t.Skip("skipping test since tsdb isolation is disabled")
|
t.Skip("skipping test since tsdb isolation is disabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpdir, _ := ioutil.TempDir("", "test")
|
tmpdir := t.TempDir()
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(tmpdir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
db, err := Open(tmpdir, nil, nil, nil, nil)
|
db, err := Open(tmpdir, nil, nil, nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -2577,10 +2509,7 @@ func TestDBQueryDoesntSeeAppendsAfterCreation(t *testing.T) {
|
||||||
t.Skip("skipping test since tsdb isolation is disabled")
|
t.Skip("skipping test since tsdb isolation is disabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpdir, _ := ioutil.TempDir("", "test")
|
tmpdir := t.TempDir()
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(tmpdir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
db, err := Open(tmpdir, nil, nil, nil, nil)
|
db, err := Open(tmpdir, nil, nil, nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -2767,9 +2696,7 @@ func TestChunkWriter_ReadAfterWrite(t *testing.T) {
|
||||||
|
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||||
tempDir, err := ioutil.TempDir("", "test_chunk_writer")
|
tempDir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() { require.NoError(t, os.RemoveAll(tempDir)) }()
|
|
||||||
|
|
||||||
chunkw, err := chunks.NewWriterWithSegSize(tempDir, chunks.SegmentHeaderSize+int64(test.segmentSize))
|
chunkw, err := chunks.NewWriterWithSegSize(tempDir, chunks.SegmentHeaderSize+int64(test.segmentSize))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -2856,9 +2783,7 @@ func TestChunkReader_ConcurrentReads(t *testing.T) {
|
||||||
tsdbutil.ChunkFromSamples([]tsdbutil.Sample{sample{1, 5}}),
|
tsdbutil.ChunkFromSamples([]tsdbutil.Sample{sample{1, 5}}),
|
||||||
}
|
}
|
||||||
|
|
||||||
tempDir, err := ioutil.TempDir("", "test_chunk_writer")
|
tempDir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() { require.NoError(t, os.RemoveAll(tempDir)) }()
|
|
||||||
|
|
||||||
chunkw, err := chunks.NewWriter(tempDir)
|
chunkw, err := chunks.NewWriter(tempDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -2895,9 +2820,7 @@ func TestChunkReader_ConcurrentReads(t *testing.T) {
|
||||||
// * compacts the head; and
|
// * compacts the head; and
|
||||||
// * queries the db to ensure the samples are present from the compacted head.
|
// * queries the db to ensure the samples are present from the compacted head.
|
||||||
func TestCompactHead(t *testing.T) {
|
func TestCompactHead(t *testing.T) {
|
||||||
dbDir, err := ioutil.TempDir("", "testFlush")
|
dbDir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() { require.NoError(t, os.RemoveAll(dbDir)) }()
|
|
||||||
|
|
||||||
// Open a DB and append data to the WAL.
|
// Open a DB and append data to the WAL.
|
||||||
tsdbCfg := &Options{
|
tsdbCfg := &Options{
|
||||||
|
@ -2978,11 +2901,7 @@ func deleteNonBlocks(dbDir string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOpen_VariousBlockStates(t *testing.T) {
|
func TestOpen_VariousBlockStates(t *testing.T) {
|
||||||
tmpDir, err := ioutil.TempDir("", "test")
|
tmpDir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
t.Cleanup(func() {
|
|
||||||
require.NoError(t, os.RemoveAll(tmpDir))
|
|
||||||
})
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
expectedLoadedDirs = map[string]struct{}{}
|
expectedLoadedDirs = map[string]struct{}{}
|
||||||
|
@ -3097,11 +3016,7 @@ func TestOneCheckpointPerCompactCall(t *testing.T) {
|
||||||
MaxBlockDuration: blockRange,
|
MaxBlockDuration: blockRange,
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpDir, err := ioutil.TempDir("", "test")
|
tmpDir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
t.Cleanup(func() {
|
|
||||||
require.NoError(t, os.RemoveAll(tmpDir))
|
|
||||||
})
|
|
||||||
|
|
||||||
db, err := Open(tmpDir, log.NewNopLogger(), prometheus.NewRegistry(), tsdbCfg, nil)
|
db, err := Open(tmpDir, log.NewNopLogger(), prometheus.NewRegistry(), tsdbCfg, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -3210,11 +3125,7 @@ func TestOneCheckpointPerCompactCall(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNoPanicOnTSDBOpenError(t *testing.T) {
|
func TestNoPanicOnTSDBOpenError(t *testing.T) {
|
||||||
tmpdir, err := ioutil.TempDir("", "test")
|
tmpdir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
t.Cleanup(func() {
|
|
||||||
require.NoError(t, os.RemoveAll(tmpdir))
|
|
||||||
})
|
|
||||||
|
|
||||||
// Taking the lock will cause a TSDB startup error.
|
// Taking the lock will cause a TSDB startup error.
|
||||||
l, err := tsdbutil.NewDirLocker(tmpdir, "tsdb", log.NewNopLogger(), nil)
|
l, err := tsdbutil.NewDirLocker(tmpdir, "tsdb", log.NewNopLogger(), nil)
|
||||||
|
@ -3499,11 +3410,7 @@ func testChunkQuerierShouldNotPanicIfHeadChunkIsTruncatedWhileReadingQueriedChun
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestDB(t *testing.T) *DB {
|
func newTestDB(t *testing.T) *DB {
|
||||||
dir, err := ioutil.TempDir("", "test")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
t.Cleanup(func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
})
|
|
||||||
|
|
||||||
db, err := Open(dir, nil, nil, DefaultOptions(), nil)
|
db, err := Open(dir, nil, nil, DefaultOptions(), nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -14,8 +14,6 @@
|
||||||
package tsdb
|
package tsdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -27,11 +25,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkHeadStripeSeriesCreate(b *testing.B) {
|
func BenchmarkHeadStripeSeriesCreate(b *testing.B) {
|
||||||
chunkDir, err := ioutil.TempDir("", "chunk_dir")
|
chunkDir := b.TempDir()
|
||||||
require.NoError(b, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(b, os.RemoveAll(chunkDir))
|
|
||||||
}()
|
|
||||||
// Put a series, select it. GC it and then access it.
|
// Put a series, select it. GC it and then access it.
|
||||||
opts := DefaultHeadOptions()
|
opts := DefaultHeadOptions()
|
||||||
opts.ChunkRange = 1000
|
opts.ChunkRange = 1000
|
||||||
|
@ -46,11 +40,7 @@ func BenchmarkHeadStripeSeriesCreate(b *testing.B) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkHeadStripeSeriesCreateParallel(b *testing.B) {
|
func BenchmarkHeadStripeSeriesCreateParallel(b *testing.B) {
|
||||||
chunkDir, err := ioutil.TempDir("", "chunk_dir")
|
chunkDir := b.TempDir()
|
||||||
require.NoError(b, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(b, os.RemoveAll(chunkDir))
|
|
||||||
}()
|
|
||||||
// Put a series, select it. GC it and then access it.
|
// Put a series, select it. GC it and then access it.
|
||||||
opts := DefaultHeadOptions()
|
opts := DefaultHeadOptions()
|
||||||
opts.ChunkRange = 1000
|
opts.ChunkRange = 1000
|
||||||
|
@ -70,11 +60,7 @@ func BenchmarkHeadStripeSeriesCreateParallel(b *testing.B) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkHeadStripeSeriesCreate_PreCreationFailure(b *testing.B) {
|
func BenchmarkHeadStripeSeriesCreate_PreCreationFailure(b *testing.B) {
|
||||||
chunkDir, err := ioutil.TempDir("", "chunk_dir")
|
chunkDir := b.TempDir()
|
||||||
require.NoError(b, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(b, os.RemoveAll(chunkDir))
|
|
||||||
}()
|
|
||||||
// Put a series, select it. GC it and then access it.
|
// Put a series, select it. GC it and then access it.
|
||||||
opts := DefaultHeadOptions()
|
opts := DefaultHeadOptions()
|
||||||
opts.ChunkRange = 1000
|
opts.ChunkRange = 1000
|
||||||
|
|
|
@ -51,8 +51,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func newTestHead(t testing.TB, chunkRange int64, compressWAL bool) (*Head, *wal.WAL) {
|
func newTestHead(t testing.TB, chunkRange int64, compressWAL bool) (*Head, *wal.WAL) {
|
||||||
dir, err := ioutil.TempDir("", "test")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
wlog, err := wal.NewSize(nil, nil, filepath.Join(dir, "wal"), 32768, compressWAL)
|
wlog, err := wal.NewSize(nil, nil, filepath.Join(dir, "wal"), 32768, compressWAL)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -67,9 +66,6 @@ func newTestHead(t testing.TB, chunkRange int64, compressWAL bool) (*Head, *wal.
|
||||||
|
|
||||||
require.NoError(t, h.chunkDiskMapper.IterateAllChunks(func(_ chunks.HeadSeriesRef, _ chunks.ChunkDiskMapperRef, _, _ int64, _ uint16) error { return nil }))
|
require.NoError(t, h.chunkDiskMapper.IterateAllChunks(func(_ chunks.HeadSeriesRef, _ chunks.ChunkDiskMapperRef, _, _ int64, _ uint16) error { return nil }))
|
||||||
|
|
||||||
t.Cleanup(func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
})
|
|
||||||
return h, wlog
|
return h, wlog
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,11 +179,7 @@ func BenchmarkLoadWAL(b *testing.B) {
|
||||||
// fmt.Println("exemplars per series: ", exemplarsPerSeries)
|
// fmt.Println("exemplars per series: ", exemplarsPerSeries)
|
||||||
b.Run(fmt.Sprintf("batches=%d,seriesPerBatch=%d,samplesPerSeries=%d,exemplarsPerSeries=%d,mmappedChunkT=%d", c.batches, c.seriesPerBatch, c.samplesPerSeries, exemplarsPerSeries, c.mmappedChunkT),
|
b.Run(fmt.Sprintf("batches=%d,seriesPerBatch=%d,samplesPerSeries=%d,exemplarsPerSeries=%d,mmappedChunkT=%d", c.batches, c.seriesPerBatch, c.samplesPerSeries, exemplarsPerSeries, c.mmappedChunkT),
|
||||||
func(b *testing.B) {
|
func(b *testing.B) {
|
||||||
dir, err := ioutil.TempDir("", "test_load_wal")
|
dir := b.TempDir()
|
||||||
require.NoError(b, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(b, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
w, err := wal.New(nil, nil, dir, false)
|
w, err := wal.New(nil, nil, dir, false)
|
||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
|
@ -724,11 +716,7 @@ func TestHead_Truncate(t *testing.T) {
|
||||||
// Validate various behaviors brought on by firstChunkID accounting for
|
// Validate various behaviors brought on by firstChunkID accounting for
|
||||||
// garbage collected chunks.
|
// garbage collected chunks.
|
||||||
func TestMemSeries_truncateChunks(t *testing.T) {
|
func TestMemSeries_truncateChunks(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "truncate_chunks")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
// This is usually taken from the Head, but passing manually here.
|
// This is usually taken from the Head, but passing manually here.
|
||||||
chunkDiskMapper, err := chunks.NewChunkDiskMapper(nil, dir, chunkenc.NewPool(), chunks.DefaultWriteBufferSize, chunks.DefaultWriteQueueSize)
|
chunkDiskMapper, err := chunks.NewChunkDiskMapper(nil, dir, chunkenc.NewPool(), chunks.DefaultWriteBufferSize, chunks.DefaultWriteQueueSize)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -1268,11 +1256,7 @@ func TestComputeChunkEndTime(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMemSeries_append(t *testing.T) {
|
func TestMemSeries_append(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "append")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
// This is usually taken from the Head, but passing manually here.
|
// This is usually taken from the Head, but passing manually here.
|
||||||
chunkDiskMapper, err := chunks.NewChunkDiskMapper(nil, dir, chunkenc.NewPool(), chunks.DefaultWriteBufferSize, chunks.DefaultWriteQueueSize)
|
chunkDiskMapper, err := chunks.NewChunkDiskMapper(nil, dir, chunkenc.NewPool(), chunks.DefaultWriteBufferSize, chunks.DefaultWriteQueueSize)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -1556,11 +1540,7 @@ func TestWalRepair_DecodingError(t *testing.T) {
|
||||||
} {
|
} {
|
||||||
for _, compress := range []bool{false, true} {
|
for _, compress := range []bool{false, true} {
|
||||||
t.Run(fmt.Sprintf("%s,compress=%t", name, compress), func(t *testing.T) {
|
t.Run(fmt.Sprintf("%s,compress=%t", name, compress), func(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "wal_repair")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
// Fill the wal and corrupt it.
|
// Fill the wal and corrupt it.
|
||||||
{
|
{
|
||||||
|
@ -1620,11 +1600,7 @@ func TestWalRepair_DecodingError(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHeadReadWriterRepair(t *testing.T) {
|
func TestHeadReadWriterRepair(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "head_read_writer_repair")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
const chunkRange = 1000
|
const chunkRange = 1000
|
||||||
|
|
||||||
|
@ -2030,11 +2006,7 @@ func TestIsolationWithoutAdd(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOutOfOrderSamplesMetric(t *testing.T) {
|
func TestOutOfOrderSamplesMetric(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
db, err := Open(dir, nil, nil, DefaultOptions(), nil)
|
db, err := Open(dir, nil, nil, DefaultOptions(), nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -2456,11 +2428,7 @@ func BenchmarkHeadLabelValuesWithMatchers(b *testing.B) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMemSafeIteratorSeekIntoBuffer(t *testing.T) {
|
func TestMemSafeIteratorSeekIntoBuffer(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "iterator_seek")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
// This is usually taken from the Head, but passing manually here.
|
// This is usually taken from the Head, but passing manually here.
|
||||||
chunkDiskMapper, err := chunks.NewChunkDiskMapper(nil, dir, chunkenc.NewPool(), chunks.DefaultWriteBufferSize, chunks.DefaultWriteQueueSize)
|
chunkDiskMapper, err := chunks.NewChunkDiskMapper(nil, dir, chunkenc.NewPool(), chunks.DefaultWriteBufferSize, chunks.DefaultWriteQueueSize)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -137,11 +137,7 @@ func (m mockIndex) Series(ref storage.SeriesRef, lset *labels.Labels, chks *[]ch
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIndexRW_Create_Open(t *testing.T) {
|
func TestIndexRW_Create_Open(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test_index_create")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
fn := filepath.Join(dir, indexFilename)
|
fn := filepath.Join(dir, indexFilename)
|
||||||
|
|
||||||
|
@ -166,11 +162,7 @@ func TestIndexRW_Create_Open(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIndexRW_Postings(t *testing.T) {
|
func TestIndexRW_Postings(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test_index_postings")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
fn := filepath.Join(dir, indexFilename)
|
fn := filepath.Join(dir, indexFilename)
|
||||||
|
|
||||||
|
@ -250,11 +242,7 @@ func TestIndexRW_Postings(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPostingsMany(t *testing.T) {
|
func TestPostingsMany(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test_postings_many")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
fn := filepath.Join(dir, indexFilename)
|
fn := filepath.Join(dir, indexFilename)
|
||||||
|
|
||||||
|
@ -344,11 +332,7 @@ func TestPostingsMany(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPersistence_index_e2e(t *testing.T) {
|
func TestPersistence_index_e2e(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test_persistence_e2e")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
lbls, err := labels.ReadLabels(filepath.Join("..", "testdata", "20kseries.json"), 20000)
|
lbls, err := labels.ReadLabels(filepath.Join("..", "testdata", "20kseries.json"), 20000)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -16,8 +16,6 @@ package tsdb
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -32,11 +30,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkQuerier(b *testing.B) {
|
func BenchmarkQuerier(b *testing.B) {
|
||||||
chunkDir, err := ioutil.TempDir("", "chunk_dir")
|
chunkDir := b.TempDir()
|
||||||
require.NoError(b, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(b, os.RemoveAll(chunkDir))
|
|
||||||
}()
|
|
||||||
opts := DefaultHeadOptions()
|
opts := DefaultHeadOptions()
|
||||||
opts.ChunkRange = 1000
|
opts.ChunkRange = 1000
|
||||||
opts.ChunkDirRoot = chunkDir
|
opts.ChunkDirRoot = chunkDir
|
||||||
|
@ -74,11 +68,7 @@ func BenchmarkQuerier(b *testing.B) {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
tmpdir, err := ioutil.TempDir("", "test_benchpostingsformatchers")
|
tmpdir := b.TempDir()
|
||||||
require.NoError(b, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(b, os.RemoveAll(tmpdir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
blockdir := createBlockFromHead(b, tmpdir, h)
|
blockdir := createBlockFromHead(b, tmpdir, h)
|
||||||
block, err := OpenBlock(nil, blockdir, nil)
|
block, err := OpenBlock(nil, blockdir, nil)
|
||||||
|
@ -186,11 +176,7 @@ func benchmarkLabelValuesWithMatchers(b *testing.B, ir IndexReader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkQuerierSelect(b *testing.B) {
|
func BenchmarkQuerierSelect(b *testing.B) {
|
||||||
chunkDir, err := ioutil.TempDir("", "chunk_dir")
|
chunkDir := b.TempDir()
|
||||||
require.NoError(b, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(b, os.RemoveAll(chunkDir))
|
|
||||||
}()
|
|
||||||
opts := DefaultHeadOptions()
|
opts := DefaultHeadOptions()
|
||||||
opts.ChunkRange = 1000
|
opts.ChunkRange = 1000
|
||||||
opts.ChunkDirRoot = chunkDir
|
opts.ChunkDirRoot = chunkDir
|
||||||
|
@ -230,11 +216,7 @@ func BenchmarkQuerierSelect(b *testing.B) {
|
||||||
bench(b, h, true)
|
bench(b, h, true)
|
||||||
})
|
})
|
||||||
|
|
||||||
tmpdir, err := ioutil.TempDir("", "test_benchquerierselect")
|
tmpdir := b.TempDir()
|
||||||
require.NoError(b, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(b, os.RemoveAll(tmpdir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
blockdir := createBlockFromHead(b, tmpdir, h)
|
blockdir := createBlockFromHead(b, tmpdir, h)
|
||||||
block, err := OpenBlock(nil, blockdir, nil)
|
block, err := OpenBlock(nil, blockdir, nil)
|
||||||
|
|
|
@ -16,10 +16,8 @@ package tsdb
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -1329,11 +1327,7 @@ func BenchmarkQueryIterator(b *testing.B) {
|
||||||
c.numBlocks, c.numSeries, c.numSamplesPerSeriesPerBlock, overlapPercentage)
|
c.numBlocks, c.numSeries, c.numSamplesPerSeriesPerBlock, overlapPercentage)
|
||||||
|
|
||||||
b.Run(benchMsg, func(b *testing.B) {
|
b.Run(benchMsg, func(b *testing.B) {
|
||||||
dir, err := ioutil.TempDir("", "bench_query_iterator")
|
dir := b.TempDir()
|
||||||
require.NoError(b, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(b, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
blocks []*Block
|
blocks []*Block
|
||||||
|
@ -1396,11 +1390,7 @@ func BenchmarkQuerySeek(b *testing.B) {
|
||||||
c.numBlocks, c.numSeries, c.numSamplesPerSeriesPerBlock, overlapPercentage)
|
c.numBlocks, c.numSeries, c.numSamplesPerSeriesPerBlock, overlapPercentage)
|
||||||
|
|
||||||
b.Run(benchMsg, func(b *testing.B) {
|
b.Run(benchMsg, func(b *testing.B) {
|
||||||
dir, err := ioutil.TempDir("", "bench_query_iterator")
|
dir := b.TempDir()
|
||||||
require.NoError(b, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(b, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
blocks []*Block
|
blocks []*Block
|
||||||
|
@ -1451,7 +1441,6 @@ func BenchmarkQuerySeek(b *testing.B) {
|
||||||
require.NoError(b, it.Err())
|
require.NoError(b, it.Err())
|
||||||
}
|
}
|
||||||
require.NoError(b, ss.Err())
|
require.NoError(b, ss.Err())
|
||||||
require.NoError(b, err)
|
|
||||||
require.Equal(b, 0, len(ss.Warnings()))
|
require.Equal(b, 0, len(ss.Warnings()))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1537,11 +1526,7 @@ func BenchmarkSetMatcher(b *testing.B) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
dir, err := ioutil.TempDir("", "bench_postings_for_matchers")
|
dir := b.TempDir()
|
||||||
require.NoError(b, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(b, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
blocks []*Block
|
blocks []*Block
|
||||||
|
@ -1654,11 +1639,7 @@ func TestFindSetMatches(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPostingsForMatchers(t *testing.T) {
|
func TestPostingsForMatchers(t *testing.T) {
|
||||||
chunkDir, err := ioutil.TempDir("", "chunk_dir")
|
chunkDir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(chunkDir))
|
|
||||||
}()
|
|
||||||
opts := DefaultHeadOptions()
|
opts := DefaultHeadOptions()
|
||||||
opts.ChunkRange = 1000
|
opts.ChunkRange = 1000
|
||||||
opts.ChunkDirRoot = chunkDir
|
opts.ChunkDirRoot = chunkDir
|
||||||
|
@ -1915,13 +1896,7 @@ func TestPostingsForMatchers(t *testing.T) {
|
||||||
|
|
||||||
// TestClose ensures that calling Close more than once doesn't block and doesn't panic.
|
// TestClose ensures that calling Close more than once doesn't block and doesn't panic.
|
||||||
func TestClose(t *testing.T) {
|
func TestClose(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test_storage")
|
dir := t.TempDir()
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Opening test dir failed: %s", err)
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
createBlock(t, dir, genSeries(1, 1, 0, 10))
|
createBlock(t, dir, genSeries(1, 1, 0, 10))
|
||||||
createBlock(t, dir, genSeries(1, 1, 10, 20))
|
createBlock(t, dir, genSeries(1, 1, 10, 20))
|
||||||
|
@ -1982,11 +1957,7 @@ func BenchmarkQueries(b *testing.B) {
|
||||||
for title, selectors := range cases {
|
for title, selectors := range cases {
|
||||||
for _, nSeries := range []int{10} {
|
for _, nSeries := range []int{10} {
|
||||||
for _, nSamples := range []int64{1000, 10000, 100000} {
|
for _, nSamples := range []int64{1000, 10000, 100000} {
|
||||||
dir, err := ioutil.TempDir("", "test_persisted_query")
|
dir := b.TempDir()
|
||||||
require.NoError(b, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(b, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
series := genSeries(nSeries, 5, 1, nSamples)
|
series := genSeries(nSeries, 5, 1, nSamples)
|
||||||
|
|
||||||
|
@ -2024,11 +1995,7 @@ func BenchmarkQueries(b *testing.B) {
|
||||||
queryTypes["_3-Blocks"] = storage.NewMergeQuerier(qs[0:3], nil, storage.ChainedSeriesMerge)
|
queryTypes["_3-Blocks"] = storage.NewMergeQuerier(qs[0:3], nil, storage.ChainedSeriesMerge)
|
||||||
queryTypes["_10-Blocks"] = storage.NewMergeQuerier(qs, nil, storage.ChainedSeriesMerge)
|
queryTypes["_10-Blocks"] = storage.NewMergeQuerier(qs, nil, storage.ChainedSeriesMerge)
|
||||||
|
|
||||||
chunkDir, err := ioutil.TempDir("", "chunk_dir")
|
chunkDir := b.TempDir()
|
||||||
require.NoError(b, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(b, os.RemoveAll(chunkDir))
|
|
||||||
}()
|
|
||||||
head := createHead(b, nil, series, chunkDir)
|
head := createHead(b, nil, series, chunkDir)
|
||||||
qHead, err := NewBlockQuerier(head, 1, nSamples)
|
qHead, err := NewBlockQuerier(head, 1, nSamples)
|
||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
package tsdb
|
package tsdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -28,11 +27,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRepairBadIndexVersion(t *testing.T) {
|
func TestRepairBadIndexVersion(t *testing.T) {
|
||||||
tmpDir, err := ioutil.TempDir("", "test")
|
tmpDir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
t.Cleanup(func() {
|
|
||||||
require.NoError(t, os.RemoveAll(tmpDir))
|
|
||||||
})
|
|
||||||
|
|
||||||
// The broken index used in this test was written by the following script
|
// The broken index used in this test was written by the following script
|
||||||
// at a broken revision.
|
// at a broken revision.
|
||||||
|
@ -74,7 +69,7 @@ func TestRepairBadIndexVersion(t *testing.T) {
|
||||||
|
|
||||||
// Check the current db.
|
// Check the current db.
|
||||||
// In its current state, lookups should fail with the fixed code.
|
// In its current state, lookups should fail with the fixed code.
|
||||||
_, _, err = readMetaFile(tmpDbDir)
|
_, _, err := readMetaFile(tmpDbDir)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
// Touch chunks dir in block to imitate them.
|
// Touch chunks dir in block to imitate them.
|
||||||
|
|
|
@ -14,10 +14,8 @@
|
||||||
package tombstones
|
package tombstones
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -34,10 +32,7 @@ func TestMain(m *testing.M) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWriteAndReadbackTombstones(t *testing.T) {
|
func TestWriteAndReadbackTombstones(t *testing.T) {
|
||||||
tmpdir, _ := ioutil.TempDir("", "test")
|
tmpdir := t.TempDir()
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(tmpdir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
ref := uint64(0)
|
ref := uint64(0)
|
||||||
|
|
||||||
|
|
|
@ -39,11 +39,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSegmentWAL_cut(t *testing.T) {
|
func TestSegmentWAL_cut(t *testing.T) {
|
||||||
tmpdir, err := ioutil.TempDir("", "test_wal_cut")
|
tmpdir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(tmpdir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
// This calls cut() implicitly the first time without a previous tail.
|
// This calls cut() implicitly the first time without a previous tail.
|
||||||
w, err := OpenSegmentWAL(tmpdir, nil, 0, nil)
|
w, err := OpenSegmentWAL(tmpdir, nil, 0, nil)
|
||||||
|
@ -89,11 +85,7 @@ func TestSegmentWAL_Truncate(t *testing.T) {
|
||||||
series, err := labels.ReadLabels(filepath.Join("testdata", "20kseries.json"), numMetrics)
|
series, err := labels.ReadLabels(filepath.Join("testdata", "20kseries.json"), numMetrics)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "test_wal_log_truncate")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
w, err := OpenSegmentWAL(dir, nil, 0, nil)
|
w, err := OpenSegmentWAL(dir, nil, 0, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -172,11 +164,7 @@ func TestSegmentWAL_Log_Restore(t *testing.T) {
|
||||||
series, err := labels.ReadLabels(filepath.Join("testdata", "20kseries.json"), numMetrics)
|
series, err := labels.ReadLabels(filepath.Join("testdata", "20kseries.json"), numMetrics)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "test_wal_log_restore")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
recordedSeries [][]record.RefSeries
|
recordedSeries [][]record.RefSeries
|
||||||
|
@ -281,11 +269,7 @@ func TestSegmentWAL_Log_Restore(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWALRestoreCorrupted_invalidSegment(t *testing.T) {
|
func TestWALRestoreCorrupted_invalidSegment(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "test_wal_log_restore")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
wal, err := OpenSegmentWAL(dir, nil, 0, nil)
|
wal, err := OpenSegmentWAL(dir, nil, 0, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -386,11 +370,7 @@ func TestWALRestoreCorrupted(t *testing.T) {
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
// Generate testing data. It does not make semantic sense but
|
// Generate testing data. It does not make semantic sense but
|
||||||
// for the purpose of this test.
|
// for the purpose of this test.
|
||||||
dir, err := ioutil.TempDir("", "test_corrupted")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
w, err := OpenSegmentWAL(dir, nil, 0, nil)
|
w, err := OpenSegmentWAL(dir, nil, 0, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -466,11 +446,7 @@ func TestWALRestoreCorrupted(t *testing.T) {
|
||||||
func TestMigrateWAL_Empty(t *testing.T) {
|
func TestMigrateWAL_Empty(t *testing.T) {
|
||||||
// The migration procedure must properly deal with a zero-length segment,
|
// The migration procedure must properly deal with a zero-length segment,
|
||||||
// which is valid in the new format.
|
// which is valid in the new format.
|
||||||
dir, err := ioutil.TempDir("", "walmigrate")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
wdir := path.Join(dir, "wal")
|
wdir := path.Join(dir, "wal")
|
||||||
|
|
||||||
|
@ -483,11 +459,7 @@ func TestMigrateWAL_Empty(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMigrateWAL_Fuzz(t *testing.T) {
|
func TestMigrateWAL_Fuzz(t *testing.T) {
|
||||||
dir, err := ioutil.TempDir("", "walmigrate")
|
dir := t.TempDir()
|
||||||
require.NoError(t, err)
|
|
||||||
defer func() {
|
|
||||||
require.NoError(t, os.RemoveAll(dir))
|
|
||||||
}()
|
|
||||||
|
|
||||||
wdir := path.Join(dir, "wal")
|
wdir := path.Join(dir, "wal")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue