cmd/promtool: fix panic with empty exp_labels

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
Simon Pasquier 2019-07-17 17:02:31 +02:00
parent abdcbda82a
commit 75886e0464
1 changed files with 3 additions and 0 deletions

View File

@ -286,6 +286,9 @@ func (tg *testGroup) test(mint, maxt time.Time, evalInterval time.Duration, grou
for _, a := range testcase.ExpAlerts { for _, a := range testcase.ExpAlerts {
// User gives only the labels from alerting rule, which doesn't // User gives only the labels from alerting rule, which doesn't
// include this label (added by Prometheus during Eval). // include this label (added by Prometheus during Eval).
if a.ExpLabels == nil {
a.ExpLabels = make(map[string]string)
}
a.ExpLabels[labels.AlertName] = testcase.Alertname a.ExpLabels[labels.AlertName] = testcase.Alertname
expAlerts = append(expAlerts, labelAndAnnotation{ expAlerts = append(expAlerts, labelAndAnnotation{