diff --git a/promql/printer.go b/promql/printer.go index 82ac53812..d8b8a58c7 100644 --- a/promql/printer.go +++ b/promql/printer.go @@ -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) diff --git a/promql/printer_test.go b/promql/printer_test.go index e17774ac8..c02e26ba6 100644 --- a/promql/printer_test.go +++ b/promql/printer_test.go @@ -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`, },