Rename to generateMatrix

Rename evaluator.expandSeriesToMatrix into generateMatrix, while also dropping
the start, end, interval arguments since they are evaluator fields.
Write more extensive method documentation.

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Arve Knudsen 2024-09-13 10:28:54 +02:00
parent 96845f9b66
commit f6bf3b7a0d

View file

@ -1457,9 +1457,12 @@ func (ev *evaluator) rangeEvalAgg(ctx context.Context, aggExpr *parser.Aggregate
return result, warnings return result, warnings
} }
// expandSeriesToMatrix expands vs.Series into a Matrix. // generateMatrix generates a Matrix between ev.startTimestamp and ev.endTimestamp (inclusive), each point spaced ev.interval apart, from vs.
func (ev *evaluator) expandSeriesToMatrix(ctx context.Context, vs *parser.VectorSelector, start, end, interval int64) Matrix { // For every series iterator in vs.Series, the method iterates in ev.interval sized steps from ev.startTimestamp until and including ev.endTimestamp,
numSteps := int((end-start)/interval) + 1 // collecting every corresponding sample (obtained via ev.vectorSelectorSingle) into a Series.
// All of the generated Series are collected into a Matrix, that gets returned.
func (ev *evaluator) generateMatrix(ctx context.Context, vs *parser.VectorSelector) Matrix {
numSteps := int((ev.endTimestamp-ev.startTimestamp)/ev.interval) + 1
mat := make(Matrix, 0, len(vs.Series)) mat := make(Matrix, 0, len(vs.Series))
var prevSS *Series var prevSS *Series
@ -1476,7 +1479,7 @@ func (ev *evaluator) expandSeriesToMatrix(ctx context.Context, vs *parser.Vector
Metric: s.Labels(), Metric: s.Labels(),
} }
for ts, step := start, -1; ts <= end; ts += interval { for ts, step := ev.startTimestamp, -1; ts <= ev.endTimestamp; ts += ev.interval {
step++ step++
_, f, h, ok := ev.vectorSelectorSingle(it, vs, ts) _, f, h, ok := ev.vectorSelectorSingle(it, vs, ts)
if !ok { if !ok {
@ -1955,7 +1958,7 @@ func (ev *evaluator) eval(ctx context.Context, expr parser.Expr) (parser.Value,
if err != nil { if err != nil {
ev.error(errWithWarnings{fmt.Errorf("expanding series: %w", err), ws}) ev.error(errWithWarnings{fmt.Errorf("expanding series: %w", err), ws})
} }
mat := ev.expandSeriesToMatrix(ctx, e, ev.startTimestamp, ev.endTimestamp, ev.interval) mat := ev.generateMatrix(ctx, e)
return mat, ws return mat, ws
case *parser.MatrixSelector: case *parser.MatrixSelector: