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

Alerting: Fix provisioned templates being ignored by alertmanager #69485

Merged
merged 2 commits into from
Jun 2, 2023

Conversation

JacobsonMT
Copy link
Member

@JacobsonMT JacobsonMT commented Jun 2, 2023

Template provisioning sets the template in cfg.TemplateFiles while a recent change made it so that alertmanager reads cfg.AlertmanagerConfig.Templates instead.

This change fixes the issue on both ends, by having provisioning set boths fields and reverts the change on the alertmanager side so that it uses cfg.TemplateFiles.

Fixes: #69486

Template provisioning sets the template in cfg.TemplateFiles while a recent change
made it so that alertmanager reads cfg.AlertmanagerConfig.Templates instead.

This change fixes the issue on both ends, by having provisioning set boths fields and
reverts the change on the alertmanager side so that it uses cfg.TemplateFiles.
@@ -53,6 +53,7 @@ func (t *TemplateService) SetTemplate(ctx context.Context, orgID int64, tmpl def
revision.cfg.TemplateFiles = map[string]string{}
}
revision.cfg.TemplateFiles[tmpl.Name] = tmpl.Template
revision.cfg.AlertmanagerConfig.Templates = append(revision.cfg.AlertmanagerConfig.Templates, tmpl.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

This will also append each time a provisioned template is updated:

curl -H "Content-Type: application/json" -u admin:admin http://127.0.0.1:3000/api/v1/provisioning/templates/test -X PUT -d '{"name":"test","template":"hello1"}'
curl -H "Content-Type: application/json" -u admin:admin http://127.0.0.1:3000/api/v1/provisioning/templates/test -X PUT -d '{"name":"test","template":"hello2"}'
"templates": [
  "test",
  "test"
],

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess we might as well overwrite cfg.AlertmanagerConfig.Templates here with the current state of TemplateFiles since we'll do it during applyConfig anyways, WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I think so! I've noticed that sometimes deleted templates are removed from template_files and not templates, so it should fix both!

Copy link
Contributor

Choose a reason for hiding this comment

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

What's the relationship between this and cfg.AlertmanagerConfig.Templates = paths on Line 269 of pkg/services/ngalert/notifier/alertmanager.go.

Copy link
Member Author

Choose a reason for hiding this comment

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

This change is not technically required since we now do the same thing in pkg/services/ngalert/notifier/alertmanager.go, figured we might preempt future issues by just making this do both anyways. I can remove it if that's the preference.

Copy link
Contributor

@alexweav alexweav left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@grobinson-grafana grobinson-grafana left a comment

Choose a reason for hiding this comment

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

I tested this in:

  • Grafana 9.5.2 ✅
  • This branch with broken AM configuration (provisioned template missing from templates) ✅
  • This branch with fixed AM configuration (provisioned template now present in templates) ✅

@JacobsonMT JacobsonMT merged commit c16f1f5 into main Jun 2, 2023
11 checks passed
@JacobsonMT JacobsonMT deleted the jacobsonmt/fix_provisioned_templates branch June 2, 2023 19:47
@grafanabot
Copy link
Contributor

The backport to v10.0.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new branch
git switch --create backport-69485-to-v10.0.x origin/v10.0.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x c16f1f5e99def9e0136170605368ab33e31e80a1
# Push it to GitHub
git push --set-upstream origin backport-69485-to-v10.0.x
git switch main
# Remove the local backport branch
git branch -D backport-69485-to-v10.0.x

Then, create a pull request where the base branch is v10.0.x and the compare/head branch is backport-69485-to-v10.0.x.

@grafanabot grafanabot added the backport-failed Failed to generate backport PR. Please resolve conflicts and create one manually. label Jun 2, 2023
JacobsonMT added a commit that referenced this pull request Jun 2, 2023
…9485)

* Alerting: Fix provisioned templates being ignored by alertmanager

Template provisioning sets the template in cfg.TemplateFiles while a recent change
made it so that alertmanager reads cfg.AlertmanagerConfig.Templates instead.

This change fixes the issue on both ends, by having provisioning set boths fields and
reverts the change on the alertmanager side so that it uses cfg.TemplateFiles.

(cherry picked from commit c16f1f5)
JacobsonMT added a commit that referenced this pull request Jun 2, 2023
…anager (#69488)

Alerting: Fix provisioned templates being ignored by alertmanager (#69485)

* Alerting: Fix provisioned templates being ignored by alertmanager

Template provisioning sets the template in cfg.TemplateFiles while a recent change
made it so that alertmanager reads cfg.AlertmanagerConfig.Templates instead.

This change fixes the issue on both ends, by having provisioning set boths fields and
reverts the change on the alertmanager side so that it uses cfg.TemplateFiles.

(cherry picked from commit c16f1f5)
@zerok zerok modified the milestones: 10.0.x, 10.0.1, 10.1.x Jun 20, 2023
zerok pushed a commit that referenced this pull request Jun 22, 2023
…anager (#69488)

Alerting: Fix provisioned templates being ignored by alertmanager (#69485)

* Alerting: Fix provisioned templates being ignored by alertmanager

Template provisioning sets the template in cfg.TemplateFiles while a recent change
made it so that alertmanager reads cfg.AlertmanagerConfig.Templates instead.

This change fixes the issue on both ends, by having provisioning set boths fields and
reverts the change on the alertmanager side so that it uses cfg.TemplateFiles.

(cherry picked from commit c16f1f5)
(cherry picked from commit 0a6e80c)
@ricky-undeadcoders ricky-undeadcoders modified the milestones: 10.1.x, 10.1.0 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to changelog area/backend backport v10.0.x backport-failed Failed to generate backport PR. Please resolve conflicts and create one manually. type/bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Alerting: Provisioned Notification templates no longer work in Grafana 10
6 participants