From 2a41843a5c3de1f4579cae85fe12d8c94314cf2a Mon Sep 17 00:00:00 2001 From: Gilles De Mey Date: Fri, 12 May 2023 17:45:03 +0200 Subject: [PATCH] Alerting: Omit "description" and "summary" from default email template annotations (#68122) (#68189) * Alerting: Omit "description" and "summary" from default email template annotations (#68122) (cherry picked from commit 720b5b3b6515c72f98c957b2f2c9bbc4aedec7e5) Co-authored-by: Matthew Jacobson --- .../partials/alerting/instance_details.mjml | 111 +++++------------- pkg/services/ngalert/notifier/email_test.go | 8 +- public/emails/ng_alert_notification.html | 88 ++++---------- 3 files changed, 61 insertions(+), 146 deletions(-) diff --git a/emails/templates/partials/alerting/instance_details.mjml b/emails/templates/partials/alerting/instance_details.mjml index 26a4bbd7856..458124dd974 100644 --- a/emails/templates/partials/alerting/instance_details.mjml +++ b/emails/templates/partials/alerting/instance_details.mjml @@ -1,71 +1,47 @@ - - {{ if .ImageURL }} - +{{ if .ImageURL }} - - {{ end }} - +{{ end }} - - {{ if .EmbeddedImage }} - +{{ if .EmbeddedImage }} - - {{ end }} - +{{ end }} - - {{ if .Annotations.summary }} - + {{ if .Annotations.summary }} Summary - - {{- .Annotations.summary -}} - - - {{ end }} - + {{- .Annotations.summary -}} + {{ end }} - - {{ if .Annotations.description }} - + {{ if .Annotations.description }} Description - - {{ range $line := (splitList "\n" .Annotations.description) }} - + {{ range $line := (splitList "\n" .Annotations.description) }} {{ $line }}
- - {{ end }} - + {{ end }}
- - {{ end }} - + {{ end }}
- - {{ if .Values }} - +{{ if .Values }} @@ -76,80 +52,56 @@ - - {{ range $refID, $value := .Values }} - + {{ range $refID, $value := .Values }} {{ $refID }}={{ $value }}  - - {{ end }} - + {{ end }} - - {{ end }} - +{{ end }} - - {{ if .Labels.SortedPairs }} - + {{ if .Labels.SortedPairs }} Labels - - {{ range .Labels.SortedPairs }} - + {{ range .Labels.SortedPairs }} {{ .Name }} - - {{ .Value }} - + {{ .Value }} - - {{ end }} - + {{ end }} - - {{ end }} - + {{ end }} - - - {{ if .Annotations.SortedPairs }} - + + {{ if (without .Annotations.SortedPairs.Names "description" "summary") }} Annotations - - {{ range .Annotations.SortedPairs }} - + {{ range .Annotations.SortedPairs }} + {{ if and (ne .Name "description") (ne .Name "summary") }} {{ .Name }} - - {{ .Value }} - + {{ .Value }} - - {{ end }} - + {{ end }} + {{ end }} - - {{ end }} - + {{ end }} @@ -178,9 +130,7 @@ {{ end }} {{ if .PanelURL }} - - View panel - + View panel {{ end }} @@ -189,7 +139,8 @@ - Observed {{ ago .StartsAt }} before this notification was delivered, at {{ .StartsAt }} + Observed {{ ago .StartsAt }} before this notification was delivered, at + {{ .StartsAt }} diff --git a/pkg/services/ngalert/notifier/email_test.go b/pkg/services/ngalert/notifier/email_test.go index 7bcd66a10a2..6bbae47a275 100644 --- a/pkg/services/ngalert/notifier/email_test.go +++ b/pkg/services/ngalert/notifier/email_test.go @@ -112,11 +112,11 @@ func TestEmailNotifierIntegration(t *testing.T) { expSnippets: []string{ "2 firing instances", "severity", - "warning\n", - "critical\n", + "warning", + "critical", "alertname", - "FiringTwo\n", - "FiringOne\n", + "FiringTwo", + "FiringOne", "
- - {{ range $line := (splitList "\n" .Annotations.description) }} - + {{ range $line := (splitList "\n" .Annotations.description) }} {{ $line }}
- - {{ end }} - + {{ end }}
@@ -533,12 +529,8 @@
- - {{ range $refID, $value := .Values }} - - {{ $refID }}={{ $value }}  - {{ end }} - + {{ range $refID, $value := .Values }} + {{ $refID }}={{ $value }}  {{ end }}
@@ -576,24 +568,18 @@ - - {{ range .Labels.SortedPairs }} - + {{ range .Labels.SortedPairs }} - + - - {{ end }} - + {{ end }}
{{ .Name }} - {{ .Value }} - {{ .Value }}
- {{ end }}{{ if .Annotations.SortedPairs }} + {{ end }}{{ if (without .Annotations.SortedPairs.Names "description" "summary") }}
Annotations
@@ -602,20 +588,16 @@ - - {{ range .Annotations.SortedPairs }} - + {{ range .Annotations.SortedPairs }} + {{ if and (ne .Name "description") (ne .Name "summary") }} - + - - {{ end }} - + {{ end }} + {{ end }}
{{ .Name }} - {{ .Value }} - {{ .Value }}
@@ -979,13 +961,9 @@
- - {{ range $line := (splitList "\n" .Annotations.description) }} - + {{ range $line := (splitList "\n" .Annotations.description) }} {{ $line }}
- - {{ end }} - + {{ end }}
@@ -1042,12 +1020,8 @@
- - {{ range $refID, $value := .Values }} - - {{ $refID }}={{ $value }}  - {{ end }} - + {{ range $refID, $value := .Values }} + {{ $refID }}={{ $value }}  {{ end }}
@@ -1085,24 +1059,18 @@ - - {{ range .Labels.SortedPairs }} - + {{ range .Labels.SortedPairs }} - + - - {{ end }} - + {{ end }}
{{ .Name }} - {{ .Value }} - {{ .Value }}
- {{ end }}{{ if .Annotations.SortedPairs }} + {{ end }}{{ if (without .Annotations.SortedPairs.Names "description" "summary") }}
Annotations
@@ -1111,20 +1079,16 @@ - - {{ range .Annotations.SortedPairs }} - + {{ range .Annotations.SortedPairs }} + {{ if and (ne .Name "description") (ne .Name "summary") }} - + - - {{ end }} - + {{ end }} + {{ end }}
{{ .Name }} - {{ .Value }} - {{ .Value }}