Skip to content
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: Use the default email sender for Grafana receivers #8529

Merged
merged 7 commits into from
Jul 2, 2024

Conversation

santihernandezc
Copy link
Contributor

@santihernandezc santihernandezc commented Jun 26, 2024

This PR updates the Alertmanager to use the default email sender from grafana/alerting for sending notifications with Grafana's email integration.

If the Grafana Alertmanager configuration is to be used, we use the SMTP and HTTP settings from the global section of Mimir's Alertmanager configuration to configure the email sender.

Related PoC: #8376

@grobinson-grafana
Copy link
Contributor

Just a heads up that the build and tests will fail until #8525 is merged to main and you can rebase. I'm working to get a second review of it as soon as possible.

vendor/github.com/grafana/alerting/notify/silences.go:101:12: assignment mismatch: 1 variable but am.silences.Set returns 2 values
vendor/github.com/grafana/alerting/notify/silences.go:122:12: assignment mismatch: 1 variable but am.silences.Upsert returns 2 values) (typecheck)

@grobinson-grafana
Copy link
Contributor

Just a heads up that the build and tests will fail until #8525 is merged to main and you can rebase. I'm working to get a second review of it as soon as possible.

vendor/github.com/grafana/alerting/notify/silences.go:101:12: assignment mismatch: 1 variable but am.silences.Set returns 2 values
vendor/github.com/grafana/alerting/notify/silences.go:122:12: assignment mismatch: 1 variable but am.silences.Upsert returns 2 values) (typecheck)

Hi! 👋 You can rebase main as #8525 is closed. This will fix the build failure and tests 👍

@santihernandezc santihernandezc marked this pull request as ready for review June 27, 2024 13:01
"github.com/grafana/mimir/pkg/alertmanager/alertspb"
)

// parseGrafanaConfig creates an AlertConfigDesc from a GrafanaAlertConfigDesc.
func parseGrafanaConfig(cfg alertspb.GrafanaAlertConfigDesc) (alertspb.AlertConfigDesc, error) {
// It uses the global section from the Mimir config if it is provided.
func parseGrafanaConfig(gCfg alertspb.GrafanaAlertConfigDesc, mCfg *alertspb.AlertConfigDesc) (alertspb.AlertConfigDesc, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think parseGrafanaConfig is a suitable name anymore, something like parseConfig might be more appropriate?

@@ -708,14 +708,14 @@ func (am *MultitenantAlertmanager) computeConfig(cfgs alertspb.AlertConfigDescs)
// Grafana configuration.
case cfgs.Mimir.RawConfig == am.fallbackConfig:
level.Debug(am.logger).Log("msg", "mimir configuration is default, using grafana config", "user", cfgs.Mimir.User)
cfg, err = parseGrafanaConfig(cfgs.Grafana)
cfg, err = parseGrafanaConfig(cfgs.Grafana, &cfgs.Mimir)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd also update the log message above

@@ -394,7 +395,7 @@ templates:
require.Len(t, am.alertmanagers, 4)

// The Mimir configuration was empty, so the Grafana configuration should be chosen for user 4.
parsed, err := parseGrafanaConfig(userGrafanaCfg)
parsed, err := parseGrafanaConfig(userGrafanaCfg, nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this isn't directly to do with this PR, but just a code quality change:

require.NoError(t, store.SetAlertConfig(ctx, emptyMimirConfig))

can be done on line 391 above.

},
expCfg: alertspb.AlertConfigDesc{
User: "user",
RawConfig: string(simpleConfigOne),
Copy link
Contributor

Choose a reason for hiding this comment

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

simpleConfigOne doesn't need to be casted to string

@santihernandezc santihernandezc merged commit 6d8bdcf into main Jul 2, 2024
29 checks passed
@santihernandezc santihernandezc deleted the santihernandezc/use_default_email_sender branch July 2, 2024 14:02
Ivaka pushed a commit to Ivaka/mimir that referenced this pull request Jul 3, 2024
…fana#8529)

* Alertmanager: Use the default email sender for Grafana receivers

* tests, fix mimir global config not being used in Grafana

* address code review comments

* format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants