From 6ac39700ead8d40b5394db51528e50992955a47d Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Fri, 15 Apr 2016 19:48:17 +0200 Subject: [PATCH] Fix missing printed keep_common without grouping. --- promql/printer.go | 8 ++++---- promql/printer_test.go | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/promql/printer.go b/promql/printer.go index e35699d7d..748d77461 100644 --- a/promql/printer.go +++ b/promql/printer.go @@ -143,10 +143,10 @@ func (node *AggregateExpr) String() string { } else { format = "%s BY (%s)" } - if node.KeepExtraLabels { - format += " KEEP_COMMON" - } - return fmt.Sprintf(format, aggrString, node.Grouping) + aggrString = fmt.Sprintf(format, aggrString, node.Grouping) + } + if node.KeepExtraLabels { + aggrString += " KEEP_COMMON" } return aggrString } diff --git a/promql/printer_test.go b/promql/printer_test.go index 890adc661..29b275e0b 100644 --- a/promql/printer_test.go +++ b/promql/printer_test.go @@ -30,6 +30,9 @@ func TestExprString(t *testing.T) { { in: `sum(task:errors:rate10s{job="s"}) BY (code) KEEP_COMMON`, }, + { + in: `sum(task:errors:rate10s{job="s"}) KEEP_COMMON`, + }, { in: `sum(task:errors:rate10s{job="s"}) WITHOUT (instance)`, },