Rename On to MatchingLabels

pull/1571/head
Brian Brazil 9 years ago
parent d991f0cf47
commit 7201c010c4

@ -228,9 +228,9 @@ func (vmc VectorMatchCardinality) String() string {
type VectorMatching struct { type VectorMatching struct {
// The cardinality of the two vectors. // The cardinality of the two vectors.
Card VectorMatchCardinality Card VectorMatchCardinality
// On contains the labels which define equality of a pair // MatchingLabels contains the labels which define equality of a pair of
// of elements from the vectors. // elements from the vectors.
On model.LabelNames MatchingLabels model.LabelNames
// Ignoring excludes the given label names from matching, // Ignoring excludes the given label names from matching,
// rather than only using them. // rather than only using them.
Ignoring bool Ignoring bool

@ -728,7 +728,7 @@ func (ev *evaluator) vectorAnd(lhs, rhs vector, matching *VectorMatching) vector
if matching.Card != CardManyToMany { if matching.Card != CardManyToMany {
panic("set operations must only use many-to-many matching") 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 var result vector
// The set of signatures for the right-hand side 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 { if matching.Card != CardManyToMany {
panic("set operations must only use many-to-many matching") 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 var result vector
leftSigs := map[uint64]struct{}{} leftSigs := map[uint64]struct{}{}
@ -773,7 +773,7 @@ func (ev *evaluator) vectorUnless(lhs, rhs vector, matching *VectorMatching) vec
if matching.Card != CardManyToMany { if matching.Card != CardManyToMany {
panic("set operations must only use many-to-many matching") 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{}{} rightSigs := map[uint64]struct{}{}
for _, rs := range rhs { for _, rs := range rhs {
@ -796,7 +796,7 @@ func (ev *evaluator) vectorBinop(op itemType, lhs, rhs vector, matching *VectorM
} }
var ( var (
result = vector{} 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. // 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) { if shouldDropMetricName(op) {
lhs.Del(model.MetricNameLabel) lhs.Del(model.MetricNameLabel)
} }
if len(matching.On)+len(matching.Include) == 0 { if len(matching.MatchingLabels)+len(matching.Include) == 0 {
return lhs return lhs
} }
if matching.Ignoring { if matching.Ignoring {
if matching.Card == CardOneToOne { if matching.Card == CardOneToOne {
for _, l := range matching.On { for _, l := range matching.MatchingLabels {
lhs.Del(l) 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. // As we definitely write, creating a new metric is the easiest solution.
m := model.Metric{} m := model.Metric{}
if matching.Card == CardOneToOne { if matching.Card == CardOneToOne {
for _, ln := range matching.On { for _, ln := range matching.MatchingLabels {
if v, ok := lhs.Metric[ln]; ok { if v, ok := lhs.Metric[ln]; ok {
m[ln] = v m[ln] = v
} }

@ -467,7 +467,7 @@ func (p *parser) expr() Expr {
vecMatching.Ignoring = true vecMatching.Ignoring = true
} }
p.next() p.next()
vecMatching.On = p.labels() vecMatching.MatchingLabels = p.labels()
// Parse grouping. // Parse grouping.
if t := p.peek().typ; t == itemGroupLeft || t == itemGroupRight { 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 { for _, ln2 := range vecMatching.Include {
if ln == ln2 && !vecMatching.Ignoring { if ln == ln2 && !vecMatching.Ignoring {
p.errorf("label %q must not occur in ON and INCLUDE clause at once", ln) 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 (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") p.errorf("vector matching only allowed between vectors")
} }
n.VectorMatching = nil n.VectorMatching = nil

@ -469,14 +469,14 @@ var testExpr = []struct {
}, },
}, },
VectorMatching: &VectorMatching{ VectorMatching: &VectorMatching{
Card: CardOneToMany, Card: CardOneToMany,
On: model.LabelNames{"baz", "buz"}, MatchingLabels: model.LabelNames{"baz", "buz"},
Include: model.LabelNames{"test"}, Include: model.LabelNames{"test"},
}, },
}, },
VectorMatching: &VectorMatching{ VectorMatching: &VectorMatching{
Card: CardOneToOne, Card: CardOneToOne,
On: model.LabelNames{"foo"}, MatchingLabels: model.LabelNames{"foo"},
}, },
}, },
}, { }, {
@ -496,8 +496,8 @@ var testExpr = []struct {
}, },
}, },
VectorMatching: &VectorMatching{ VectorMatching: &VectorMatching{
Card: CardOneToOne, Card: CardOneToOne,
On: model.LabelNames{"test", "blub"}, MatchingLabels: model.LabelNames{"test", "blub"},
}, },
}, },
}, { }, {
@ -517,8 +517,8 @@ var testExpr = []struct {
}, },
}, },
VectorMatching: &VectorMatching{ VectorMatching: &VectorMatching{
Card: CardManyToOne, Card: CardManyToOne,
On: model.LabelNames{"test", "blub"}, MatchingLabels: model.LabelNames{"test", "blub"},
}, },
}, },
}, { }, {
@ -538,8 +538,8 @@ var testExpr = []struct {
}, },
}, },
VectorMatching: &VectorMatching{ VectorMatching: &VectorMatching{
Card: CardManyToMany, Card: CardManyToMany,
On: model.LabelNames{"test", "blub"}, MatchingLabels: model.LabelNames{"test", "blub"},
}, },
}, },
}, { }, {
@ -559,9 +559,9 @@ var testExpr = []struct {
}, },
}, },
VectorMatching: &VectorMatching{ VectorMatching: &VectorMatching{
Card: CardManyToMany, Card: CardManyToMany,
On: model.LabelNames{"test", "blub"}, MatchingLabels: model.LabelNames{"test", "blub"},
Ignoring: true, Ignoring: true,
}, },
}, },
}, { }, {
@ -581,8 +581,8 @@ var testExpr = []struct {
}, },
}, },
VectorMatching: &VectorMatching{ VectorMatching: &VectorMatching{
Card: CardManyToMany, Card: CardManyToMany,
On: model.LabelNames{"bar"}, MatchingLabels: model.LabelNames{"bar"},
}, },
}, },
}, { }, {
@ -602,9 +602,9 @@ var testExpr = []struct {
}, },
}, },
VectorMatching: &VectorMatching{ VectorMatching: &VectorMatching{
Card: CardManyToOne, Card: CardManyToOne,
On: model.LabelNames{"test", "blub"}, MatchingLabels: model.LabelNames{"test", "blub"},
Include: model.LabelNames{"bar"}, Include: model.LabelNames{"bar"},
}, },
}, },
}, { }, {
@ -624,10 +624,10 @@ var testExpr = []struct {
}, },
}, },
VectorMatching: &VectorMatching{ VectorMatching: &VectorMatching{
Card: CardManyToOne, Card: CardManyToOne,
On: model.LabelNames{"test", "blub"}, MatchingLabels: model.LabelNames{"test", "blub"},
Include: model.LabelNames{"blub"}, Include: model.LabelNames{"blub"},
Ignoring: true, Ignoring: true,
}, },
}, },
}, { }, {
@ -647,10 +647,10 @@ var testExpr = []struct {
}, },
}, },
VectorMatching: &VectorMatching{ VectorMatching: &VectorMatching{
Card: CardManyToOne, Card: CardManyToOne,
On: model.LabelNames{"test", "blub"}, MatchingLabels: model.LabelNames{"test", "blub"},
Include: model.LabelNames{"bar"}, Include: model.LabelNames{"bar"},
Ignoring: true, Ignoring: true,
}, },
}, },
}, { }, {
@ -670,9 +670,9 @@ var testExpr = []struct {
}, },
}, },
VectorMatching: &VectorMatching{ VectorMatching: &VectorMatching{
Card: CardOneToMany, Card: CardOneToMany,
On: model.LabelNames{"test", "blub"}, MatchingLabels: model.LabelNames{"test", "blub"},
Include: model.LabelNames{"bar", "foo"}, Include: model.LabelNames{"bar", "foo"},
}, },
}, },
}, { }, {
@ -692,10 +692,10 @@ var testExpr = []struct {
}, },
}, },
VectorMatching: &VectorMatching{ VectorMatching: &VectorMatching{
Card: CardOneToMany, Card: CardOneToMany,
On: model.LabelNames{"test", "blub"}, MatchingLabels: model.LabelNames{"test", "blub"},
Include: model.LabelNames{"bar", "foo"}, Include: model.LabelNames{"bar", "foo"},
Ignoring: true, Ignoring: true,
}, },
}, },
}, { }, {

@ -159,11 +159,11 @@ func (node *BinaryExpr) String() string {
matching := "" matching := ""
vm := node.VectorMatching vm := node.VectorMatching
if vm != nil && len(vm.On) > 0 { if vm != nil && len(vm.MatchingLabels) > 0 {
if vm.Ignoring { if vm.Ignoring {
matching = fmt.Sprintf(" IGNORING(%s)", vm.On) matching = fmt.Sprintf(" IGNORING(%s)", vm.MatchingLabels)
} else { } else {
matching = fmt.Sprintf(" ON(%s)", vm.On) matching = fmt.Sprintf(" ON(%s)", vm.MatchingLabels)
} }
if vm.Card == CardManyToOne { if vm.Card == CardManyToOne {
matching += fmt.Sprintf(" GROUP_LEFT(%s)", vm.Include) matching += fmt.Sprintf(" GROUP_LEFT(%s)", vm.Include)

Loading…
Cancel
Save