grafana/pkg/services/ngalert/provisioning
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
..
alert_rules_test.go Alerting: Fix unique violation when updating rule group with title chains/cycles (#67868) 2023-06-08 18:51:50 -04:00
alert_rules.go Alerting: Fix unique violation when updating rule group with title chains/cycles (#67868) 2023-06-08 18:51:50 -04:00
compat.go Alerting: Update alerting module to 20230418161049-5f374e58cb32 + refactoring (#66622) 2023-04-25 13:39:46 -04:00
config.go Chore: Remove result fields from ngalert (#65410) 2023-03-28 10:34:35 +02:00
contactpoints_test.go Alerting: Fix panic when reparenting receivers to groups following an attempted rename via Provisioning (#67167) 2023-04-24 21:23:23 -04:00
contactpoints.go Alerting: Update alerting module to 20230418161049-5f374e58cb32 + refactoring (#66622) 2023-04-25 13:39:46 -04:00
errors.go Alerting: Code-gen parsing of URL parameters and fix related bugs (#50731) 2022-06-23 15:13:39 -05:00
mute_timings_test.go Chore: Remove result fields from ngalert (#65410) 2023-03-28 10:34:35 +02:00
mute_timings.go Alerting: decouple api models from domain\dto models: separate Provenance status + converters (#63594) 2023-02-27 17:57:15 -05:00
notification_policies_test.go Chore: Remove result fields from ngalert (#65410) 2023-03-28 10:34:35 +02:00
notification_policies.go Chore: Remove result fields from ngalert (#65410) 2023-03-28 10:34:35 +02:00
persist_mock.go Plugins: Improve instrumentation by adding metrics and tracing (#61035) 2023-03-28 11:01:06 +02:00
persist.go Chore: Remove result fields from ngalert (#65410) 2023-03-28 10:34:35 +02:00
provenance.go Alerting: Allow provenance disable in alerting provisioning API (#63650) 2023-04-18 15:10:36 +02:00
provisioning_store_mock.go Chore: Fix goimports grouping in alerting (#62424) 2023-01-30 09:55:35 +01:00
quota_checker_mock.go Chore: Fix goimports grouping in alerting (#62424) 2023-01-30 09:55:35 +01:00
templates_test.go Chore: Remove result fields from ngalert (#65410) 2023-03-28 10:34:35 +02:00
templates.go Alerting: Fix provisioned templates being ignored by alertmanager (#69485) 2023-06-02 15:47:43 -04:00
testing.go Chore: Remove result fields from ngalert (#65410) 2023-03-28 10:34:35 +02:00