From 6fc88d4b4d7f477c4331382c9d71055c8db2a951 Mon Sep 17 00:00:00 2001 From: Brian Brazil Date: Mon, 1 Aug 2016 23:32:01 +0100 Subject: [PATCH] Remove __name__ from alerts sent to AM. Fixes #1861 --- rules/alerting.go | 3 +-- rules/manager_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/rules/alerting.go b/rules/alerting.go index 2930ec937..f28ffa289 100644 --- a/rules/alerting.go +++ b/rules/alerting.go @@ -198,6 +198,7 @@ func (r *AlertingRule) eval(ts model.Time, engine *promql.Engine, externalURLPat return model.LabelValue(result) } + delete(smpl.Metric, model.MetricNameLabel) labels := make(model.LabelSet, len(smpl.Metric)+len(r.labels)+1) for ln, lv := range smpl.Metric { labels[ln] = lv @@ -219,8 +220,6 @@ func (r *AlertingRule) eval(ts model.Time, engine *promql.Engine, externalURLPat continue } - delete(smpl.Metric, model.MetricNameLabel) - r.active[fp] = &Alert{ Labels: labels, Annotations: annotations, diff --git a/rules/manager_test.go b/rules/manager_test.go index 9c18ff53e..dfee078d7 100644 --- a/rules/manager_test.go +++ b/rules/manager_test.go @@ -136,6 +136,12 @@ func TestAlertingRule(t *testing.T) { t.Errorf("%d. Expected and actual outputs don't match:", i) t.Fatalf("Expected:\n%v\n----\nActual:\n%v", strings.Join(expected, "\n"), strings.Join(actual, "\n")) } + + for _, aa := range rule.ActiveAlerts() { + if _, ok := aa.Labels[model.MetricNameLabel]; ok { + t.Fatalf("%s label set on active alert: %s", model.MetricNameLabel, aa.Labels) + } + } } }