mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 22:19:40 -08:00
Merge pull request #13085 from dimitarvdimitrov/dimitar/expose-findQueryMinMaxTime
Export `promql.FindMinMaxTime`
This commit is contained in:
commit
caec414964
|
@ -674,7 +674,7 @@ func durationMilliseconds(d time.Duration) int64 {
|
||||||
// execEvalStmt evaluates the expression of an evaluation statement for the given time range.
|
// execEvalStmt evaluates the expression of an evaluation statement for the given time range.
|
||||||
func (ng *Engine) execEvalStmt(ctx context.Context, query *query, s *parser.EvalStmt) (parser.Value, annotations.Annotations, error) {
|
func (ng *Engine) execEvalStmt(ctx context.Context, query *query, s *parser.EvalStmt) (parser.Value, annotations.Annotations, error) {
|
||||||
prepareSpanTimer, ctxPrepare := query.stats.GetSpanTimer(ctx, stats.QueryPreparationTime, ng.metrics.queryPrepareTime)
|
prepareSpanTimer, ctxPrepare := query.stats.GetSpanTimer(ctx, stats.QueryPreparationTime, ng.metrics.queryPrepareTime)
|
||||||
mint, maxt := ng.findMinMaxTime(s)
|
mint, maxt := FindMinMaxTime(s)
|
||||||
querier, err := query.queryable.Querier(mint, maxt)
|
querier, err := query.queryable.Querier(mint, maxt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
prepareSpanTimer.Finish()
|
prepareSpanTimer.Finish()
|
||||||
|
@ -816,7 +816,10 @@ func subqueryTimes(path []parser.Node) (time.Duration, time.Duration, *int64) {
|
||||||
return subqOffset, subqRange, tsp
|
return subqOffset, subqRange, tsp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ng *Engine) findMinMaxTime(s *parser.EvalStmt) (int64, int64) {
|
// FindMinMaxTime returns the time in milliseconds of the earliest and latest point in time the statement will try to process.
|
||||||
|
// This takes into account offsets, @ modifiers, and range selectors.
|
||||||
|
// If the statement does not select series, then FindMinMaxTime returns (0, 0).
|
||||||
|
func FindMinMaxTime(s *parser.EvalStmt) (int64, int64) {
|
||||||
var minTimestamp, maxTimestamp int64 = math.MaxInt64, math.MinInt64
|
var minTimestamp, maxTimestamp int64 = math.MaxInt64, math.MinInt64
|
||||||
// Whenever a MatrixSelector is evaluated, evalRange is set to the corresponding range.
|
// Whenever a MatrixSelector is evaluated, evalRange is set to the corresponding range.
|
||||||
// The evaluation of the VectorSelector inside then evaluates the given range and unsets
|
// The evaluation of the VectorSelector inside then evaluates the given range and unsets
|
||||||
|
@ -825,7 +828,7 @@ func (ng *Engine) findMinMaxTime(s *parser.EvalStmt) (int64, int64) {
|
||||||
parser.Inspect(s.Expr, func(node parser.Node, path []parser.Node) error {
|
parser.Inspect(s.Expr, func(node parser.Node, path []parser.Node) error {
|
||||||
switch n := node.(type) {
|
switch n := node.(type) {
|
||||||
case *parser.VectorSelector:
|
case *parser.VectorSelector:
|
||||||
start, end := ng.getTimeRangesForSelector(s, n, path, evalRange)
|
start, end := getTimeRangesForSelector(s, n, path, evalRange)
|
||||||
if start < minTimestamp {
|
if start < minTimestamp {
|
||||||
minTimestamp = start
|
minTimestamp = start
|
||||||
}
|
}
|
||||||
|
@ -848,7 +851,7 @@ func (ng *Engine) findMinMaxTime(s *parser.EvalStmt) (int64, int64) {
|
||||||
return minTimestamp, maxTimestamp
|
return minTimestamp, maxTimestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ng *Engine) getTimeRangesForSelector(s *parser.EvalStmt, n *parser.VectorSelector, path []parser.Node, evalRange time.Duration) (int64, int64) {
|
func getTimeRangesForSelector(s *parser.EvalStmt, n *parser.VectorSelector, path []parser.Node, evalRange time.Duration) (int64, int64) {
|
||||||
start, end := timestamp.FromTime(s.Start), timestamp.FromTime(s.End)
|
start, end := timestamp.FromTime(s.Start), timestamp.FromTime(s.End)
|
||||||
subqOffset, subqRange, subqTs := subqueryTimes(path)
|
subqOffset, subqRange, subqTs := subqueryTimes(path)
|
||||||
|
|
||||||
|
@ -905,7 +908,7 @@ func (ng *Engine) populateSeries(ctx context.Context, querier storage.Querier, s
|
||||||
parser.Inspect(s.Expr, func(node parser.Node, path []parser.Node) error {
|
parser.Inspect(s.Expr, func(node parser.Node, path []parser.Node) error {
|
||||||
switch n := node.(type) {
|
switch n := node.(type) {
|
||||||
case *parser.VectorSelector:
|
case *parser.VectorSelector:
|
||||||
start, end := ng.getTimeRangesForSelector(s, n, path, evalRange)
|
start, end := getTimeRangesForSelector(s, n, path, evalRange)
|
||||||
interval := ng.getLastSubqueryInterval(path)
|
interval := ng.getLastSubqueryInterval(path)
|
||||||
if interval == 0 {
|
if interval == 0 {
|
||||||
interval = s.Interval
|
interval = s.Interval
|
||||||
|
|
Loading…
Reference in a new issue