Init work

This commit is contained in:
Jesus Vazquez 2024-06-20 12:54:51 +02:00
parent 6572b1fe63
commit 3eacd094a0
No known key found for this signature in database
GPG key ID: E2492C7B8442A95B
5 changed files with 85 additions and 19 deletions

View file

@ -685,6 +685,9 @@ func durationMilliseconds(d time.Duration) int64 {
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)
mint, maxt := FindMinMaxTime(s)
// metric[5m] + metric[5m] offset 5m
// mint -10m (-5m - 5m offset)
// maxt now()
querier, err := query.queryable.Querier(mint, maxt)
if err != nil {
prepareSpanTimer.Finish()
@ -2171,6 +2174,15 @@ func (ev *evaluator) matrixSelector(node *parser.MatrixSelector) (Matrix, annota
it = storage.NewBuffer(durationMilliseconds(node.Range))
)
// TODO Test for case where range of 1ms
if node.OpenLeft {
mint += 1
}
if node.OpenRight {
maxt -= 1
}
ws, err := checkAndExpandSeriesSet(ev.ctx, node)
if err != nil {
ev.error(errWithWarnings{fmt.Errorf("expanding series: %w", err), ws})

View file

@ -73,7 +73,7 @@ func extrapolatedRate(vals []parser.Value, args parser.Expressions, enh *EvalNod
var (
samples = vals[0].(Matrix)[0]
rangeStart = enh.Ts - durationMilliseconds(ms.Range+vs.Offset)
rangeEnd = enh.Ts - durationMilliseconds(vs.Offset)
rangeEnd = enh.Ts - durationMilliseconds(vs.Offset) // TODO Open this in the vector selector
resultFloat float64
resultHistogram *histogram.FloatHistogram
firstT, lastT int64

View file

@ -126,6 +126,9 @@ type MatrixSelector struct {
VectorSelector Expr
Range time.Duration
OpenLeft bool
OpenRight bool
EndPos posrange.Pos
}

View file

@ -28,22 +28,23 @@ import (
%}
%union {
node Node
item Item
matchers []*labels.Matcher
matcher *labels.Matcher
label labels.Label
labels labels.Labels
lblList []labels.Label
strings []string
series []SequenceValue
histogram *histogram.FloatHistogram
descriptors map[string]interface{}
bucket_set []float64
int int64
uint uint64
float float64
duration time.Duration
node Node
item Item
matchers []*labels.Matcher
matcher *labels.Matcher
label labels.Label
labels labels.Labels
lblList []labels.Label
strings []string
series []SequenceValue
histogram *histogram.FloatHistogram
descriptors map[string]interface{}
bucket_set []float64
int int64
uint uint64
float float64
duration time.Duration
range_duration rangeDuration
}
@ -449,7 +450,7 @@ at_modifier_preprocessors: START | END;
* Subquery and range selectors.
*/
matrix_selector : expr LEFT_BRACKET duration RIGHT_BRACKET
matrix_selector : expr LEFT_BRACKET range_duration RIGHT_BRACKET
{
var errMsg string
vs, ok := $1.(*VectorSelector)
@ -468,7 +469,9 @@ matrix_selector : expr LEFT_BRACKET duration RIGHT_BRACKET
$$ = &MatrixSelector{
VectorSelector: $1.(Expr),
Range: $3,
Range: $3.duration,
OpenLeft: $3.openLeft,
OpenRight: $3.openRight,
EndPos: yylex.(*parser).lastClosing,
}
}
@ -899,6 +902,47 @@ duration : DURATION
}
;
range_duration : DURATION
{
var err error
$$.duration, err = parseDuration($1.Val)
if err != nil {
yylex.(*parser).addParseErr($1.PositionRange(), err)
}
}
| POW DURATION
{
var err error
$$.duration, err = parseDuration($1.Val)
if err != nil {
yylex.(*parser).addParseErr($1.PositionRange(), err)
}
$$.openLeft = true
}
| DURATION POW
{
var err error
$$.duration, err = parseDuration($1.Val)
if err != nil {
yylex.(*parser).addParseErr($1.PositionRange(), err)
}
$$.openRight = true
}
| POW DURATION POW
{
var err error
$$.duration, err = parseDuration($1.Val)
if err != nil {
yylex.(*parser).addParseErr($1.PositionRange(), err)
}
$$.openLeft = true
$$.openRight = true
}
;
string_literal : STRING
{

View file

@ -16,6 +16,7 @@ package parser
import (
"fmt"
"strings"
"time"
"unicode"
"unicode/utf8"
@ -1000,3 +1001,9 @@ func isLabel(s string) bool {
}
return true
}
type rangeDuration struct {
duration time.Duration
openLeft bool
openRight bool
}