grafana/pkg/services/ngalert/api
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
..
test-data Expressions: Fixes the issue showing expressions editor (#62510) 2023-01-31 18:50:10 +01:00
tooling Alerting: Fix status code of successful response POST /api/alertmanager/grafana/api/v2/silences in swagger specs (#67951) 2023-05-15 11:23:30 -04:00
api_alertmanager_guards_test.go Alerting: Fix provenance guard checks for Alertmanager configuration to not cause panic when compared nested objects (#69009) 2023-05-25 11:41:11 -04:00
api_alertmanager_guards.go Alerting: Fix provenance guard checks for Alertmanager configuration to not cause panic when compared nested objects (#69009) 2023-05-25 11:41:11 -04:00
api_alertmanager_test.go RBAC: Remove legacy AC from HasAccess permission check (#68995) 2023-05-30 14:39:09 +01:00
api_alertmanager.go RBAC: Remove legacy AC from HasAccess permission check (#68995) 2023-05-30 14:39:09 +01:00
api_configuration_test.go Chore: Rename Id to ID in alerting models (#62777) 2023-02-02 17:22:43 +01:00
api_configuration.go Chore: Remove Result field from datasources (#63048) 2023-02-09 15:49:44 +01:00
api_prometheus_test_fixtures.go Expressions: Fixes the issue showing expressions editor (#62510) 2023-01-31 18:50:10 +01:00
api_prometheus_test.go Alerting: Skip flaky test TestRouteGetRuleStatuses (#69258) 2023-05-30 09:48:02 -05:00
api_prometheus.go RBAC: Remove legacy AC from HasAccess permission check (#68995) 2023-05-30 14:39:09 +01:00
api_provisioning_test.go Alerting: Fix misleading status code in provisioning API (#67331) 2023-04-27 09:25:34 +01:00
api_provisioning.go Alerting: Fix misleading status code in provisioning API (#67331) 2023-04-27 09:25:34 +01:00
api_ruler_history.go Alerting: Create new state history "fanout" backend that dispatches to multiple other backends at once (#64774) 2023-03-17 12:41:18 -05:00
api_ruler_test.go RBAC: Remove legacy AC from HasAccess permission check (#68995) 2023-05-30 14:39:09 +01:00
api_ruler_validation_test.go Alerting: introduce AlertQuery in definitions package (#63825) 2023-03-27 11:55:13 -04:00
api_ruler_validation.go Alerting: introduce AlertQuery in definitions package (#63825) 2023-03-27 11:55:13 -04:00
api_ruler.go Alerting: Fix unique violation when updating rule group with title chains/cycles (#67868) 2023-06-08 18:51:50 -04:00
api_testing_test.go RBAC: Remove legacy AC from HasAccess permission check (#68995) 2023-05-30 14:39:09 +01:00
api_testing.go RBAC: Remove legacy AC from HasAccess permission check (#68995) 2023-05-30 14:39:09 +01:00
api.go Alerting: Template Testing API (#67450) 2023-04-28 15:56:59 +01:00
authorization_test.go Alerting: Template Testing API (#67450) 2023-04-28 15:56:59 +01:00
authorization.go Alerting: Update patch for #865 after #68898 (#890) 2023-06-06 13:38:37 +02:00
compat_test.go Alerting: introduce AlertQuery in definitions package (#63825) 2023-03-27 11:55:13 -04:00
compat.go Alerting: Remove dependency on alerting package in definitions (#65390) 2023-03-29 13:34:59 -04:00
configuration.go Chore: Move ReqContext to contexthandler service (#62102) 2023-01-27 08:50:36 +01:00
errors.go Alerting: Update forking request handlers to use the same errors (#52965) 2022-08-02 09:33:59 -04:00
forking_alertmanager.go Alerting: Template Testing API (#67450) 2023-04-28 15:56:59 +01:00
forking_prometheus.go Chore: Move ReqContext to contexthandler service (#62102) 2023-01-27 08:50:36 +01:00
forking_ruler.go Chore: Move ReqContext to contexthandler service (#62102) 2023-01-27 08:50:36 +01:00
generated_base_api_alertmanager.go Alerting: Template Testing API (#67450) 2023-04-28 15:56:59 +01:00
generated_base_api_configuration.go Alerting: Allow hooking into request handler functions. (#67000) 2023-04-24 18:18:44 +02:00
generated_base_api_history.go Alerting: Allow hooking into request handler functions. (#67000) 2023-04-24 18:18:44 +02:00
generated_base_api_prometheus.go Alerting: Allow hooking into request handler functions. (#67000) 2023-04-24 18:18:44 +02:00
generated_base_api_provisioning.go Alerting: Allow hooking into request handler functions. (#67000) 2023-04-24 18:18:44 +02:00
generated_base_api_ruler.go Alerting: Allow hooking into request handler functions. (#67000) 2023-04-24 18:18:44 +02:00
generated_base_api_testing.go Alerting: Allow hooking into request handler functions. (#67000) 2023-04-24 18:18:44 +02:00
hooks.go Alerting: Allow hooking into request handler functions. (#67000) 2023-04-24 18:18:44 +02:00
lotex_am.go Caching: Refactor enterprise query caching middleware to a wire service (#65616) 2023-04-12 12:30:33 -04:00
lotex_prom.go Caching: Refactor enterprise query caching middleware to a wire service (#65616) 2023-04-12 12:30:33 -04:00
lotex_ruler_test.go Chore: Rename Id to ID in alerting models (#62777) 2023-02-02 17:22:43 +01:00
lotex_ruler.go Caching: Refactor enterprise query caching middleware to a wire service (#65616) 2023-04-12 12:30:33 -04:00
persist.go RBAC: remove some IsDisabled checks (#69272) 2023-05-31 09:58:57 +01:00
promql_compat_test.go Alerting: Update prometheus version (#65688) 2023-03-31 16:34:35 +02:00
promql_compat.go Alerting: Update prometheus version (#65688) 2023-03-31 16:34:35 +02:00
provisioning.go Alerting: Create endpoints for exporting in provisioning file format (#58623) 2023-01-27 11:39:16 -05:00
ruler_history.go Alerting: Add endpoint for querying state history (#62166) 2023-02-02 11:34:00 -06:00
testing_api.go Chore: Move ReqContext to contexthandler service (#62102) 2023-01-27 08:50:36 +01:00
testing.go Chore: Fix goimports grouping in alerting (#62424) 2023-01-30 09:55:35 +01:00
util_test.go RBAC: remove some IsDisabled checks (#69272) 2023-05-31 09:58:57 +01:00
util.go RBAC: remove some IsDisabled checks (#69272) 2023-05-31 09:58:57 +01:00