Skip to content

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

Merged
merged 16 commits into from
Jun 25, 2025

Conversation

santihernandezc
Copy link
Contributor

@santihernandezc santihernandezc commented Jun 16, 2025

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 and SmtpFrom fields in the past. These are now part of SmtpConfig.

Commit aed46ac has changes to test this PR locally using read-write mode.

@santihernandezc santihernandezc requested review from a team as code owners June 16, 2025 16:27
@santihernandezc santihernandezc marked this pull request as draft June 16, 2025 16:27
@santihernandezc santihernandezc force-pushed the santihernandezc/custom_smtp_config_remote_am branch from f578c66 to 9c008d6 Compare June 16, 2025 18:48
@santihernandezc santihernandezc added the changelog-not-needed PRs that don't need a CHANGELOG.md entry label Jun 17, 2025
@santihernandezc santihernandezc force-pushed the santihernandezc/custom_smtp_config_remote_am branch 3 times, most recently from 6f30434 to ffc7169 Compare June 17, 2025 19:20
@santihernandezc santihernandezc force-pushed the santihernandezc/custom_smtp_config_remote_am branch from ffc7169 to 60925a0 Compare June 17, 2025 19:25
@santihernandezc santihernandezc marked this pull request as ready for review June 18, 2025 17:50
@santihernandezc santihernandezc changed the title (WIP) Alertmanager: Allow for custom SMTP configs in Grafana email integrations Alertmanager: Allow for custom SMTP configs in Grafana email integrations Jun 18, 2025
Copy link
Contributor

@56quarters 56quarters left a 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.

"Header-1": "Value-1",
"Header-2": "Value-2",
smtpConfig := &alertmanager.SmtpConfig{
FromAddress: "test@test.com",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
FromAddress: "test@test.com",
FromAddress: "test@example.com",

@@ -75,76 +76,170 @@ const grafanaConfigWithDuplicateReceiverName = `{
}`

func TestCreateUsableGrafanaConfig(t *testing.T) {
defaultFromAddress := "grafana@localhost.com"
Copy link
Contributor

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.

@@ -199,8 +199,11 @@ func TestMultitenantAlertmanager_GetUserGrafanaConfig(t *testing.T) {
logger: test.NewTestingLogger(t),
}

smtpConfig := &alertspb.SmtpConfig{
FromAddress: "test@grafana.com",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
FromAddress: "test@grafana.com",
FromAddress: "test@example.com",


// Patch the base config with the custom SMTP config sent by Grafana.
if gCfg.SmtpConfig != nil {
s := gCfg.SmtpConfig
Copy link
Contributor

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

@santihernandezc santihernandezc enabled auto-merge (squash) June 25, 2025 20:33
@santihernandezc santihernandezc merged commit e0019f4 into main Jun 25, 2025
31 checks passed
@santihernandezc santihernandezc deleted the santihernandezc/custom_smtp_config_remote_am branch June 25, 2025 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog-not-needed PRs that don't need a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants