mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Flip vector matching to be ignoring by default.
This is a noop semantically.
This commit is contained in:
parent
d431187f77
commit
246a817300
|
@ -231,9 +231,9 @@ type VectorMatching struct {
|
|||
// 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
|
||||
// On includes the given label names from matching,
|
||||
// rather than excluding them.
|
||||
On bool
|
||||
// Include contains additional labels that should be included in
|
||||
// the result from the side with the lower cardinality.
|
||||
Include model.LabelNames
|
||||
|
|
|
@ -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.MatchingLabels...)
|
||||
sigf := signatureFunc(matching.On, 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.MatchingLabels...)
|
||||
sigf := signatureFunc(matching.On, 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.MatchingLabels...)
|
||||
sigf := signatureFunc(matching.On, 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.MatchingLabels...)
|
||||
sigf = signatureFunc(matching.On, matching.MatchingLabels...)
|
||||
)
|
||||
|
||||
// The control flow below handles one-to-one or many-to-one matching.
|
||||
|
@ -883,8 +883,8 @@ func (ev *evaluator) vectorBinop(op itemType, lhs, rhs vector, matching *VectorM
|
|||
|
||||
// signatureFunc returns a function that calculates the signature for a metric
|
||||
// based on the provided labels. If ignoring, then the given labels are ignored instead.
|
||||
func signatureFunc(ignoring bool, labels ...model.LabelName) func(m metric.Metric) uint64 {
|
||||
if len(labels) == 0 || ignoring {
|
||||
func signatureFunc(on bool, labels ...model.LabelName) func(m metric.Metric) uint64 {
|
||||
if len(labels) == 0 || !on {
|
||||
return func(m metric.Metric) uint64 {
|
||||
tmp := m.Metric.Clone()
|
||||
for _, l := range labels {
|
||||
|
@ -908,7 +908,7 @@ func resultMetric(lhs, rhs metric.Metric, op itemType, matching *VectorMatching)
|
|||
if len(matching.MatchingLabels)+len(matching.Include) == 0 {
|
||||
return lhs
|
||||
}
|
||||
if matching.Ignoring {
|
||||
if !matching.On {
|
||||
if matching.Card == CardOneToOne {
|
||||
for _, l := range matching.MatchingLabels {
|
||||
lhs.Del(l)
|
||||
|
|
|
@ -463,8 +463,8 @@ func (p *parser) expr() Expr {
|
|||
|
||||
// Parse ON/IGNORING clause.
|
||||
if p.peek().typ == itemOn || p.peek().typ == itemIgnoring {
|
||||
if p.peek().typ == itemIgnoring {
|
||||
vecMatching.Ignoring = true
|
||||
if p.peek().typ == itemOn {
|
||||
vecMatching.On = true
|
||||
}
|
||||
p.next()
|
||||
vecMatching.MatchingLabels = p.labels()
|
||||
|
@ -485,7 +485,7 @@ func (p *parser) expr() Expr {
|
|||
|
||||
for _, ln := range vecMatching.MatchingLabels {
|
||||
for _, ln2 := range vecMatching.Include {
|
||||
if ln == ln2 && !vecMatching.Ignoring {
|
||||
if ln == ln2 && vecMatching.On {
|
||||
p.errorf("label %q must not occur in ON and GROUP clause at once", ln)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -471,12 +471,14 @@ var testExpr = []struct {
|
|||
VectorMatching: &VectorMatching{
|
||||
Card: CardOneToMany,
|
||||
MatchingLabels: model.LabelNames{"baz", "buz"},
|
||||
On: true,
|
||||
Include: model.LabelNames{"test"},
|
||||
},
|
||||
},
|
||||
VectorMatching: &VectorMatching{
|
||||
Card: CardOneToOne,
|
||||
MatchingLabels: model.LabelNames{"foo"},
|
||||
On: true,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
|
@ -498,6 +500,7 @@ var testExpr = []struct {
|
|||
VectorMatching: &VectorMatching{
|
||||
Card: CardOneToOne,
|
||||
MatchingLabels: model.LabelNames{"test", "blub"},
|
||||
On: true,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
|
@ -519,6 +522,7 @@ var testExpr = []struct {
|
|||
VectorMatching: &VectorMatching{
|
||||
Card: CardManyToOne,
|
||||
MatchingLabels: model.LabelNames{"test", "blub"},
|
||||
On: true,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
|
@ -540,6 +544,7 @@ var testExpr = []struct {
|
|||
VectorMatching: &VectorMatching{
|
||||
Card: CardManyToMany,
|
||||
MatchingLabels: model.LabelNames{"test", "blub"},
|
||||
On: true,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
|
@ -561,7 +566,6 @@ var testExpr = []struct {
|
|||
VectorMatching: &VectorMatching{
|
||||
Card: CardManyToMany,
|
||||
MatchingLabels: model.LabelNames{"test", "blub"},
|
||||
Ignoring: true,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
|
@ -583,6 +587,7 @@ var testExpr = []struct {
|
|||
VectorMatching: &VectorMatching{
|
||||
Card: CardManyToMany,
|
||||
MatchingLabels: model.LabelNames{"bar"},
|
||||
On: true,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
|
@ -604,6 +609,7 @@ var testExpr = []struct {
|
|||
VectorMatching: &VectorMatching{
|
||||
Card: CardManyToOne,
|
||||
MatchingLabels: model.LabelNames{"test", "blub"},
|
||||
On: true,
|
||||
Include: model.LabelNames{"bar"},
|
||||
},
|
||||
},
|
||||
|
@ -627,7 +633,6 @@ var testExpr = []struct {
|
|||
Card: CardManyToOne,
|
||||
MatchingLabels: model.LabelNames{"test", "blub"},
|
||||
Include: model.LabelNames{"blub"},
|
||||
Ignoring: true,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
|
@ -650,7 +655,6 @@ var testExpr = []struct {
|
|||
Card: CardManyToOne,
|
||||
MatchingLabels: model.LabelNames{"test", "blub"},
|
||||
Include: model.LabelNames{"bar"},
|
||||
Ignoring: true,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
|
@ -673,6 +677,7 @@ var testExpr = []struct {
|
|||
Card: CardOneToMany,
|
||||
MatchingLabels: model.LabelNames{"test", "blub"},
|
||||
Include: model.LabelNames{"bar", "foo"},
|
||||
On: true,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
|
@ -695,7 +700,6 @@ var testExpr = []struct {
|
|||
Card: CardOneToMany,
|
||||
MatchingLabels: model.LabelNames{"test", "blub"},
|
||||
Include: model.LabelNames{"bar", "foo"},
|
||||
Ignoring: true,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
|
|
|
@ -160,10 +160,10 @@ func (node *BinaryExpr) String() string {
|
|||
matching := ""
|
||||
vm := node.VectorMatching
|
||||
if vm != nil && len(vm.MatchingLabels) > 0 {
|
||||
if vm.Ignoring {
|
||||
matching = fmt.Sprintf(" IGNORING(%s)", vm.MatchingLabels)
|
||||
} else {
|
||||
if vm.On {
|
||||
matching = fmt.Sprintf(" ON(%s)", vm.MatchingLabels)
|
||||
} else {
|
||||
matching = fmt.Sprintf(" IGNORING(%s)", vm.MatchingLabels)
|
||||
}
|
||||
if vm.Card == CardManyToOne || vm.Card == CardOneToMany {
|
||||
matching += " GROUP_"
|
||||
|
|
Loading…
Reference in a new issue