mirror of
https://github.com/prometheus/prometheus.git
synced 2026-04-15 22:09:39 -04:00
fix: remove metadata write and debug test
Signed-off-by: x1unix <9203548+x1unix@users.noreply.github.com>
This commit is contained in:
parent
f604552de1
commit
dbf0b3dff8
1 changed files with 73 additions and 21 deletions
|
|
@ -23,6 +23,71 @@ import (
|
|||
"github.com/prometheus/prometheus/tsdb/wlog"
|
||||
)
|
||||
|
||||
func TestBenchCheckpoint(b *testing.T) {
|
||||
// Prepare in advance samples and labels that will be written into appender.
|
||||
samples := genCheckpointTestSamples(checkpointTestSamplesParams{
|
||||
labelPrefix: b.Name(),
|
||||
numDatapoints: 1000,
|
||||
numHistograms: 100,
|
||||
numSeries: 360,
|
||||
})
|
||||
|
||||
// Prepare initial wlog state with segments.
|
||||
testSamplesSrcDir := filepath.Join(b.TempDir(), "samples-src")
|
||||
require.NoError(b, os.Mkdir(testSamplesSrcDir, os.ModePerm))
|
||||
createCheckpointFixtures(b, checkpointFixtureParams{
|
||||
dir: testSamplesSrcDir,
|
||||
numSegments: 512,
|
||||
dtDelta: 10000,
|
||||
segmentSize: 32 << 10, // must be aligned to the page size
|
||||
seriesLabels: samples.datapointLabels,
|
||||
})
|
||||
|
||||
// Check what checkpoint implementation to use from a feature flag.
|
||||
checkpointImpl := os.Getenv("TEST_CHECKPOINT_IMPL")
|
||||
// isNewCheckpointEnabled := checkpointImpl != "wlog"
|
||||
isNewCheckpointEnabled := checkpointImpl == "wlog"
|
||||
|
||||
// Run the bench.
|
||||
fn := func(b *testing.T) {
|
||||
// Copy initial wlog state into a scratch directory for test.
|
||||
// wlog.Open expects to have a "wal" subdirectory
|
||||
wlogDir := filepath.Join(b.TempDir(), "testdata", "wal")
|
||||
b.Log("WlogDir: ", wlogDir)
|
||||
err := os.CopyFS(wlogDir, os.DirFS(testSamplesSrcDir))
|
||||
require.NoErrorf(b, err, "failed to copy test samples from %q to %q", testSamplesSrcDir, wlogDir)
|
||||
storageDir := filepath.Dir(wlogDir)
|
||||
|
||||
// b.ReportAllocs()
|
||||
// b.ResetTimer()
|
||||
|
||||
benchCheckpoint(b, benchCheckpointParams{
|
||||
storageDir: storageDir,
|
||||
samples: samples,
|
||||
skipCurrentCheckpointReRead: isNewCheckpointEnabled,
|
||||
})
|
||||
|
||||
b.Log("=== STORE DATA ===")
|
||||
b.Log("Dir: ", storageDir)
|
||||
entries, err := os.ReadDir(storageDir)
|
||||
require.NoError(b, err)
|
||||
|
||||
for _, entry := range entries {
|
||||
filePath := filepath.Join(wlogDir, entry.Name())
|
||||
if entry.IsDir() {
|
||||
b.Log("[D] ", filePath)
|
||||
continue
|
||||
}
|
||||
|
||||
fileInfo, err := os.Stat(filePath)
|
||||
require.NoError(b, err)
|
||||
b.Logf("[F] %s (Size: %d bytes)", entry.Name(), fileInfo.Size())
|
||||
}
|
||||
b.Log("END")
|
||||
}
|
||||
fn(b)
|
||||
}
|
||||
|
||||
// func TestBenchmarkCheckpoint(b *testing.T) {
|
||||
func BenchmarkCheckpoint(b *testing.B) {
|
||||
// Prepare in advance samples and labels that will be written into appender.
|
||||
|
|
@ -52,7 +117,7 @@ func BenchmarkCheckpoint(b *testing.B) {
|
|||
b.Run("checkpoint", func(b *testing.B) {
|
||||
// Copy initial wlog state into a scratch directory for test.
|
||||
// wlog.Open expects to have a "wal" subdirectory
|
||||
wlogDir := filepath.Join(b.TempDir(), "testdata", "wlog")
|
||||
wlogDir := filepath.Join(b.TempDir(), "testdata", "wal")
|
||||
err := os.CopyFS(wlogDir, os.DirFS(testSamplesSrcDir))
|
||||
require.NoErrorf(b, err, "failed to copy test samples from %q to %q", testSamplesSrcDir, wlogDir)
|
||||
storageDir := filepath.Dir(wlogDir)
|
||||
|
|
@ -76,7 +141,7 @@ type benchCheckpointParams struct {
|
|||
samples checkpointTestSamples
|
||||
}
|
||||
|
||||
func benchCheckpoint(b *testing.B, p benchCheckpointParams) {
|
||||
func benchCheckpoint(b testing.TB, p benchCheckpointParams) {
|
||||
l := promslog.NewNopLogger()
|
||||
rs := remote.NewStorage(
|
||||
promslog.NewNopLogger(), nil,
|
||||
|
|
@ -85,16 +150,10 @@ func benchCheckpoint(b *testing.B, p benchCheckpointParams) {
|
|||
)
|
||||
defer rs.Close()
|
||||
|
||||
// b.Cleanup(func() {
|
||||
// require.NoError(b, rs.Close())
|
||||
// })
|
||||
|
||||
opts := DefaultOptions()
|
||||
|
||||
// Hack to avoid "out of order sample" error that's happening only in benchmarks.
|
||||
opts.OutOfOrderTimeWindow = math.MaxInt64
|
||||
|
||||
opts.OutOfOrderTimeWindow = math.MaxInt64 // Fixes "out of order sample" in benchmarks
|
||||
opts.SkipCurrentCheckpointReRead = p.skipCurrentCheckpointReRead
|
||||
|
||||
db, err := Open(l, nil, rs, p.storageDir, opts)
|
||||
require.NoError(b, err, "Open")
|
||||
|
||||
|
|
@ -184,8 +243,9 @@ func createCheckpointFixtures(t testing.TB, p checkpointFixtureParams) {
|
|||
// Make a segment to put initial data
|
||||
var enc record.Encoder
|
||||
|
||||
// Create first dummy segment to bump the start segment number.
|
||||
seg, err := wlog.CreateSegment(p.dir, 100)
|
||||
// Create dummy segment to bump the start segment number.
|
||||
// Dummy segment should be zero or agent.Open() will fail.
|
||||
seg, err := wlog.CreateSegment(p.dir, 0)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, seg.Close())
|
||||
|
||||
|
|
@ -193,17 +253,12 @@ func createCheckpointFixtures(t testing.TB, p checkpointFixtureParams) {
|
|||
require.NoError(t, err)
|
||||
|
||||
series := make([]record.RefSeries, 0, len(p.seriesLabels))
|
||||
meta := make([]record.RefMetadata, 0, len(p.seriesLabels))
|
||||
for i, lset := range p.seriesLabels {
|
||||
// NOTE: don't append RefMetadata as agent.DB doesn't support it during WAL replay.
|
||||
series = append(series, record.RefSeries{
|
||||
Ref: chunks.HeadSeriesRef(i),
|
||||
Labels: labels.New(lset...),
|
||||
})
|
||||
meta = append(meta, record.RefMetadata{
|
||||
Ref: chunks.HeadSeriesRef(i),
|
||||
Unit: "unit",
|
||||
Help: "help",
|
||||
})
|
||||
}
|
||||
|
||||
var dt int64
|
||||
|
|
@ -213,9 +268,6 @@ func createCheckpointFixtures(t testing.TB, p checkpointFixtureParams) {
|
|||
// Write series required for samples
|
||||
b := enc.Series(series, nil)
|
||||
require.NoError(t, w.Log(b))
|
||||
|
||||
b = enc.Metadata(meta, nil)
|
||||
require.NoError(t, w.Log(b))
|
||||
}
|
||||
|
||||
samples = samples[:0]
|
||||
|
|
|
|||
Loading…
Reference in a new issue