Rename On to MatchingLabels
This commit is contained in:
parent
d991f0cf47
commit
7201c010c4
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue