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

Use grafana URL to test receivers #9125

Merged
merged 5 commits into from
Sep 6, 2024

Conversation

titolins
Copy link
Contributor

Fixes https://github.com/grafana/alerting-squad/issues/872

As described, alerts should use the Grafana URL instead of the remote AM's. For regular alert notifications this was already done, this PR fixes for tests

@titolins titolins requested review from a team as code owners August 28, 2024 13:27
@CLAassistant
Copy link

CLAassistant commented Aug 28, 2024

CLA assistant check
All committers have signed the CLA.

@titolins titolins force-pushed the titolins/use_grafana_url_on_templates branch from 38bd360 to 7b6cbe8 Compare August 28, 2024 13:44
Copy link
Contributor

@santihernandezc santihernandezc left a comment

Choose a reason for hiding this comment

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

Nice one! A few comments.

@@ -92,6 +92,7 @@ type Config struct {
Retention time.Duration
MaxConcurrentGetRequestsPerTenant int
ExternalURL *url.URL
TmplExternalURL *url.URL
Copy link
Contributor

Choose a reason for hiding this comment

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

This new field is not "config" in the same sense as the other fields in the struct, i.e. global config taken from a YAML file and applied to all Alertmanagers.

I think the Alertmanager struct would be a better fit for this field (you could add tmplExternalURL here).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it! Changed it now 👍

@@ -901,6 +901,7 @@ func (am *MultitenantAlertmanager) newAlertmanager(userID string, amConfig *defi
Retention: am.cfg.Retention,
MaxConcurrentGetRequestsPerTenant: am.cfg.MaxConcurrentGetRequestsPerTenant,
ExternalURL: am.cfg.ExternalURL.URL,
TmplExternalURL: tmplExternalURL,
Copy link
Contributor

Choose a reason for hiding this comment

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

The external URL can change when a new config is applied. For example, consider the following scenario:

  1. A user has no Grafana configuration, they are using Mimir's external URL
  2. They upload some Grafana configuration, they should be using Grafana's external URL

We should assign the correct external URL on every config sync (check here, we're updating the templates in the Alertmanager struct, we could use the same lock to update the external URL).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah, ofc.. I missed the else and presumed a new instance would be built every time. Tks, fixed now 👍

@titolins titolins force-pushed the titolins/use_grafana_url_on_templates branch from b91b073 to 66c1ca4 Compare August 30, 2024 16:18
Copy link
Contributor

@santihernandezc santihernandezc left a comment

Choose a reason for hiding this comment

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

I just tested it, it works as expected, nice job! 🎉
Please address my comment, once that's fixed you can merge the PR. I don't need to re-review it.

@@ -191,7 +192,7 @@ type Replicator interface {
}

// New creates a new Alertmanager.
func New(cfg *Config, reg *prometheus.Registry) (*Alertmanager, error) {
func New(cfg *Config, reg *prometheus.Registry, tmplExternalURL *url.URL) (*Alertmanager, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're already passing the URL in ApplyConfig(), we can skip adding a new parameter here. On the initial sync (right after the Alertmanager is created), the AM will get the correct URL to be used when testing receivers.

I'd remove this new parameter.

Copy link
Contributor Author

@titolins titolins Sep 5, 2024

Choose a reason for hiding this comment

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

Ah, good catch! Removed now 👍

@titolins titolins force-pushed the titolins/use_grafana_url_on_templates branch from af62cde to a113290 Compare September 5, 2024 15:03
@santihernandezc santihernandezc merged commit b9da4d0 into main Sep 6, 2024
29 checks passed
@santihernandezc santihernandezc deleted the titolins/use_grafana_url_on_templates branch September 6, 2024 12:20
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