grafana/pkg/services/ngalert/store
Matthew Jacobson 0c688190f7
Alerting: Fix unique violation when updating rule group with title chains/cycles (#67868)
* Alerting: Fix unique violation when updating rule group with title chains/cycles

The uniqueness constraint for titles within an org+folder is enforced on every update within a transaction instead of on commit (deferred constraint). This means that there could be a set of updates that will throw a unique constraint violation in an intermediate step even though the final state is valid. For example, a chain of updates RuleA -> RuleB -> RuleC could fail if not executed in the correct order, or a swap of titles RuleA <-> RuleB cannot be executed in any order without violating the constraint.

The exact solution to this is complex and requires determining directed paths and cycles in the update graph, adding in temporary updates to break cycles, and then executing the updates in reverse topological order (see first commit in PR if curious).

This is not implemented here.

Instead, we choose a simpler solution that works in all cases but might perform more updates than necessary. This simpler solution makes a determination of whether an intermediate collision could occur and if so, adds a temporary title on all updated rules to break any cycles and remove the need for specific ordering.

In addition, we make sure diffs are executed in the following order: DELETES, UPDATES, INSERTS.
2023-06-08 18:51:50 -04:00
..
admin_configuration_store_mock.go Chore: Fix goimports grouping in alerting (#62424) 2023-01-30 09:55:35 +01:00
admin_configuration.go chore: remove sqlstore & mockstore dependencies from (most) packages (#57087) 2022-10-19 09:02:15 -04:00
alert_rule_test.go Alerting: Fix unique violation when updating rule group with title chains/cycles (#67868) 2023-06-08 18:51:50 -04:00
alert_rule.go Alerting: Fix unique violation when updating rule group with title chains/cycles (#67868) 2023-06-08 18:51:50 -04:00
alertmanager_test.go Alerting: Add endpoint to revert to a previous alertmanager configuration (#65751) 2023-04-05 14:10:03 -04:00
alertmanager.go Alerting: Add endpoint to revert to a previous alertmanager configuration (#65751) 2023-04-05 14:10:03 -04:00
database.go Nested folders: Add alert rule counts and deletion to folder registry (#67259) 2023-06-02 16:38:02 +02:00
deltas_test.go Alerting: Allow alert rule pausing from API (#62326) 2023-02-01 13:15:03 +01:00
deltas.go Chore: Remove result fields from ngalert (#65410) 2023-03-28 10:34:35 +02:00
image_test.go Alerting: Use URLs in image annotations (#66804) 2023-04-26 13:06:18 -03:00
image.go Revert "Alerting: Refactor the ImageStore/Provider to provide image URL/bytes" (#69265) 2023-05-30 11:33:33 -05:00
instance_database_test.go Alerting: Remove and revert flag alertingBigTransactions (#65976) 2023-04-06 18:06:25 +02:00
instance_database.go Alerting: Remove and revert flag alertingBigTransactions (#65976) 2023-04-06 18:06:25 +02:00
org.go chore: remove sqlstore & mockstore dependencies from (most) packages (#57087) 2022-10-19 09:02:15 -04:00
provisioning_store_test.go Chore: Fix goimports grouping in alerting (#62424) 2023-01-30 09:55:35 +01:00
provisioning_store.go chore: remove sqlstore & mockstore dependencies from (most) packages (#57087) 2022-10-19 09:02:15 -04:00
testing.go Nested folders: Add alert rule counts and deletion to folder registry (#67259) 2023-06-02 16:38:02 +02:00
transactions.go Alerting: Provisioning API - Notification Policies (#46755) 2022-04-05 16:48:51 -05:00