Skip to content

Commit 4068968

Browse files
authored
Protect retention from overflowing (prometheus#5112)
Also sanitise the max block duration to max a month. Signed-off-by: Goutham Veeramachaneni <[email protected]>
1 parent 384cba1 commit 4068968

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

cmd/prometheus/main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"crypto/md5"
2020
"encoding/json"
2121
"fmt"
22+
"math"
2223
"net"
2324
"net/http"
2425
_ "net/http/pprof" // Comment this line to disable pprof endpoint.
@@ -266,8 +267,23 @@ func main() {
266267

267268
cfg.tsdb.RetentionDuration = chooseRetention(oldFlagRetentionDuration, newFlagRetentionDuration)
268269

270+
// Check for overflows. This limits our max retention to ~292.5y.
271+
if cfg.tsdb.RetentionDuration < 0 {
272+
cfg.tsdb.RetentionDuration = math.MaxInt64
273+
}
274+
269275
if cfg.tsdb.MaxBlockDuration == 0 {
270276
cfg.tsdb.MaxBlockDuration = cfg.tsdb.RetentionDuration / 10
277+
278+
// Prevent blocks from getting too big.
279+
monthLong, err := model.ParseDuration("31d")
280+
if err != nil {
281+
panic(err)
282+
}
283+
284+
if cfg.tsdb.MaxBlockDuration > monthLong {
285+
cfg.tsdb.MaxBlockDuration = monthLong
286+
}
271287
}
272288

273289
promql.LookbackDelta = time.Duration(cfg.lookbackDelta)

0 commit comments

Comments
 (0)