github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/pkg/storage/stores/tsdb/bounds.go (about) 1 package tsdb 2 3 import ( 4 "math" 5 6 "github.com/prometheus/common/model" 7 ) 8 9 type Bounded interface { 10 Bounds() (model.Time, model.Time) 11 } 12 13 // InclusiveBounds will ensure the underlying Bounded implementation 14 // is turned into [lower,upper] inclusivity. 15 // Generally, we consider bounds to be `[lower,upper)` inclusive 16 // This helper will account for integer overflow. 17 // Because model.Time is millisecond-precise, but Loki uses nanosecond precision, 18 // be careful usage can handle an extra millisecond being added. 19 func inclusiveBounds(b Bounded) (model.Time, model.Time) { 20 lower, upper := b.Bounds() 21 22 if int64(upper) < math.MaxInt64 { 23 upper++ 24 } 25 26 return lower, upper 27 } 28 29 type bounds struct { 30 mint, maxt model.Time 31 } 32 33 func newBounds(mint, maxt model.Time) bounds { return bounds{mint: mint, maxt: maxt} } 34 35 func (b bounds) Bounds() (model.Time, model.Time) { return b.mint, b.maxt } 36 37 func Overlap(a, b Bounded) bool { 38 aFrom, aThrough := a.Bounds() 39 bFrom, bThrough := b.Bounds() 40 41 return aFrom < bThrough && aThrough > bFrom 42 }