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

Fix make alert rule uid settable to avoid accidental overwriting of existing rule history #1971

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

moustafab
Copy link

Unfortunately this is the only viable workaround. It will require users to manually set the uid for alert rules similar to how it is done in file provisioning.

Addresses #1928

Copy link

In order to lower resource usage and have a faster runtime, PRs will not run Cloud tests automatically.
To do so, a Grafana Labs employee must trigger the cloud acceptance tests workflow manually.

@moustafab moustafab force-pushed the moustafab/fix-optional-uid branch 7 times, most recently from b44e148 to c6e5be8 Compare December 24, 2024 21:19
…xisting rule history

Unfortunately this is the only viable workaround. It will require users to manually set the uid for alert rules similar to how it is done in file provisioning.

Addresses #1928
@moustafab moustafab force-pushed the moustafab/fix-optional-uid branch from c6e5be8 to c7c6a1f Compare January 6, 2025 21:54
@JacobsonMT
Copy link
Member

JacobsonMT commented Jan 17, 2025

The change looks good to me, however I think there is still a bug that will cause this to be an incomplete fix.

Reproduction:

  • Create a group, two rules will do
  • Give the rules uids.
  • Swap the order of any two rules definitions.
  • Apply will show a diff (correct) and apply successfully (correct) but the diff will remain afterwards (bug).

Likely there is a bug in the API that is causing the group to not actually re-order itself. This shouldn't necessarily prevent the merge of this change, but we should probably add a test case to cover this since tests passed here and probably shouldn't have.

Other (likely related) cases also fail, such as:

  • Adding a new rules to a group that immediately have UIDs (not adding them after the fact)

moustafab added a commit to grafana/grafana that referenced this pull request Jan 31, 2025
This was discovered as part of work to add support `uid` to the alert rule terraform provider. When modifying rule groups the uid can be specified but only if the rule already existed in the DB. If the rule is new the update would be rejected.

Additionally, the RuleGroupIdx was not being updated when rules were reordered in the group.

TODO: This breaks a number of tests and breaks the PutRule endpoint as it uses the same underlying function. I need to figure out how to bifurcate the usages of the delta calculator as PutRule should not allow creation of new rules.

Context: grafana/terraform-provider-grafana#1971 (comment)
Relates to: grafana/terraform-provider-grafana#1928
moustafab added a commit to grafana/grafana that referenced this pull request Jan 31, 2025
This was discovered as part of work to add support `uid` to the alert rule terraform provider. When modifying rule groups the uid can be specified but only if the rule already existed in the DB. If the rule is new the update would be rejected.

Additionally, the RuleGroupIdx was not being updated when rules were reordered in the group.

Context: grafana/terraform-provider-grafana#1971 (comment)
Relates to: grafana/terraform-provider-grafana#1928
moustafab added a commit to grafana/grafana that referenced this pull request Jan 31, 2025
This was discovered as part of work to add support `uid` to the alert rule terraform provider. When modifying rule groups the uid can be specified but only if the rule already existed in the DB. If the rule is new the update would be rejected.

Additionally, the RuleGroupIdx was not being updated when rules were reordered in the group.

Context: grafana/terraform-provider-grafana#1971 (comment)
Relates to: grafana/terraform-provider-grafana#1928
@moustafab
Copy link
Author

Hopefully grafana/grafana#99858 should address the issues @JacobsonMT pointed out, but the question is then how should we merge and release this so that we can clarify that setting the uid in configuration relies on the version that has the fixes.

moustafab added a commit to grafana/grafana that referenced this pull request Feb 10, 2025
When modifying rule groups the `uid` can be specified but only if the rule already existed in the DB. If the rule is new the update would be rejected.

This updates the RuleGroup provisioning apis to allow specifying the `uid` when creating/updating rule groups. 

Additionally, the RuleGroupIdx was not being updated when rules were reordered in the group.

Context: grafana/terraform-provider-grafana#1971 (comment)
Relates to: grafana/terraform-provider-grafana#1928

Fixes: #98283
moustafab added a commit to grafana/grafana that referenced this pull request Feb 11, 2025
When modifying rule groups the `uid` can be specified but only if the rule already existed in the DB. If the rule is new the update would be rejected.

This updates the RuleGroup provisioning apis to allow specifying the `uid` when creating/updating rule groups.

Additionally, the RuleGroupIdx was not being updated when rules were reordered in the group.

Context: grafana/terraform-provider-grafana#1971 (comment)
Relates to: grafana/terraform-provider-grafana#1928

Fixes: #98283
(cherry picked from commit 7dee4d1)
moustafab added a commit to grafana/grafana that referenced this pull request Feb 11, 2025
When modifying rule groups the `uid` can be specified but only if the rule already existed in the DB. If the rule is new the update would be rejected.

This updates the RuleGroup provisioning apis to allow specifying the `uid` when creating/updating rule groups.

Additionally, the RuleGroupIdx was not being updated when rules were reordered in the group.

Context: grafana/terraform-provider-grafana#1971 (comment)
Relates to: grafana/terraform-provider-grafana#1928

Fixes: #98283
(cherry picked from commit 7dee4d1)
aishyandapalli pushed a commit to aishyandapalli/grafana that referenced this pull request Feb 12, 2025
…#99858)

When modifying rule groups the `uid` can be specified but only if the rule already existed in the DB. If the rule is new the update would be rejected.

This updates the RuleGroup provisioning apis to allow specifying the `uid` when creating/updating rule groups. 

Additionally, the RuleGroupIdx was not being updated when rules were reordered in the group.

Context: grafana/terraform-provider-grafana#1971 (comment)
Relates to: grafana/terraform-provider-grafana#1928

Fixes: grafana#98283
moustafab added a commit to grafana/grafana that referenced this pull request Feb 12, 2025
When modifying rule groups the `uid` can be specified but only if the rule already existed in the DB. If the rule is new the update would be rejected.

This updates the RuleGroup provisioning apis to allow specifying the `uid` when creating/updating rule groups.

Additionally, the RuleGroupIdx was not being updated when rules were reordered in the group.

Context: grafana/terraform-provider-grafana#1971 (comment)
Relates to: grafana/terraform-provider-grafana#1928

Fixes: #98283
(cherry picked from commit 7dee4d1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants