mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-02 08:31:11 -08:00
Prevent panic with ApplyConfig (#312)
Signed-off-by: Ganesh Vernekar <ganeshvern@gmail.com>
This commit is contained in:
parent
9fe7d3a478
commit
01b03b7f85
|
@ -980,7 +980,10 @@ func (db *DB) ApplyConfig(conf *config.Config) error {
|
||||||
// Create WBL if it was not present and if OOO is enabled with WAL enabled.
|
// Create WBL if it was not present and if OOO is enabled with WAL enabled.
|
||||||
var wblog *wal.WAL
|
var wblog *wal.WAL
|
||||||
var err error
|
var err error
|
||||||
if !db.oooWasEnabled.Load() && oooTimeWindow > 0 && db.opts.WALSegmentSize >= 0 {
|
if db.head.wbl != nil {
|
||||||
|
// The existing WBL from the disk might have been replayed while OOO was disabled.
|
||||||
|
wblog = db.head.wbl
|
||||||
|
} else if !db.oooWasEnabled.Load() && oooTimeWindow > 0 && db.opts.WALSegmentSize >= 0 {
|
||||||
segmentSize := wal.DefaultSegmentSize
|
segmentSize := wal.DefaultSegmentSize
|
||||||
// Wal is set to a custom size.
|
// Wal is set to a custom size.
|
||||||
if db.opts.WALSegmentSize > 0 {
|
if db.opts.WALSegmentSize > 0 {
|
||||||
|
|
|
@ -5352,3 +5352,52 @@ func TestWblReplayAfterOOODisableAndRestart(t *testing.T) {
|
||||||
// We can still query OOO samples when OOO is disabled.
|
// We can still query OOO samples when OOO is disabled.
|
||||||
verifySamples(allSamples)
|
verifySamples(allSamples)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPanicOnApplyConfig(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
|
||||||
|
opts := DefaultOptions()
|
||||||
|
opts.OutOfOrderTimeWindow = 60 * time.Minute.Milliseconds()
|
||||||
|
opts.AllowOverlappingQueries = true
|
||||||
|
|
||||||
|
db, err := Open(dir, nil, nil, opts, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
db.DisableCompactions()
|
||||||
|
t.Cleanup(func() {
|
||||||
|
require.NoError(t, db.Close())
|
||||||
|
})
|
||||||
|
|
||||||
|
series1 := labels.FromStrings("foo", "bar1")
|
||||||
|
var allSamples []tsdbutil.Sample
|
||||||
|
addSamples := func(fromMins, toMins int64) {
|
||||||
|
app := db.Appender(context.Background())
|
||||||
|
for min := fromMins; min <= toMins; min++ {
|
||||||
|
ts := min * time.Minute.Milliseconds()
|
||||||
|
_, err := app.Append(0, series1, ts, float64(ts))
|
||||||
|
require.NoError(t, err)
|
||||||
|
allSamples = append(allSamples, sample{t: ts, v: float64(ts)})
|
||||||
|
}
|
||||||
|
require.NoError(t, app.Commit())
|
||||||
|
}
|
||||||
|
|
||||||
|
// In-order samples.
|
||||||
|
addSamples(290, 300)
|
||||||
|
// OOO samples.
|
||||||
|
addSamples(250, 260)
|
||||||
|
|
||||||
|
// Restart DB with OOO disabled.
|
||||||
|
require.NoError(t, db.Close())
|
||||||
|
opts.OutOfOrderTimeWindow = 0
|
||||||
|
db, err = Open(db.dir, nil, prometheus.NewRegistry(), opts, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// ApplyConfig with OOO enabled and expect no panic.
|
||||||
|
err = db.ApplyConfig(&config.Config{
|
||||||
|
StorageConfig: config.StorageConfig{
|
||||||
|
TSDBConfig: &config.TSDBConfig{
|
||||||
|
OutOfOrderTimeWindow: 60 * time.Minute.Milliseconds(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue