|
|
@@ -447,85 +447,85 @@ func (w Window) Minutes() float64 {
|
|
|
return w.end.Sub(*w.start).Minutes()
|
|
|
}
|
|
|
|
|
|
-// Overlaps returns true iff the two given Windows share and amount of temporal
|
|
|
+// Overlaps returns true iff the two given Windows share an amount of temporal
|
|
|
// coverage.
|
|
|
// TODO complete (with unit tests!) and then implement in AllocationSet.accumulate
|
|
|
// TODO:CLEANUP
|
|
|
-func (w Window) Overlaps(x Window) bool {
|
|
|
- if (w.start == nil && w.end == nil) || (x.start == nil && x.end == nil) {
|
|
|
- // one window is completely open, so overlap is guaranteed
|
|
|
- // <---------->
|
|
|
- // ?------?
|
|
|
- return true
|
|
|
- }
|
|
|
-
|
|
|
- // Neither window is completely open (nil, nil), but one or the other might
|
|
|
- // still be future- or past-open.
|
|
|
-
|
|
|
- if w.start == nil {
|
|
|
- // w is past-open, future-closed
|
|
|
- // <------]
|
|
|
-
|
|
|
- if x.start != nil && !x.start.Before(*w.end) {
|
|
|
- // x starts after w ends (or eq)
|
|
|
- // <------]
|
|
|
- // [------?
|
|
|
- return false
|
|
|
- }
|
|
|
-
|
|
|
- // <-----]
|
|
|
- // ?-----?
|
|
|
- return true
|
|
|
- }
|
|
|
-
|
|
|
- if w.end == nil {
|
|
|
- // w is future-open, past-closed
|
|
|
- // [------>
|
|
|
-
|
|
|
- if x.end != nil && !x.end.After(*w.end) {
|
|
|
- // x ends before w begins (or eq)
|
|
|
- // [------>
|
|
|
- // ?------]
|
|
|
- return false
|
|
|
- }
|
|
|
-
|
|
|
- // [------>
|
|
|
- // ?------?
|
|
|
- return true
|
|
|
- }
|
|
|
-
|
|
|
- // Now we know w is closed, but we don't know about x
|
|
|
- // [------]
|
|
|
- // ?------?
|
|
|
- if x.start == nil {
|
|
|
- // TODO
|
|
|
- }
|
|
|
-
|
|
|
- if x.end == nil {
|
|
|
- // TODO
|
|
|
- }
|
|
|
-
|
|
|
- // Both are closed.
|
|
|
-
|
|
|
- if !x.start.Before(*w.end) && !x.end.Before(*w.end) {
|
|
|
- // x starts and ends after w ends
|
|
|
- // [------]
|
|
|
- // [------]
|
|
|
- return false
|
|
|
- }
|
|
|
-
|
|
|
- if !x.start.After(*w.start) && !x.end.After(*w.start) {
|
|
|
- // x starts and ends before w starts
|
|
|
- // [------]
|
|
|
- // [------]
|
|
|
- return false
|
|
|
- }
|
|
|
-
|
|
|
- // w and x must overlap
|
|
|
- // [------]
|
|
|
- // [------]
|
|
|
- return true
|
|
|
-}
|
|
|
+// func (w Window) Overlaps(x Window) bool {
|
|
|
+// if (w.start == nil && w.end == nil) || (x.start == nil && x.end == nil) {
|
|
|
+// // one window is completely open, so overlap is guaranteed
|
|
|
+// // <---------->
|
|
|
+// // ?------?
|
|
|
+// return true
|
|
|
+// }
|
|
|
+
|
|
|
+// // Neither window is completely open (nil, nil), but one or the other might
|
|
|
+// // still be future- or past-open.
|
|
|
+
|
|
|
+// if w.start == nil {
|
|
|
+// // w is past-open, future-closed
|
|
|
+// // <------]
|
|
|
+
|
|
|
+// if x.start != nil && !x.start.Before(*w.end) {
|
|
|
+// // x starts after w ends (or eq)
|
|
|
+// // <------]
|
|
|
+// // [------?
|
|
|
+// return false
|
|
|
+// }
|
|
|
+
|
|
|
+// // <-----]
|
|
|
+// // ?-----?
|
|
|
+// return true
|
|
|
+// }
|
|
|
+
|
|
|
+// if w.end == nil {
|
|
|
+// // w is future-open, past-closed
|
|
|
+// // [------>
|
|
|
+
|
|
|
+// if x.end != nil && !x.end.After(*w.end) {
|
|
|
+// // x ends before w begins (or eq)
|
|
|
+// // [------>
|
|
|
+// // ?------]
|
|
|
+// return false
|
|
|
+// }
|
|
|
+
|
|
|
+// // [------>
|
|
|
+// // ?------?
|
|
|
+// return true
|
|
|
+// }
|
|
|
+
|
|
|
+// // Now we know w is closed, but we don't know about x
|
|
|
+// // [------]
|
|
|
+// // ?------?
|
|
|
+// if x.start == nil {
|
|
|
+// // TODO
|
|
|
+// }
|
|
|
+
|
|
|
+// if x.end == nil {
|
|
|
+// // TODO
|
|
|
+// }
|
|
|
+
|
|
|
+// // Both are closed.
|
|
|
+
|
|
|
+// if !x.start.Before(*w.end) && !x.end.Before(*w.end) {
|
|
|
+// // x starts and ends after w ends
|
|
|
+// // [------]
|
|
|
+// // [------]
|
|
|
+// return false
|
|
|
+// }
|
|
|
+
|
|
|
+// if !x.start.After(*w.start) && !x.end.After(*w.start) {
|
|
|
+// // x starts and ends before w starts
|
|
|
+// // [------]
|
|
|
+// // [------]
|
|
|
+// return false
|
|
|
+// }
|
|
|
+
|
|
|
+// // w and x must overlap
|
|
|
+// // [------]
|
|
|
+// // [------]
|
|
|
+// return true
|
|
|
+// }
|
|
|
|
|
|
func (w Window) Set(start, end *time.Time) {
|
|
|
w.start = start
|
|
|
@@ -577,9 +577,12 @@ func (w Window) DurationOffset() (time.Duration, time.Duration, error) {
|
|
|
return duration, offset, nil
|
|
|
}
|
|
|
|
|
|
-// DurationOffsetForPrometheus returns durations representing the duration and
|
|
|
-// offset of the given window, factoring in the Thanos offset if necessary. The
|
|
|
-// duration is returned as
|
|
|
+// DurationOffsetForPrometheus returns strings representing durations for the
|
|
|
+// duration and offset of the given window, factoring in the Thanos offset if
|
|
|
+// necessary. Whereas duration is a simple duration string (e.g. "1d"), the
|
|
|
+// offset includes the word "offset" (e.g. " offset 2d") so that the values
|
|
|
+// returned can be used directly in the formatting string "some_metric[%s]%s"
|
|
|
+// to generate the query "some_metric[1d] offset 2d".
|
|
|
func (w Window) DurationOffsetForPrometheus() (string, string, error) {
|
|
|
duration, offset, err := w.DurationOffset()
|
|
|
if err != nil {
|