mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 13:44:05 -08:00
tsdb/agent: fix validation of default options (#9876)
* tsdb/agent: fix application of defaults MaxTS was being incorrectly constrained to the truncation interval * add more tests to check validation * force MaxWALTime = MinWALTime if min > max Signed-off-by: Robert Fratto <robertfratto@gmail.com>
This commit is contained in:
parent
d166da7b59
commit
448cfda6c1
|
@ -317,13 +317,16 @@ func validateOptions(opts *Options) *Options {
|
||||||
opts.TruncateFrequency = DefaultTruncateFrequency
|
opts.TruncateFrequency = DefaultTruncateFrequency
|
||||||
}
|
}
|
||||||
if opts.MinWALTime <= 0 {
|
if opts.MinWALTime <= 0 {
|
||||||
opts.MinWALTime = 0
|
opts.MinWALTime = DefaultMinWALTime
|
||||||
}
|
}
|
||||||
if opts.MaxWALTime <= 0 {
|
if opts.MaxWALTime <= 0 {
|
||||||
opts.MaxWALTime = DefaultMaxWALTime
|
opts.MaxWALTime = DefaultMaxWALTime
|
||||||
}
|
}
|
||||||
|
if opts.MinWALTime > opts.MaxWALTime {
|
||||||
|
opts.MaxWALTime = opts.MinWALTime
|
||||||
|
}
|
||||||
|
|
||||||
if t := int64(opts.TruncateFrequency * time.Hour / time.Millisecond); opts.MaxWALTime < t {
|
if t := int64(opts.TruncateFrequency / time.Millisecond); opts.MaxWALTime < t {
|
||||||
opts.MaxWALTime = t
|
opts.MaxWALTime = t
|
||||||
}
|
}
|
||||||
return opts
|
return opts
|
||||||
|
|
|
@ -446,6 +446,25 @@ func Test_ExistingWAL_NextRef(t *testing.T) {
|
||||||
require.Equal(t, uint64(seriesCount), db.nextRef.Load(), "nextRef should be equal to the number of series written across the entire WAL")
|
require.Equal(t, uint64(seriesCount), db.nextRef.Load(), "nextRef should be equal to the number of series written across the entire WAL")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_validateOptions(t *testing.T) {
|
||||||
|
t.Run("Apply defaults to zero values", func(t *testing.T) {
|
||||||
|
opts := validateOptions(&Options{})
|
||||||
|
require.Equal(t, DefaultOptions(), opts)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Defaults are already valid", func(t *testing.T) {
|
||||||
|
require.Equal(t, DefaultOptions(), validateOptions(nil))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("MaxWALTime should not be lower than TruncateFrequency", func(t *testing.T) {
|
||||||
|
opts := validateOptions(&Options{
|
||||||
|
MaxWALTime: int64(time.Hour / time.Millisecond),
|
||||||
|
TruncateFrequency: 2 * time.Hour,
|
||||||
|
})
|
||||||
|
require.Equal(t, int64(2*time.Hour/time.Millisecond), opts.MaxWALTime)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func startTime() (int64, error) {
|
func startTime() (int64, error) {
|
||||||
return time.Now().Unix() * 1000, nil
|
return time.Now().Unix() * 1000, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue