From b3f71df350bcbc80c08c49ec2d04908256fe6a16 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Sat, 24 Dec 2016 10:42:54 +0100 Subject: [PATCH] promql: make matrix exported --- promql/ast.go | 20 ++++++++++---------- promql/engine.go | 42 +++++++++++++++++++++--------------------- promql/functions.go | 26 +++++++++++++------------- promql/parse.go | 4 ++-- promql/test.go | 2 +- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/promql/ast.go b/promql/ast.go index 97009e59d3..7de36cc8df 100644 --- a/promql/ast.go +++ b/promql/ast.go @@ -98,12 +98,12 @@ type Expr interface { // Expressions is a list of expression nodes that implements Node. type Expressions []Expr -// AggregateExpr represents an aggregation operation on a vector. +// AggregateExpr represents an aggregation operation on a Vector. type AggregateExpr struct { Op itemType // The used aggregation operation. - Expr Expr // The vector expression over which is aggregated. + Expr Expr // The Vector expression over which is aggregated. Param Expr // Parameter used by some aggregators. - Grouping []string // The labels by which to group the vector. + Grouping []string // The labels by which to group the Vector. Without bool // Whether to drop the given labels rather than keep them. KeepCommonLabels bool // Whether to keep common labels among result elements. } @@ -113,7 +113,7 @@ type BinaryExpr struct { Op itemType // The operation of the expression. LHS, RHS Expr // The operands on the respective sides of the operator. - // The matching behavior for the operation if both operands are vectors. + // The matching behavior for the operation if both operands are Vectors. // If they are not this field is nil. VectorMatching *VectorMatching @@ -127,7 +127,7 @@ type Call struct { Args Expressions // Arguments used in the call. } -// MatrixSelector represents a matrix selection. +// MatrixSelector represents a Matrix selection. type MatrixSelector struct { Name string Range time.Duration @@ -162,7 +162,7 @@ type UnaryExpr struct { Expr Expr } -// VectorSelector represents a vector selection. +// VectorSelector represents a Vector selection. type VectorSelector struct { Name string Offset time.Duration @@ -199,7 +199,7 @@ func (*UnaryExpr) expr() {} func (*VectorSelector) expr() {} // VectorMatchCardinality describes the cardinality relationship -// of two vectors in a binary operation. +// of two Vectors in a binary operation. type VectorMatchCardinality int const ( @@ -223,13 +223,13 @@ func (vmc VectorMatchCardinality) String() string { panic("promql.VectorMatchCardinality.String: unknown match cardinality") } -// VectorMatching describes how elements from two vectors in a binary +// VectorMatching describes how elements from two Vectors in a binary // operation are supposed to be matched. type VectorMatching struct { - // The cardinality of the two vectors. + // The cardinality of the two Vectors. Card VectorMatchCardinality // MatchingLabels contains the labels which define equality of a pair of - // elements from the vectors. + // elements from the Vectors. MatchingLabels []string // On includes the given label names from matching, // rather than excluding them. diff --git a/promql/engine.go b/promql/engine.go index a50e29367c..7244a57e5d 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -50,7 +50,7 @@ type Value interface { String() string } -func (matrix) Type() ValueType { return ValueTypeMatrix } +func (Matrix) Type() ValueType { return ValueTypeMatrix } func (Vector) Type() ValueType { return ValueTypeVector } func (scalar) Type() ValueType { return ValueTypeScalar } func (stringVal) Type() ValueType { return ValueTypeString } @@ -63,7 +63,7 @@ const ( ValueTypeNone = "none" ValueTypeVector = "Vector" ValueTypeScalar = "scalar" - ValueTypeMatrix = "matrix" + ValueTypeMatrix = "Matrix" ValueTypeString = "string" ) @@ -127,11 +127,11 @@ func (vec Vector) String() string { return strings.Join(entries, "\n") } -// matrix is a slice of SampleStreams that implements sort.Interface and +// Matrix is a slice of SampleStreams that implements sort.Interface and // has a String method. -type matrix []sampleStream +type Matrix []sampleStream -func (m matrix) String() string { +func (m Matrix) String() string { // TODO(fabxc): sort, or can we rely on order from the querier? strs := make([]string, len(m)) @@ -162,13 +162,13 @@ func (r *Result) Vector() (Vector, error) { return v, nil } -// Matrix returns a matrix. An error is returned if -// the result was an error or the result value is not a matrix. -func (r *Result) Matrix() (matrix, error) { +// Matrix returns a Matrix. An error is returned if +// the result was an error or the result value is not a Matrix. +func (r *Result) Matrix() (Matrix, error) { if r.Err != nil { return nil, r.Err } - v, ok := r.Value.(matrix) + v, ok := r.Value.(Matrix) if !ok { return nil, fmt.Errorf("query result is not a range Vector") } @@ -509,7 +509,7 @@ func (ng *Engine) execEvalStmt(ctx context.Context, query *query, s *EvalStmt) ( } appendTimer := query.stats.GetTimer(stats.ResultAppendTime).Start() - mat := matrix{} + mat := Matrix{} for _, ss := range sampleStreams { mat = append(mat, ss) } @@ -519,7 +519,7 @@ func (ng *Engine) execEvalStmt(ctx context.Context, query *query, s *EvalStmt) ( return nil, err } - // Turn matrix type with protected metric into model.Matrix. + // Turn Matrix type with protected metric into model.Matrix. resMatrix := mat // TODO(fabxc): order ensured by storage? @@ -668,12 +668,12 @@ func (ev *evaluator) evalFloat(e Expr) float64 { return float64(sc.v) } -// evalMatrix attempts to evaluate e into a matrix and errors otherwise. +// evalMatrix attempts to evaluate e into a Matrix and errors otherwise. // The error message uses the term "range Vector" to match the user facing // documentation. -func (ev *evaluator) evalMatrix(e Expr) matrix { +func (ev *evaluator) evalMatrix(e Expr) Matrix { val := ev.eval(e) - mat, ok := val.(matrix) + mat, ok := val.(Matrix) if !ok { ev.errorf("expected range Vector but got %s", documentedType(val.Type())) } @@ -750,7 +750,7 @@ func (ev *evaluator) eval(expr Expr) Value { return e.Func.Call(ev, e.Args) case *MatrixSelector: - return ev.matrixSelector(e) + return ev.MatrixSelector(e) case *NumberLiteral: return scalar{v: e.Val, t: ev.Timestamp} @@ -815,13 +815,13 @@ func (ev *evaluator) VectorSelector(node *VectorSelector) Vector { return vec } -// matrixSelector evaluates a *MatrixSelector expression. -func (ev *evaluator) matrixSelector(node *MatrixSelector) matrix { +// MatrixSelector evaluates a *MatrixSelector expression. +func (ev *evaluator) MatrixSelector(node *MatrixSelector) Matrix { var ( offset = durationMilliseconds(node.Offset) maxt = ev.Timestamp - offset mint = maxt - durationMilliseconds(node.Range) - matrix = make(matrix, 0, len(node.series)) + Matrix = make(Matrix, 0, len(node.series)) ) for i, it := range node.iterators { @@ -851,9 +851,9 @@ func (ev *evaluator) matrixSelector(node *MatrixSelector) matrix { ss.Values = append(ss.Values, samplePair{t: t + offset, v: v}) } - matrix = append(matrix, ss) + Matrix = append(Matrix, ss) } - return matrix + return Matrix } func (ev *evaluator) VectorAnd(lhs, rhs Vector, matching *VectorMatching) Vector { @@ -1496,7 +1496,7 @@ func documentedType(t ValueType) string { switch t { case "Vector": return "instant Vector" - case "matrix": + case "Matrix": return "range Vector" default: return string(t) diff --git a/promql/functions.go b/promql/functions.go index c0e5e5cd97..bf5e4d0e3d 100644 --- a/promql/functions.go +++ b/promql/functions.go @@ -54,8 +54,8 @@ func extrapolatedRate(ev *evaluator, arg Expr, isCounter bool, isRate bool) Valu resultVector := Vector{} - matrixValue := ev.evalMatrix(ms) - for _, samples := range matrixValue { + MatrixValue := ev.evalMatrix(ms) + for _, samples := range MatrixValue { // No sense in trying to compute a rate without at least two points. Drop // this Vector element. if len(samples.Values) < 2 { @@ -125,7 +125,7 @@ func extrapolatedRate(ev *evaluator, arg Expr, isCounter bool, isRate bool) Valu return resultVector } -// === delta(matrix ValueTypeMatrix) Vector === +// === delta(Matrix ValueTypeMatrix) Vector === func funcDelta(ev *evaluator, args Expressions) Value { return extrapolatedRate(ev, args[0], false, false) } @@ -425,7 +425,7 @@ func aggrOverTime(ev *evaluator, args Expressions, aggrFn func([]samplePair) flo return resultVector } -// === avg_over_time(matrix ValueTypeMatrix) Vector === +// === avg_over_time(Matrix ValueTypeMatrix) Vector === func funcAvgOverTime(ev *evaluator, args Expressions) Value { return aggrOverTime(ev, args, func(values []samplePair) float64 { var sum float64 @@ -436,7 +436,7 @@ func funcAvgOverTime(ev *evaluator, args Expressions) Value { }) } -// === count_over_time(matrix ValueTypeMatrix) Vector === +// === count_over_time(Matrix ValueTypeMatrix) Vector === func funcCountOverTime(ev *evaluator, args Expressions) Value { return aggrOverTime(ev, args, func(values []samplePair) float64 { return float64(len(values)) @@ -453,7 +453,7 @@ func funcFloor(ev *evaluator, args Expressions) Value { return Vector } -// === max_over_time(matrix ValueTypeMatrix) Vector === +// === max_over_time(Matrix ValueTypeMatrix) Vector === func funcMaxOverTime(ev *evaluator, args Expressions) Value { return aggrOverTime(ev, args, func(values []samplePair) float64 { max := math.Inf(-1) @@ -464,7 +464,7 @@ func funcMaxOverTime(ev *evaluator, args Expressions) Value { }) } -// === min_over_time(matrix ValueTypeMatrix) Vector === +// === min_over_time(Matrix ValueTypeMatrix) Vector === func funcMinOverTime(ev *evaluator, args Expressions) Value { return aggrOverTime(ev, args, func(values []samplePair) float64 { min := math.Inf(1) @@ -475,7 +475,7 @@ func funcMinOverTime(ev *evaluator, args Expressions) Value { }) } -// === sum_over_time(matrix ValueTypeMatrix) Vector === +// === sum_over_time(Matrix ValueTypeMatrix) Vector === func funcSumOverTime(ev *evaluator, args Expressions) Value { return aggrOverTime(ev, args, func(values []samplePair) float64 { var sum float64 @@ -486,7 +486,7 @@ func funcSumOverTime(ev *evaluator, args Expressions) Value { }) } -// === quantile_over_time(matrix ValueTypeMatrix) Vector === +// === quantile_over_time(Matrix ValueTypeMatrix) Vector === func funcQuantileOverTime(ev *evaluator, args Expressions) Value { q := ev.evalFloat(args[0]) mat := ev.evalMatrix(args[1]) @@ -511,7 +511,7 @@ func funcQuantileOverTime(ev *evaluator, args Expressions) Value { return resultVector } -// === stddev_over_time(matrix ValueTypeMatrix) Vector === +// === stddev_over_time(Matrix ValueTypeMatrix) Vector === func funcStddevOverTime(ev *evaluator, args Expressions) Value { return aggrOverTime(ev, args, func(values []samplePair) float64 { var sum, squaredSum, count float64 @@ -525,7 +525,7 @@ func funcStddevOverTime(ev *evaluator, args Expressions) Value { }) } -// === stdvar_over_time(matrix ValueTypeMatrix) Vector === +// === stdvar_over_time(Matrix ValueTypeMatrix) Vector === func funcStdvarOverTime(ev *evaluator, args Expressions) Value { return aggrOverTime(ev, args, func(values []samplePair) float64 { var sum, squaredSum, count float64 @@ -745,7 +745,7 @@ func funcHistogramQuantile(ev *evaluator, args Expressions) Value { return outVec } -// === resets(matrix ValueTypeMatrix) Vector === +// === resets(Matrix ValueTypeMatrix) Vector === func funcResets(ev *evaluator, args Expressions) Value { in := ev.evalMatrix(args[0]) out := make(Vector, 0, len(in)) @@ -770,7 +770,7 @@ func funcResets(ev *evaluator, args Expressions) Value { return out } -// === changes(matrix ValueTypeMatrix) Vector === +// === changes(Matrix ValueTypeMatrix) Vector === func funcChanges(ev *evaluator, args Expressions) Value { in := ev.evalMatrix(args[0]) out := make(Vector, 0, len(in)) diff --git a/promql/parse.go b/promql/parse.go index b2e9e42fc6..27015a114b 100644 --- a/promql/parse.go +++ b/promql/parse.go @@ -531,7 +531,7 @@ func (p *parser) balance(lhs Expr, op itemType, rhs Expr, vecMatching *VectorMat // unaryExpr parses a unary expression. // -// | | (+|-) | '(' ')' +// | | (+|-) | '(' ')' // func (p *parser) unaryExpr() Expr { switch t := p.peek(); t.typ { @@ -583,7 +583,7 @@ func (p *parser) unaryExpr() Expr { return e } -// rangeSelector parses a matrix (a.k.a. range) selector based on a given +// rangeSelector parses a Matrix (a.k.a. range) selector based on a given // Vector selector. // // '[' ']' diff --git a/promql/test.go b/promql/test.go index cf25eaefce..424ce01c44 100644 --- a/promql/test.go +++ b/promql/test.go @@ -351,7 +351,7 @@ func (ev *evalCmd) expect(pos int, m labels.Labels, vals ...sequenceValue) { // compareResult compares the result value with the defined expectation. func (ev *evalCmd) compareResult(result Value) error { switch val := result.(type) { - case matrix: + case Matrix: if ev.instant { return fmt.Errorf("received range result on instant evaluation") }