Protect retention from overflowing (#5112)

Also sanitise the max block duration to max a month.

Signed-off-by: Goutham Veeramachaneni <gouthamve@gmail.com>
This commit is contained in:
Goutham Veeramachaneni 2019-01-18 20:18:06 +05:30 committed by GitHub
parent 384cba1211
commit 4068968e12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,6 +19,7 @@ import (
"crypto/md5"
"encoding/json"
"fmt"
"math"
"net"
"net/http"
_ "net/http/pprof" // Comment this line to disable pprof endpoint.
@ -266,8 +267,23 @@ func main() {
cfg.tsdb.RetentionDuration = chooseRetention(oldFlagRetentionDuration, newFlagRetentionDuration)
// Check for overflows. This limits our max retention to ~292.5y.
if cfg.tsdb.RetentionDuration < 0 {
cfg.tsdb.RetentionDuration = math.MaxInt64
}
if cfg.tsdb.MaxBlockDuration == 0 {
cfg.tsdb.MaxBlockDuration = cfg.tsdb.RetentionDuration / 10
// Prevent blocks from getting too big.
monthLong, err := model.ParseDuration("31d")
if err != nil {
panic(err)
}
if cfg.tsdb.MaxBlockDuration > monthLong {
cfg.tsdb.MaxBlockDuration = monthLong
}
}
promql.LookbackDelta = time.Duration(cfg.lookbackDelta)