-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
ingester_query_window.go
33 lines (26 loc) · 1.23 KB
/
ingester_query_window.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package queryrange
import (
"time"
"github.com/grafana/loki/v3/pkg/util"
"github.com/grafana/loki/v3/pkg/util/validation"
)
// SplitIntervalForTimeRange returns the correct split interval to use. It accounts for the given upperBound value being
// within the ingester query window, in which case it returns the ingester query split (unless it's not set, then the default
// split interval will be used).
func SplitIntervalForTimeRange(iqo util.IngesterQueryOptions, limits Limits, defaultSplitFn func(string) time.Duration, tenantIDs []string, ref, upperBound time.Time) time.Duration {
split := validation.SmallestPositiveNonZeroDurationPerTenant(tenantIDs, defaultSplitFn)
if iqo == nil {
return split
}
// if the query is within the ingester query window, choose the ingester split duration (if configured), otherwise
// revert to the default split duration
ingesterQueryWindowStart := ref.Add(-iqo.QueryIngestersWithin())
// query is (even partially) within the ingester query window
if upperBound.After(ingesterQueryWindowStart) {
ingesterSplit := validation.MaxDurationOrZeroPerTenant(tenantIDs, limits.IngesterQuerySplitDuration)
if !iqo.QueryStoreOnly() && ingesterSplit > 0 {
split = ingesterSplit
}
}
return split
}