-
Notifications
You must be signed in to change notification settings - Fork 603
Alertmanager: Allow for custom SMTP configs in Grafana email integrations #11755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alertmanager: Allow for custom SMTP configs in Grafana email integrations #11755
Conversation
f578c66
to
9c008d6
Compare
6f30434
to
ffc7169
Compare
ffc7169
to
60925a0
Compare
…custom_smtp_config_remote_am
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a few suggestions.
integration/alertmanager_test.go
Outdated
"Header-1": "Value-1", | ||
"Header-2": "Value-2", | ||
smtpConfig := &alertmanager.SmtpConfig{ | ||
FromAddress: "test@test.com", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FromAddress: "test@test.com", | |
FromAddress: "test@example.com", |
pkg/alertmanager/config_test.go
Outdated
@@ -75,76 +76,170 @@ const grafanaConfigWithDuplicateReceiverName = `{ | |||
}` | |||
|
|||
func TestCreateUsableGrafanaConfig(t *testing.T) { | |||
defaultFromAddress := "grafana@localhost.com" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addresses in tests probably shouldn't use real domains except for example.com
or localhost.
pkg/alertmanager/api_grafana_test.go
Outdated
@@ -199,8 +199,11 @@ func TestMultitenantAlertmanager_GetUserGrafanaConfig(t *testing.T) { | |||
logger: test.NewTestingLogger(t), | |||
} | |||
|
|||
smtpConfig := &alertspb.SmtpConfig{ | |||
FromAddress: "test@grafana.com", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FromAddress: "test@grafana.com", | |
FromAddress: "test@example.com", |
pkg/alertmanager/config.go
Outdated
|
||
// Patch the base config with the custom SMTP config sent by Grafana. | ||
if gCfg.SmtpConfig != nil { | ||
s := gCfg.SmtpConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I get that this is more concise but I think the code is easier to read using the full gCfg.SmtpConfig
instead of s
Description
Grafana users can tweak their SMTP settings to customize how Grafana sends emails. However, when enabling the remote Alertmanager in remote primary mode, Mimir sends all email notifications, and any SMTP settings in Grafana are ignored.
This PR makes Mimir use SMTP settings configured in Grafana (except for those related to files) when using the remote Alertmanager feature.
How it works
When the remote Alertmanager feature is enabled, Grafana sends its SMTP settings over to Mimir. These SMTP settings are stored in object storage alongside the configuration.
When an Alertmanager is created for the Grafana tenant, any non-empty SMTP settings are used to patch the base
EmailSenderConfig
. Grafana email integrations use this patched configuration to send notifications.Note for reviewers
We've added
StaticHeaders
andSmtpFrom
fields in the past. These are now part ofSmtpConfig
.Commit aed46ac has changes to test this PR locally using read-write mode.