diff --git a/promql/printer.go b/promql/printer.go index 785a14d4450..5d395bf6b58 100644 --- a/promql/printer.go +++ b/promql/printer.go @@ -109,7 +109,7 @@ func (node *AlertStmt) String() string { s += fmt.Sprintf("\n\tLABELS %s", node.Labels) } if len(node.Annotations) > 0 { - s += fmt.Sprintf("\n\tANNOTATIONS %s", node.Labels) + s += fmt.Sprintf("\n\tANNOTATIONS %s", node.Annotations) } return s } diff --git a/promql/printer_test.go b/promql/printer_test.go index c02e26ba602..eb60a95b79f 100644 --- a/promql/printer_test.go +++ b/promql/printer_test.go @@ -15,8 +15,43 @@ package promql import ( "testing" + "time" + + "github.com/prometheus/common/model" + "github.com/prometheus/prometheus/storage/metric" ) +func TestStatementString(t *testing.T) { + in := &AlertStmt{ + Name: "FooAlert", + Expr: &BinaryExpr{ + Op: itemGTR, + LHS: &VectorSelector{ + Name: "foo", + LabelMatchers: metric.LabelMatchers{ + {Type: metric.Equal, Name: model.MetricNameLabel, Value: "bar"}, + }, + }, + RHS: &NumberLiteral{10}, + }, + Duration: 5 * time.Minute, + Labels: model.LabelSet{"foo": "bar"}, + Annotations: model.LabelSet{ + "notify": "team-a", + }, + } + + expected := `ALERT FooAlert + IF foo > 10 + FOR 5m + LABELS {foo="bar"} + ANNOTATIONS {notify="team-a"}` + + if in.String() != expected { + t.Fatalf("expected:\n%s\ngot:\n%s\n", expected, in.String()) + } +} + func TestExprString(t *testing.T) { // A list of valid expressions that are expected to be // returned as out when calling String(). If out is empty the output