Correctly stringify GROUP_x modifiers without labels

Since rule evaluations work via String(), this fixes evaluation of
rules containing GROUP_x modifiers without labels. This change is the
minimal bugfix (so that we can release a fixed version without
risk). It does not intend to implement any additional features (like
allowing `GROUP_LEFT()` or `ON()` or even `ON` - see discussion in
https://github.com/prometheus/prometheus/issues/1597 ).
This commit is contained in:
beorn7 2016-05-28 19:45:35 +02:00
parent 9d616952b3
commit 5408666387
2 changed files with 19 additions and 5 deletions

View File

@ -165,11 +165,16 @@ func (node *BinaryExpr) String() string {
} else {
matching = fmt.Sprintf(" ON(%s)", vm.MatchingLabels)
}
if vm.Card == CardManyToOne {
matching += fmt.Sprintf(" GROUP_LEFT(%s)", vm.Include)
}
if vm.Card == CardOneToMany {
matching += fmt.Sprintf(" GROUP_RIGHT(%s)", vm.Include)
if vm.Card == CardManyToOne || vm.Card == CardOneToMany {
matching += " GROUP_"
if vm.Card == CardManyToOne {
matching += "LEFT"
} else {
matching += "RIGHT"
}
if len(vm.Include) > 0 {
matching += fmt.Sprintf("(%s)", vm.Include)
}
}
}
return fmt.Sprintf("%s %s%s%s %s", node.LHS, node.Op, returnBool, matching, node.RHS)

View File

@ -39,6 +39,15 @@ func TestExprString(t *testing.T) {
{
in: `a - ON(b) c`,
},
{
in: `a - ON(b) GROUP_LEFT(x) c`,
},
{
in: `a - ON(b) GROUP_LEFT(x, y) c`,
},
{
in: `a - ON(b) GROUP_LEFT c`,
},
{
in: `a - IGNORING(b) c`,
},