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

[v9.5.x] Alerting: Fix unique violation when updating rule group with title chains/cycles #71330

Merged
merged 1 commit into from
Jul 13, 2023

Conversation

grobinson-grafana
Copy link
Contributor

This is a backport of commit 0c68819 from #67868 to v9.5.x

…ains/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.
@grobinson-grafana grobinson-grafana added backport A backport PR no-changelog Skip including change in changelog/release notes labels Jul 11, 2023
@grobinson-grafana grobinson-grafana added this to the 9.5.x milestone Jul 11, 2023
@grobinson-grafana grobinson-grafana self-assigned this Jul 11, 2023
@grobinson-grafana grobinson-grafana requested review from rwwiv, gotjosh, JohnnyQQQQ, santihernandezc, stevesg and dylanherbig and removed request for a team July 11, 2023 08:36
Copy link
Member

@JacobsonMT JacobsonMT left a comment

Choose a reason for hiding this comment

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

LGTM

@grobinson-grafana grobinson-grafana merged commit 4f944c6 into v9.5.x Jul 13, 2023
17 checks passed
@grobinson-grafana grobinson-grafana deleted the grobinson/backport-v9.5.x-67868 branch July 13, 2023 14:30
@zerok zerok modified the milestones: 9.5.x, 9.5.7 Jul 20, 2023
@zerok zerok added add to changelog and removed no-changelog Skip including change in changelog/release notes labels Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

5 participants