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

ref(rules): Migrate 'bad' rules to be disabled #55941

Merged
merged 10 commits into from
Sep 12, 2023

Conversation

ceorourke
Copy link
Member

@ceorourke ceorourke commented Sep 8, 2023

Migrate alert rules that have no action or are exact duplicates of another rule in the same project to be disabled. We now prevent these from being created, this will just clean up old ones.

Closes #55502

@ceorourke ceorourke requested a review from a team as a code owner September 8, 2023 20:49
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Sep 8, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 8, 2023

This PR has a migration; here is the generated SQL for src/sentry/migrations/0546_migrate_no_action_dupe_issue_alerts.py ()

--
-- MIGRATION NOW PERFORMS OPERATION THAT CANNOT BE WRITTEN AS SQL:
-- Raw Python operation
--

@codecov
Copy link

codecov bot commented Sep 8, 2023

Codecov Report

Merging #55941 (a3c8931) into master (36121c1) will decrease coverage by 0.01%.
Report is 6 commits behind head on master.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master   #55941      +/-   ##
==========================================
- Coverage   79.99%   79.98%   -0.01%     
==========================================
  Files        5063     5063              
  Lines      217841   217848       +7     
  Branches    36879    36881       +2     
==========================================
- Hits       174254   174250       -4     
- Misses      38243    38249       +6     
- Partials     5344     5349       +5     
Files Changed Coverage
src/sentry/testutils/factories.py 100.00%

@github-actions
Copy link
Contributor

This PR has a migration; here is the generated SQL for src/sentry/migrations/0548_migrate_no_action_dupe_issue_alerts.py ()

--
-- MIGRATION NOW PERFORMS OPERATION THAT CANNOT BE WRITTEN AS SQL:
-- Raw Python operation
--

@github-actions
Copy link
Contributor

This PR has a migration; here is the generated SQL for src/sentry/migrations/0549_migrate_no_action_dupe_issue_alerts.py ()

--
-- MIGRATION NOW PERFORMS OPERATION THAT CANNOT BE WRITTEN AS SQL:
-- Raw Python operation
--

Copy link
Member

@JoshFerge JoshFerge left a comment

Choose a reason for hiding this comment

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

is it possible to write a test for this? I know we previously added some tooling around data migration tests

@ceorourke
Copy link
Member Author

is it possible to write a test for this? I know we previously added some tooling around data migration tests

I can - could you point me to where that is? I'm not finding much for test_migration, /tests/migrations etc.

@JoshFerge
Copy link
Member

is it possible to write a test for this? I know we previously added some tooling around data migration tests

I can - could you point me to where that is? I'm not finding much for test_migration, /tests/migrations etc.

Let me know if there's enough context here: https://develop.sentry.dev/database-migrations/#testing

@ceorourke
Copy link
Member Author

ceorourke commented Sep 11, 2023

is it possible to write a test for this? I know we previously added some tooling around data migration tests

I can - could you point me to where that is? I'm not finding much for test_migration, /tests/migrations etc.

Let me know if there's enough context here: https://develop.sentry.dev/database-migrations/#testing

I added a test based on that but running it locally (even with the env var set) always says: Migration is no longer runnable. Retain until migration is removed. 😞 This happens on almost every other test in the directory... might be because 0547 has kinda borked my local env.

Update: Fixed 0547 locally and I get the same message.

@JoshFerge
Copy link
Member

is it possible to write a test for this? I know we previously added some tooling around data migration tests

I can - could you point me to where that is? I'm not finding much for test_migration, /tests/migrations etc.

Let me know if there's enough context here: https://develop.sentry.dev/database-migrations/#testing

I added a test based on that but running it locally (even with the env var set) always says: Migration is no longer runnable. Retain until migration is removed. 😞 This happens on almost every other test in the directory... might be because 0547 has kinda borked my local env.

Update: Fixed 0547 locally and I get the same message.

ah annoying! i'll try running it on my local in a sec and see what happens. thanks for adding that!

@ceorourke
Copy link
Member Author

is it possible to write a test for this? I know we previously added some tooling around data migration tests

I can - could you point me to where that is? I'm not finding much for test_migration, /tests/migrations etc.

Let me know if there's enough context here: https://develop.sentry.dev/database-migrations/#testing

I added a test based on that but running it locally (even with the env var set) always says: Migration is no longer runnable. Retain until migration is removed. 😞 This happens on almost every other test in the directory... might be because 0547 has kinda borked my local env.
Update: Fixed 0547 locally and I get the same message.

ah annoying! i'll try running it on my local in a sec and see what happens. thanks for adding that!

Oh duh - they're all marked as skippable: @pytest.mark.skip("Migration is no longer runnable. Retain until migration is removed.") why is that though?

@JoshFerge
Copy link
Member

is it possible to write a test for this? I know we previously added some tooling around data migration tests

I can - could you point me to where that is? I'm not finding much for test_migration, /tests/migrations etc.

Let me know if there's enough context here: https://develop.sentry.dev/database-migrations/#testing

I added a test based on that but running it locally (even with the env var set) always says: Migration is no longer runnable. Retain until migration is removed. 😞 This happens on almost every other test in the directory... might be because 0547 has kinda borked my local env.
Update: Fixed 0547 locally and I get the same message.

ah annoying! i'll try running it on my local in a sec and see what happens. thanks for adding that!

Oh duh - they're all marked as skippable: @pytest.mark.skip("Migration is no longer runnable. Retain until migration is removed.") why is that though?

@markstory do you know on this one? do we generally make them skip after the PR is merged?

@github-actions
Copy link
Contributor

This PR has a migration; here is the generated SQL for src/sentry/migrations/0550_migrate_no_action_dupe_issue_alerts.py ()

--
-- MIGRATION NOW PERFORMS OPERATION THAT CANNOT BE WRITTEN AS SQL:
-- Raw Python operation
--

@ceorourke ceorourke merged commit a452b23 into master Sep 12, 2023
52 checks passed
@ceorourke ceorourke deleted the ceorourke/migrate-bad-alerts branch September 12, 2023 21:19
ceorourke added a commit that referenced this pull request Sep 22, 2023
#55941 had a mistake where rules
that were the exact same in the same project that had different
environments were being disabled due to a discrepancy in how we need to
compare rule data in the app (a data dict including the environment
data, if set) versus how we need to compare rule data in the database
(if the environment is set, it's a column in the table, not in `data`).

This migration will find disabled rules with an environment id set and
compare them against other rules in the project. If they're actually
duplicates (including the environment) we'll leave it alone, but if
they're duplicates _except_ for the environment, we'll re-enable it.
RaduW pushed a commit that referenced this pull request Sep 25, 2023
#55941 had a mistake where rules
that were the exact same in the same project that had different
environments were being disabled due to a discrepancy in how we need to
compare rule data in the app (a data dict including the environment
data, if set) versus how we need to compare rule data in the database
(if the environment is set, it's a column in the table, not in `data`).

This migration will find disabled rules with an environment id set and
compare them against other rules in the project. If they're actually
duplicates (including the environment) we'll leave it alone, but if
they're duplicates _except_ for the environment, we'll re-enable it.
@github-actions github-actions bot locked and limited conversation to collaborators Sep 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
3 participants