retention grid: interva length monotonicity: exception for keep=all

fixes #6
This commit is contained in:
Christian Schwarz 2017-10-05 20:34:35 +02:00
parent 4b489ad2c7
commit c48069ce88

View File

@ -80,13 +80,22 @@ func parseGridPrunePolicy(e map[string]interface{}) (p *GridPrunePolicy, err err
// Assert intervals are of increasing length (not necessarily required, but indicates config mistake) // Assert intervals are of increasing length (not necessarily required, but indicates config mistake)
lastDuration := time.Duration(0) lastDuration := time.Duration(0)
for i := range intervals { for i := range intervals {
if intervals[i].Length < lastDuration { if intervals[i].Length < lastDuration {
err = fmt.Errorf("retention grid interval length must be monotonically increasing:"+ // If all intervals before were keep=all, this is ok
"interval %d is shorter than %d", i+1, i) allPrevKeepCountAll := true
for j := i - 1; allPrevKeepCountAll && j >= 0; j-- {
allPrevKeepCountAll = intervals[j].KeepCount == util.RetentionGridKeepCountAll
}
if allPrevKeepCountAll {
goto isMonotonicIncrease
}
err = errors.New("retention grid interval length must be monotonically increasing")
return return
} else {
lastDuration = intervals[i].Length
} }
isMonotonicIncrease:
lastDuration = intervals[i].Length
} }
p.RetentionGrid = util.NewRetentionGrid(intervals) p.RetentionGrid = util.NewRetentionGrid(intervals)