diff --git a/app/vmalert/alerting.go b/app/vmalert/alerting.go index 3f629dab46..7cfe1076ad 100644 --- a/app/vmalert/alerting.go +++ b/app/vmalert/alerting.go @@ -159,11 +159,11 @@ func (ar *AlertingRule) toLabels(m datasource.Metric, qFn templates.QueryFn) (*l processed: make(map[string]string), } for _, l := range m.Labels { + ls.origin[l.Name] = l.Value // drop __name__ to be consistent with Prometheus alerting if l.Name == "__name__" { continue } - ls.origin[l.Name] = l.Value ls.processed[l.Name] = l.Value } diff --git a/app/vmalert/alerting_test.go b/app/vmalert/alerting_test.go index ab5be63923..2e4c231ed1 100644 --- a/app/vmalert/alerting_test.go +++ b/app/vmalert/alerting_test.go @@ -731,14 +731,14 @@ func TestAlertingRule_Template(t *testing.T) { "instance": "{{ $labels.instance }}", }, Annotations: map[string]string{ - "summary": `Too high connection number for "{{ $labels.instance }}"`, + "summary": `{{ $labels.__name__ }}: Too high connection number for "{{ $labels.instance }}"`, "description": `{{ $labels.alertname}}: It is {{ $value }} connections for "{{ $labels.instance }}"`, }, alerts: make(map[uint64]*notifier.Alert), }, []datasource.Metric{ - metricWithValueAndLabels(t, 2, "instance", "foo", alertNameLabel, "override"), - metricWithValueAndLabels(t, 10, "instance", "bar", alertNameLabel, "override"), + metricWithValueAndLabels(t, 2, "__name__", "first", "instance", "foo", alertNameLabel, "override"), + metricWithValueAndLabels(t, 10, "__name__", "second", "instance", "bar", alertNameLabel, "override"), }, map[uint64]*notifier.Alert{ hash(map[string]string{alertNameLabel: "override label", "instance": "foo"}): { @@ -747,7 +747,7 @@ func TestAlertingRule_Template(t *testing.T) { "instance": "foo", }, Annotations: map[string]string{ - "summary": `Too high connection number for "foo"`, + "summary": `first: Too high connection number for "foo"`, "description": `override: It is 2 connections for "foo"`, }, }, @@ -757,7 +757,7 @@ func TestAlertingRule_Template(t *testing.T) { "instance": "bar", }, Annotations: map[string]string{ - "summary": `Too high connection number for "bar"`, + "summary": `second: Too high connection number for "bar"`, "description": `override: It is 10 connections for "bar"`, }, },