From 4068968e126f64d7054284719ca96e94486084d0 Mon Sep 17 00:00:00 2001 From: Goutham Veeramachaneni Date: Fri, 18 Jan 2019 20:18:06 +0530 Subject: [PATCH] Protect retention from overflowing (#5112) Also sanitise the max block duration to max a month. Signed-off-by: Goutham Veeramachaneni --- cmd/prometheus/main.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go index 25426b9a3..e1321b93a 100644 --- a/cmd/prometheus/main.go +++ b/cmd/prometheus/main.go @@ -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)