From e1cfc994f716ebdbc5104bee9aef18ea8d97af13 Mon Sep 17 00:00:00 2001 From: Brian Brazil Date: Wed, 19 Oct 2016 18:38:26 +0100 Subject: [PATCH] Correctly handle on() in alerts. (#2096) Fixes #2082 --- promql/printer.go | 2 +- promql/printer_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/promql/printer.go b/promql/printer.go index 21678a7d5..79141e06e 100644 --- a/promql/printer.go +++ b/promql/printer.go @@ -163,7 +163,7 @@ func (node *BinaryExpr) String() string { matching := "" vm := node.VectorMatching - if vm != nil && len(vm.MatchingLabels) > 0 { + if vm != nil && (len(vm.MatchingLabels) > 0 || vm.On) { if vm.On { matching = fmt.Sprintf(" ON(%s)", vm.MatchingLabels) } else { diff --git a/promql/printer_test.go b/promql/printer_test.go index 52e53245b..1715b54fc 100644 --- a/promql/printer_test.go +++ b/promql/printer_test.go @@ -59,6 +59,10 @@ func TestExprString(t *testing.T) { inputs := []struct { in, out string }{ + { + in: `sum(task:errors:rate10s{job="s"}) BY ()`, + out: `sum(task:errors:rate10s{job="s"})`, + }, { in: `sum(task:errors:rate10s{job="s"}) BY (code)`, }, @@ -77,6 +81,9 @@ func TestExprString(t *testing.T) { { in: `count_values("value", task:errors:rate10s{job="s"})`, }, + { + in: `a - ON() c`, + }, { in: `a - ON(b) c`, }, @@ -92,6 +99,10 @@ func TestExprString(t *testing.T) { { in: `a - IGNORING(b) c`, }, + { + in: `a - IGNORING() c`, + out: `a - c`, + }, { in: `up > BOOL 0`, },