promql: Fix annotations conflated with labels

When converting `AlertStmt` to a string, the alert rule labels were
printed as `ANNOTATIONS` instead of the annotations themselves.

Fix and add a test to catch future regressions.
This commit is contained in:
Matt Bostock 2016-07-01 10:39:17 +01:00
parent 33759dddd2
commit cc98e164d3
2 changed files with 36 additions and 1 deletions

View File

@ -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
}

View File

@ -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