mirror of https://github.com/prometheus/prometheus
Interim documentation
parent
b470f925b7
commit
51a0f21cf8
|
@ -594,22 +594,37 @@ func rewriteForGreediestInterval(greediestIntervals map[time.Duration]durationOp
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flattens queries that occur at the same time according to duration and level
|
// rewriteForRangeAndInterval examines the existence of a range operation and a
|
||||||
// of greed.
|
// set of interval operations that start at the same time and deletes all
|
||||||
func optimizeTimeGroup(group ops) (out ops) {
|
// interval operations that start and finish before the range operation
|
||||||
var (
|
// completes and rewrites all interval operations that continue longer than
|
||||||
greediestRange = selectGreediestRange(collectRanges(group))
|
// the range operation to start at the next best increment after the range.
|
||||||
greediestIntervals = selectGreediestIntervals(collectIntervals(group))
|
//
|
||||||
containsRange = greediestRange != nil
|
// Assume that we have a range operator O1 and two interval operations O2 and
|
||||||
containsInterval = len(greediestIntervals) > 0
|
// O3. O2 and O3 have the same period (i.e., sampling interval), but O2
|
||||||
)
|
// terminates before O1 and O3 continue beyond O1.
|
||||||
|
//
|
||||||
switch {
|
// O1------------>|
|
||||||
case containsRange && !containsInterval:
|
// T1------------T7
|
||||||
out = rewriteForGreediestRange(greediestRange)
|
//
|
||||||
case !containsRange && containsInterval:
|
// O2-->|-->|-->|
|
||||||
out = rewriteForGreediestInterval(greediestIntervals)
|
// T1----------T6
|
||||||
case containsRange && containsInterval:
|
//
|
||||||
|
// O3-->|-->|-->|-->|-->|
|
||||||
|
// T1------------------T10
|
||||||
|
//
|
||||||
|
// This scenario will be rewritten such that O2 is deleted and O3 is truncated
|
||||||
|
// from T1 through T7, and O3's new starting time is at T7 and runs through T10:
|
||||||
|
//
|
||||||
|
// O1------------>|
|
||||||
|
// T1------------T7
|
||||||
|
//
|
||||||
|
// O2>|-->|
|
||||||
|
// T7---T10
|
||||||
|
//
|
||||||
|
// All rewritten interval operators will respect their original start time
|
||||||
|
// multipliers.
|
||||||
|
func rewriteForRangeAndInterval(greediestRange durationOperator, greediestIntervals map[time.Duration]durationOperator) (out ops) {
|
||||||
out = append(out, greediestRange)
|
out = append(out, greediestRange)
|
||||||
for _, op := range greediestIntervals {
|
for _, op := range greediestIntervals {
|
||||||
if !op.GreedierThan(greediestRange) {
|
if !op.GreedierThan(greediestRange) {
|
||||||
|
@ -634,6 +649,28 @@ func optimizeTimeGroup(group ops) (out ops) {
|
||||||
// necessary.
|
// necessary.
|
||||||
out = append(out, &newIntervalOperation)
|
out = append(out, &newIntervalOperation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flattens queries that occur at the same time according to duration and level
|
||||||
|
// of greed. Consult the various rewriter functions for their respective modes
|
||||||
|
// of operation.
|
||||||
|
func optimizeTimeGroup(group ops) (out ops) {
|
||||||
|
var (
|
||||||
|
greediestRange = selectGreediestRange(collectRanges(group))
|
||||||
|
greediestIntervals = selectGreediestIntervals(collectIntervals(group))
|
||||||
|
containsRange = greediestRange != nil
|
||||||
|
containsInterval = len(greediestIntervals) > 0
|
||||||
|
)
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case containsRange && !containsInterval:
|
||||||
|
out = rewriteForGreediestRange(greediestRange)
|
||||||
|
case !containsRange && containsInterval:
|
||||||
|
out = rewriteForGreediestInterval(greediestIntervals)
|
||||||
|
case containsRange && containsInterval:
|
||||||
|
out = rewriteForRangeAndInterval(greediestRange, greediestIntervals)
|
||||||
default:
|
default:
|
||||||
// Operation is OK as-is.
|
// Operation is OK as-is.
|
||||||
out = append(out, group[0])
|
out = append(out, group[0])
|
||||||
|
@ -649,8 +686,11 @@ func optimizeTimeGroups(pending ops) (out ops) {
|
||||||
|
|
||||||
sort.Sort(startsAtSort{pending})
|
sort.Sort(startsAtSort{pending})
|
||||||
|
|
||||||
nextOperation := pending[0]
|
var (
|
||||||
groupedQueries := selectQueriesForTime(nextOperation.StartsAt(), pending)
|
nextOperation = pending[0]
|
||||||
|
groupedQueries = selectQueriesForTime(nextOperation.StartsAt(), pending)
|
||||||
|
)
|
||||||
|
|
||||||
out = optimizeTimeGroup(groupedQueries)
|
out = optimizeTimeGroup(groupedQueries)
|
||||||
pending = pending[len(groupedQueries):len(pending)]
|
pending = pending[len(groupedQueries):len(pending)]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue