mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Add hidden flag for the delayed compaction random time window (#14919)
* Add hidden flag for the delayed compaction random time window Signed-off-by: Alban HURTAUD <alban.hurtaud@amadeus.com> * Update cmd/prometheus/main.go Co-authored-by: Ayoub Mrini <ayoubmrini424@gmail.com> Signed-off-by: Alban Hurtaud <alban.hurtaud@amadeus.com> * Update cmd/prometheus/main.go Co-authored-by: Ayoub Mrini <ayoubmrini424@gmail.com> Signed-off-by: Alban Hurtaud <alban.hurtaud@amadeus.com> * Update tsdb/db.go Co-authored-by: Ayoub Mrini <ayoubmrini424@gmail.com> Signed-off-by: Alban Hurtaud <alban.hurtaud@amadeus.com> * Fix flag name according to review - add test for delay Signed-off-by: Alban HURTAUD <alban.hurtaud@amadeus.com> * Fix afer main rebase Signed-off-by: Alban HURTAUD <alban.hurtaud@amadeus.com> * Implement review comments Signed-off-by: Alban HURTAUD <alban.hurtaud@amadeus.com> * Update generatedelaytest to try with limit values Signed-off-by: Alban HURTAUD <alban.hurtaud@amadeus.com> --------- Signed-off-by: Alban HURTAUD <alban.hurtaud@amadeus.com> Signed-off-by: Alban Hurtaud <alban.hurtaud@amadeus.com> Co-authored-by: Ayoub Mrini <ayoubmrini424@gmail.com>
This commit is contained in:
parent
a1a78a151d
commit
4b56af7eb8
|
@ -433,6 +433,9 @@ func main() {
|
||||||
serverOnlyFlag(a, "storage.tsdb.samples-per-chunk", "Target number of samples per chunk.").
|
serverOnlyFlag(a, "storage.tsdb.samples-per-chunk", "Target number of samples per chunk.").
|
||||||
Default("120").Hidden().IntVar(&cfg.tsdb.SamplesPerChunk)
|
Default("120").Hidden().IntVar(&cfg.tsdb.SamplesPerChunk)
|
||||||
|
|
||||||
|
serverOnlyFlag(a, "storage.tsdb.delayed-compaction.max-percent", "Sets the upper limit for the random compaction delay, specified as a percentage of the head chunk range. 100 means the compaction can be delayed by up to the entire head chunk range. Only effective when the delayed-compaction feature flag is enabled.").
|
||||||
|
Default("10").Hidden().IntVar(&cfg.tsdb.CompactionDelayMaxPercent)
|
||||||
|
|
||||||
agentOnlyFlag(a, "storage.agent.path", "Base path for metrics storage.").
|
agentOnlyFlag(a, "storage.agent.path", "Base path for metrics storage.").
|
||||||
Default("data-agent/").StringVar(&cfg.agentStoragePath)
|
Default("data-agent/").StringVar(&cfg.agentStoragePath)
|
||||||
|
|
||||||
|
@ -663,6 +666,12 @@ func main() {
|
||||||
|
|
||||||
cfg.tsdb.MaxBlockDuration = maxBlockDuration
|
cfg.tsdb.MaxBlockDuration = maxBlockDuration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delayed compaction checks
|
||||||
|
if cfg.tsdb.EnableDelayedCompaction && (cfg.tsdb.CompactionDelayMaxPercent > 100 || cfg.tsdb.CompactionDelayMaxPercent <= 0) {
|
||||||
|
logger.Warn("The --storage.tsdb.delayed-compaction.max-percent should have a value between 1 and 100. Using default", "default", tsdb.DefaultCompactionDelayMaxPercent)
|
||||||
|
cfg.tsdb.CompactionDelayMaxPercent = tsdb.DefaultCompactionDelayMaxPercent
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
noStepSubqueryInterval := &safePromQLNoStepSubqueryInterval{}
|
noStepSubqueryInterval := &safePromQLNoStepSubqueryInterval{}
|
||||||
|
@ -1796,6 +1805,7 @@ type tsdbOptions struct {
|
||||||
EnableMemorySnapshotOnShutdown bool
|
EnableMemorySnapshotOnShutdown bool
|
||||||
EnableNativeHistograms bool
|
EnableNativeHistograms bool
|
||||||
EnableDelayedCompaction bool
|
EnableDelayedCompaction bool
|
||||||
|
CompactionDelayMaxPercent int
|
||||||
EnableOverlappingCompaction bool
|
EnableOverlappingCompaction bool
|
||||||
EnableOOONativeHistograms bool
|
EnableOOONativeHistograms bool
|
||||||
}
|
}
|
||||||
|
@ -1820,6 +1830,7 @@ func (opts tsdbOptions) ToTSDBOptions() tsdb.Options {
|
||||||
EnableOOONativeHistograms: opts.EnableOOONativeHistograms,
|
EnableOOONativeHistograms: opts.EnableOOONativeHistograms,
|
||||||
OutOfOrderTimeWindow: opts.OutOfOrderTimeWindow,
|
OutOfOrderTimeWindow: opts.OutOfOrderTimeWindow,
|
||||||
EnableDelayedCompaction: opts.EnableDelayedCompaction,
|
EnableDelayedCompaction: opts.EnableDelayedCompaction,
|
||||||
|
CompactionDelayMaxPercent: opts.CompactionDelayMaxPercent,
|
||||||
EnableOverlappingCompaction: opts.EnableOverlappingCompaction,
|
EnableOverlappingCompaction: opts.EnableOverlappingCompaction,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,9 @@ const (
|
||||||
// DefaultBlockDuration in milliseconds.
|
// DefaultBlockDuration in milliseconds.
|
||||||
DefaultBlockDuration = int64(2 * time.Hour / time.Millisecond)
|
DefaultBlockDuration = int64(2 * time.Hour / time.Millisecond)
|
||||||
|
|
||||||
|
// DefaultCompactionDelayMaxPercent in percentage.
|
||||||
|
DefaultCompactionDelayMaxPercent = 10
|
||||||
|
|
||||||
// Block dir suffixes to make deletion and creation operations atomic.
|
// Block dir suffixes to make deletion and creation operations atomic.
|
||||||
// We decided to do suffixes instead of creating meta.json as last (or delete as first) one,
|
// We decided to do suffixes instead of creating meta.json as last (or delete as first) one,
|
||||||
// because in error case you still can recover meta.json from the block content within local TSDB dir.
|
// because in error case you still can recover meta.json from the block content within local TSDB dir.
|
||||||
|
@ -86,6 +89,7 @@ func DefaultOptions() *Options {
|
||||||
EnableOverlappingCompaction: true,
|
EnableOverlappingCompaction: true,
|
||||||
EnableSharding: false,
|
EnableSharding: false,
|
||||||
EnableDelayedCompaction: false,
|
EnableDelayedCompaction: false,
|
||||||
|
CompactionDelayMaxPercent: DefaultCompactionDelayMaxPercent,
|
||||||
CompactionDelay: time.Duration(0),
|
CompactionDelay: time.Duration(0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -204,6 +208,8 @@ type Options struct {
|
||||||
// CompactionDelay delays the start time of auto compactions.
|
// CompactionDelay delays the start time of auto compactions.
|
||||||
// It can be increased by up to one minute if the DB does not commit too often.
|
// It can be increased by up to one minute if the DB does not commit too often.
|
||||||
CompactionDelay time.Duration
|
CompactionDelay time.Duration
|
||||||
|
// CompactionDelayMaxPercent is the upper limit for CompactionDelay, specified as a percentage of the head chunk range.
|
||||||
|
CompactionDelayMaxPercent int
|
||||||
|
|
||||||
// NewCompactorFunc is a function that returns a TSDB compactor.
|
// NewCompactorFunc is a function that returns a TSDB compactor.
|
||||||
NewCompactorFunc NewCompactorFunc
|
NewCompactorFunc NewCompactorFunc
|
||||||
|
@ -1986,8 +1992,7 @@ func (db *DB) EnableCompactions() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) generateCompactionDelay() time.Duration {
|
func (db *DB) generateCompactionDelay() time.Duration {
|
||||||
// Up to 10% of the head's chunkRange.
|
return time.Duration(rand.Int63n(db.head.chunkRange.Load()*int64(db.opts.CompactionDelayMaxPercent)/100)) * time.Millisecond
|
||||||
return time.Duration(rand.Int63n(db.head.chunkRange.Load()/10)) * time.Millisecond
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ForceHeadMMap is intended for use only in tests and benchmarks.
|
// ForceHeadMMap is intended for use only in tests and benchmarks.
|
||||||
|
|
|
@ -8896,24 +8896,45 @@ func TestBlockQuerierAndBlockChunkQuerier(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGenerateCompactionDelay(t *testing.T) {
|
func TestGenerateCompactionDelay(t *testing.T) {
|
||||||
assertDelay := func(delay time.Duration) {
|
assertDelay := func(delay time.Duration, expectedMaxPercentDelay int) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
require.GreaterOrEqual(t, delay, time.Duration(0))
|
require.GreaterOrEqual(t, delay, time.Duration(0))
|
||||||
// Less than 10% of the chunkRange.
|
// Expect to generate a delay up to MaxPercentDelay of the head chunk range
|
||||||
require.LessOrEqual(t, delay, 6000*time.Millisecond)
|
require.LessOrEqual(t, delay, (time.Duration(60000*expectedMaxPercentDelay/100) * time.Millisecond))
|
||||||
}
|
}
|
||||||
|
|
||||||
opts := DefaultOptions()
|
opts := DefaultOptions()
|
||||||
opts.EnableDelayedCompaction = true
|
cases := []struct {
|
||||||
db := openTestDB(t, opts, []int64{60000})
|
compactionDelayPercent int
|
||||||
defer func() {
|
}{
|
||||||
require.NoError(t, db.Close())
|
{
|
||||||
}()
|
compactionDelayPercent: 1,
|
||||||
// The offset is generated and changed while opening.
|
},
|
||||||
assertDelay(db.opts.CompactionDelay)
|
{
|
||||||
|
compactionDelayPercent: 10,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
compactionDelayPercent: 60,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
compactionDelayPercent: 100,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
for i := 0; i < 1000; i++ {
|
opts.EnableDelayedCompaction = true
|
||||||
assertDelay(db.generateCompactionDelay())
|
|
||||||
|
for _, c := range cases {
|
||||||
|
opts.CompactionDelayMaxPercent = c.compactionDelayPercent
|
||||||
|
db := openTestDB(t, opts, []int64{60000})
|
||||||
|
defer func() {
|
||||||
|
require.NoError(t, db.Close())
|
||||||
|
}()
|
||||||
|
// The offset is generated and changed while opening.
|
||||||
|
assertDelay(db.opts.CompactionDelay, c.compactionDelayPercent)
|
||||||
|
|
||||||
|
for i := 0; i < 1000; i++ {
|
||||||
|
assertDelay(db.generateCompactionDelay(), c.compactionDelayPercent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue