[v10.0.x] Alerting: Fix Alertmanager change detection for receivers with secure settings #71320
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport e3787de from #71307
Context
Previously,
ApplyAlertmanagerConfiguration
would decrypt and re-encrypt all secure settings. However, this caused re-encrypted secure settings to be included in the raw configuration when applied to the embedded alertmanager, resulting in changes to the hash. Consequently, even if no actual modifications were made, saving any alertmanager configuration triggered an apply/restart and created a new historical entry in the database.Backend
To address the issue, this modifies
ApplyAlertmanagerConfiguration
, which is called by POSTapi/alertmanager/grafana/config/api/v1/alerts
, to decrypt and re-encrypt only new and updated secure settings. Unchanged secure settings are loaded directly from the database without alteration.We determine whether secure settings have changed based on the following (already in-use) assumption: Only new or updated secure settings are provided via the POST
api/alertmanager/grafana/config/api/v1/alerts
request, while existing unchanged settings are omitted.Frontend
Previously, when saving a grafana-managed contact point, empty string values were transmitted for all unset secure settings. This would render the changes above less effective for notifiers that have optional secure fields since we would re-encrypt the empty string every time.
To address this, we now exclude empty
('', null, undefined)
secure settings, unless there was a pre-existing entry insecureFields
for that specific setting. In essence, this means we only transmit an empty secure setting if a previously configured value was cleared.Which issue(s) does this PR fix?:
Fixes #71219