diff --git a/promql/ast.go b/promql/ast.go index 5a7e24caf..35719afc2 100644 --- a/promql/ast.go +++ b/promql/ast.go @@ -228,9 +228,9 @@ func (vmc VectorMatchCardinality) String() string { type VectorMatching struct { // The cardinality of the two vectors. Card VectorMatchCardinality - // On contains the labels which define equality of a pair - // of elements from the vectors. - On model.LabelNames + // MatchingLabels contains the labels which define equality of a pair of + // elements from the vectors. + MatchingLabels model.LabelNames // Ignoring excludes the given label names from matching, // rather than only using them. Ignoring bool diff --git a/promql/engine.go b/promql/engine.go index 6d1148fe5..b0742ad8d 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -728,7 +728,7 @@ func (ev *evaluator) vectorAnd(lhs, rhs vector, matching *VectorMatching) vector if matching.Card != CardManyToMany { panic("set operations must only use many-to-many matching") } - sigf := signatureFunc(matching.Ignoring, matching.On...) + sigf := signatureFunc(matching.Ignoring, matching.MatchingLabels...) var result vector // The set of signatures for the right-hand side vector. @@ -751,7 +751,7 @@ func (ev *evaluator) vectorOr(lhs, rhs vector, matching *VectorMatching) vector if matching.Card != CardManyToMany { panic("set operations must only use many-to-many matching") } - sigf := signatureFunc(matching.Ignoring, matching.On...) + sigf := signatureFunc(matching.Ignoring, matching.MatchingLabels...) var result vector leftSigs := map[uint64]struct{}{} @@ -773,7 +773,7 @@ func (ev *evaluator) vectorUnless(lhs, rhs vector, matching *VectorMatching) vec if matching.Card != CardManyToMany { panic("set operations must only use many-to-many matching") } - sigf := signatureFunc(matching.Ignoring, matching.On...) + sigf := signatureFunc(matching.Ignoring, matching.MatchingLabels...) rightSigs := map[uint64]struct{}{} for _, rs := range rhs { @@ -796,7 +796,7 @@ func (ev *evaluator) vectorBinop(op itemType, lhs, rhs vector, matching *VectorM } var ( result = vector{} - sigf = signatureFunc(matching.Ignoring, matching.On...) + sigf = signatureFunc(matching.Ignoring, matching.MatchingLabels...) ) // The control flow below handles one-to-one or many-to-one matching. @@ -905,12 +905,12 @@ func resultMetric(lhs, rhs metric.Metric, op itemType, matching *VectorMatching) if shouldDropMetricName(op) { lhs.Del(model.MetricNameLabel) } - if len(matching.On)+len(matching.Include) == 0 { + if len(matching.MatchingLabels)+len(matching.Include) == 0 { return lhs } if matching.Ignoring { if matching.Card == CardOneToOne { - for _, l := range matching.On { + for _, l := range matching.MatchingLabels { lhs.Del(l) } } @@ -928,7 +928,7 @@ func resultMetric(lhs, rhs metric.Metric, op itemType, matching *VectorMatching) // As we definitely write, creating a new metric is the easiest solution. m := model.Metric{} if matching.Card == CardOneToOne { - for _, ln := range matching.On { + for _, ln := range matching.MatchingLabels { if v, ok := lhs.Metric[ln]; ok { m[ln] = v } diff --git a/promql/parse.go b/promql/parse.go index c4b055f37..79cd37aeb 100644 --- a/promql/parse.go +++ b/promql/parse.go @@ -467,7 +467,7 @@ func (p *parser) expr() Expr { vecMatching.Ignoring = true } p.next() - vecMatching.On = p.labels() + vecMatching.MatchingLabels = p.labels() // Parse grouping. if t := p.peek().typ; t == itemGroupLeft || t == itemGroupRight { @@ -483,7 +483,7 @@ func (p *parser) expr() Expr { } } - for _, ln := range vecMatching.On { + for _, ln := range vecMatching.MatchingLabels { for _, ln2 := range vecMatching.Include { if ln == ln2 && !vecMatching.Ignoring { p.errorf("label %q must not occur in ON and INCLUDE clause at once", ln) @@ -1052,7 +1052,7 @@ func (p *parser) checkType(node Node) (typ model.ValueType) { } if (lt != model.ValVector || rt != model.ValVector) && n.VectorMatching != nil { - if len(n.VectorMatching.On) > 0 { + if len(n.VectorMatching.MatchingLabels) > 0 { p.errorf("vector matching only allowed between vectors") } n.VectorMatching = nil diff --git a/promql/parse_test.go b/promql/parse_test.go index d7c5a4dab..94f06d7e0 100644 --- a/promql/parse_test.go +++ b/promql/parse_test.go @@ -469,14 +469,14 @@ var testExpr = []struct { }, }, VectorMatching: &VectorMatching{ - Card: CardOneToMany, - On: model.LabelNames{"baz", "buz"}, - Include: model.LabelNames{"test"}, + Card: CardOneToMany, + MatchingLabels: model.LabelNames{"baz", "buz"}, + Include: model.LabelNames{"test"}, }, }, VectorMatching: &VectorMatching{ - Card: CardOneToOne, - On: model.LabelNames{"foo"}, + Card: CardOneToOne, + MatchingLabels: model.LabelNames{"foo"}, }, }, }, { @@ -496,8 +496,8 @@ var testExpr = []struct { }, }, VectorMatching: &VectorMatching{ - Card: CardOneToOne, - On: model.LabelNames{"test", "blub"}, + Card: CardOneToOne, + MatchingLabels: model.LabelNames{"test", "blub"}, }, }, }, { @@ -517,8 +517,8 @@ var testExpr = []struct { }, }, VectorMatching: &VectorMatching{ - Card: CardManyToOne, - On: model.LabelNames{"test", "blub"}, + Card: CardManyToOne, + MatchingLabels: model.LabelNames{"test", "blub"}, }, }, }, { @@ -538,8 +538,8 @@ var testExpr = []struct { }, }, VectorMatching: &VectorMatching{ - Card: CardManyToMany, - On: model.LabelNames{"test", "blub"}, + Card: CardManyToMany, + MatchingLabels: model.LabelNames{"test", "blub"}, }, }, }, { @@ -559,9 +559,9 @@ var testExpr = []struct { }, }, VectorMatching: &VectorMatching{ - Card: CardManyToMany, - On: model.LabelNames{"test", "blub"}, - Ignoring: true, + Card: CardManyToMany, + MatchingLabels: model.LabelNames{"test", "blub"}, + Ignoring: true, }, }, }, { @@ -581,8 +581,8 @@ var testExpr = []struct { }, }, VectorMatching: &VectorMatching{ - Card: CardManyToMany, - On: model.LabelNames{"bar"}, + Card: CardManyToMany, + MatchingLabels: model.LabelNames{"bar"}, }, }, }, { @@ -602,9 +602,9 @@ var testExpr = []struct { }, }, VectorMatching: &VectorMatching{ - Card: CardManyToOne, - On: model.LabelNames{"test", "blub"}, - Include: model.LabelNames{"bar"}, + Card: CardManyToOne, + MatchingLabels: model.LabelNames{"test", "blub"}, + Include: model.LabelNames{"bar"}, }, }, }, { @@ -624,10 +624,10 @@ var testExpr = []struct { }, }, VectorMatching: &VectorMatching{ - Card: CardManyToOne, - On: model.LabelNames{"test", "blub"}, - Include: model.LabelNames{"blub"}, - Ignoring: true, + Card: CardManyToOne, + MatchingLabels: model.LabelNames{"test", "blub"}, + Include: model.LabelNames{"blub"}, + Ignoring: true, }, }, }, { @@ -647,10 +647,10 @@ var testExpr = []struct { }, }, VectorMatching: &VectorMatching{ - Card: CardManyToOne, - On: model.LabelNames{"test", "blub"}, - Include: model.LabelNames{"bar"}, - Ignoring: true, + Card: CardManyToOne, + MatchingLabels: model.LabelNames{"test", "blub"}, + Include: model.LabelNames{"bar"}, + Ignoring: true, }, }, }, { @@ -670,9 +670,9 @@ var testExpr = []struct { }, }, VectorMatching: &VectorMatching{ - Card: CardOneToMany, - On: model.LabelNames{"test", "blub"}, - Include: model.LabelNames{"bar", "foo"}, + Card: CardOneToMany, + MatchingLabels: model.LabelNames{"test", "blub"}, + Include: model.LabelNames{"bar", "foo"}, }, }, }, { @@ -692,10 +692,10 @@ var testExpr = []struct { }, }, VectorMatching: &VectorMatching{ - Card: CardOneToMany, - On: model.LabelNames{"test", "blub"}, - Include: model.LabelNames{"bar", "foo"}, - Ignoring: true, + Card: CardOneToMany, + MatchingLabels: model.LabelNames{"test", "blub"}, + Include: model.LabelNames{"bar", "foo"}, + Ignoring: true, }, }, }, { diff --git a/promql/printer.go b/promql/printer.go index 06b810b90..82ac53812 100644 --- a/promql/printer.go +++ b/promql/printer.go @@ -159,11 +159,11 @@ func (node *BinaryExpr) String() string { matching := "" vm := node.VectorMatching - if vm != nil && len(vm.On) > 0 { + if vm != nil && len(vm.MatchingLabels) > 0 { if vm.Ignoring { - matching = fmt.Sprintf(" IGNORING(%s)", vm.On) + matching = fmt.Sprintf(" IGNORING(%s)", vm.MatchingLabels) } else { - matching = fmt.Sprintf(" ON(%s)", vm.On) + matching = fmt.Sprintf(" ON(%s)", vm.MatchingLabels) } if vm.Card == CardManyToOne { matching += fmt.Sprintf(" GROUP_LEFT(%s)", vm.Include)