Skip to content

Conversation

@evanpurkhiser
Copy link
Member

Implements Step 2 of the migration plan from NEW-564: There needs to be some way to mute the entire cron detector

This data migration backfills MonitorEnvironment.is_muted from Monitor.is_muted for all muted monitors. This ensures existing data is consistent before switching to read from MonitorEnvironment.is_muted.

After this migration runs:

  • Monitors with is_muted=True will have ALL environments muted
  • Monitors with is_muted=False will have environments unchanged

This establishes the correct invariant:

  • Monitor is muted ↔ ALL environments are muted
  • Monitor is unmuted ↔ ANY environment is unmuted

The migration:

  • Uses range queries for efficient batching (1000 monitors per batch)
  • Only updates environments for muted monitors (unmuted is the default)
  • Is marked as post-deployment for manual execution in production

Test verifies:

  • Muted monitor environments are updated to is_muted=True
  • Unmuted monitor environments remain unchanged
  • Monitors without environments are unaffected

@evanpurkhiser evanpurkhiser requested review from a team as code owners November 13, 2025 19:33
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 13, 2025
@codecov
Copy link

codecov bot commented Nov 13, 2025

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
29770 1 29769 245
View the top 1 failed test(s) by shortest run time
tests.sentry.api.test_api_owners.APIOwnersTestCase::test_api_owner_is_a_valid_code_owner
Stack Traces | 0.049s run time
#x1B[1m#x1B[.../sentry/api/test_api_owners.py#x1B[0m:22: in test_api_owner_is_a_valid_code_owner
    assert owner.value in self.teams
#x1B[1m#x1B[31mE   AssertionError: assert 'visibility' in {'alerts-create-issues', 'alerts-notifications', 'codecov', 'crons', 'dashboards', 'data', ...}#x1B[0m
#x1B[1m#x1B[31mE    +  where 'visibility' = <ApiOwner.VISIBILITY: 'visibility'>.value#x1B[0m
#x1B[1m#x1B[31mE    +  and   {'alerts-create-issues', 'alerts-notifications', 'codecov', 'crons', 'dashboards', 'data', ...} = <tests.sentry.api.test_api_owners.APIOwnersTestCase testMethod=test_api_owner_is_a_valid_code_owner>.teams#x1B[0m

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@evanpurkhiser evanpurkhiser removed the request for review from a team November 13, 2025 19:40
@github-actions
Copy link
Contributor

This PR has a migration; here is the generated SQL for src/sentry/monitors/migrations/0011_backfill_monitor_environment_is_muted.py

for 0011_backfill_monitor_environment_is_muted in monitors

--
-- Raw Python operation
--
-- THIS OPERATION CANNOT BE WRITTEN AS SQL

@evanpurkhiser evanpurkhiser marked this pull request as draft November 13, 2025 19:57
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-crons-add-migration-to-backfill-monitorenvironment-is-muted branch from dfd68e6 to 44fa9fa Compare November 13, 2025 22:03
Comment on lines 29 to 36
muted_monitors = list(
Monitor.objects.filter(
id__gt=last_id,
is_muted=True,
).order_by(
"id"
)[:batch_size]
)
Copy link
Member

Choose a reason for hiding this comment

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

You may as well just use RangeQuerySetWrapper and filter is_muted in memory. There's no index on id, is_muted so writing this manually won't help at all.

Copy link
Member Author

Choose a reason for hiding this comment

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

look again

@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-crons-add-migration-to-backfill-monitorenvironment-is-muted branch from 44fa9fa to 88a0a41 Compare November 13, 2025 22:09
Comment on lines 29 to 31
muted_monitors = Monitor.objects.filter(is_muted=True)

for monitor in RangeQuerySetWrapperWithProgressBar(muted_monitors):
Copy link
Member

Choose a reason for hiding this comment

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

You're better off filtering is_muted in memory here instead of the query, otherwise you might end up with timeouts.

Copy link
Member Author

Choose a reason for hiding this comment

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

good call

@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-crons-add-migration-to-backfill-monitorenvironment-is-muted branch from 88a0a41 to 9524607 Compare November 13, 2025 22:40
@evanpurkhiser evanpurkhiser marked this pull request as ready for review November 13, 2025 22:41
@evanpurkhiser evanpurkhiser enabled auto-merge (squash) November 13, 2025 22:41
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-crons-add-migration-to-backfill-monitorenvironment-is-muted branch from 9524607 to 196a9e9 Compare November 14, 2025 19:47
@evanpurkhiser evanpurkhiser requested a review from a team as a code owner November 14, 2025 19:47
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-crons-add-migration-to-backfill-monitorenvironment-is-muted branch from 196a9e9 to 2cc96dd Compare November 14, 2025 22:22
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-crons-add-migration-to-backfill-monitorenvironment-is-muted branch from 2cc96dd to af3ae18 Compare November 14, 2025 22:42
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-crons-add-migration-to-backfill-monitorenvironment-is-muted branch from af3ae18 to 581c5fa Compare November 17, 2025 16:14
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-crons-add-migration-to-backfill-monitorenvironment-is-muted branch from 2df1031 to f4e9402 Compare November 17, 2025 17:52
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-crons-add-migration-to-backfill-monitorenvironment-is-muted branch from f4e9402 to 22949a2 Compare November 17, 2025 18:15
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-crons-add-migration-to-backfill-monitorenvironment-is-muted branch from 22949a2 to ed8a517 Compare November 17, 2025 20:17
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-crons-add-migration-to-backfill-monitorenvironment-is-muted branch from ed8a517 to d7a51de Compare November 17, 2025 20:33
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-crons-add-migration-to-backfill-monitorenvironment-is-muted branch from d7a51de to beedaf8 Compare November 17, 2025 20:45
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-crons-add-migration-to-backfill-monitorenvironment-is-muted branch from beedaf8 to 18864ae Compare November 17, 2025 21:00
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-crons-add-migration-to-backfill-monitorenvironment-is-muted branch from 18864ae to c6b7907 Compare November 18, 2025 16:59
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-crons-add-migration-to-backfill-monitorenvironment-is-muted branch from c6b7907 to fa4915d Compare November 18, 2025 17:13
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-crons-add-migration-to-backfill-monitorenvironment-is-muted branch from fa4915d to f96279b Compare November 18, 2025 17:18
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-crons-add-migration-to-backfill-monitorenvironment-is-muted branch from f96279b to 7b5bb18 Compare November 18, 2025 18:17
Implements Step 2 of the migration plan from [NEW-564: There needs to be some way to mute the entire cron detector](https://linear.app/getsentry/issue/NEW-564/there-needs-to-be-some-way-to-mute-the-entire-cron-detector)

This data migration backfills MonitorEnvironment.is_muted from Monitor.is_muted for all muted monitors. This ensures existing data is consistent before switching to read from MonitorEnvironment.is_muted.

After this migration runs:
- Monitors with is_muted=True will have ALL environments muted
- Monitors with is_muted=False will have environments unchanged

This establishes the correct invariant:
- Monitor is muted ↔ ALL environments are muted
- Monitor is unmuted ↔ ANY environment is unmuted

The migration:
- Uses range queries for efficient batching (1000 monitors per batch)
- Only updates environments for muted monitors (unmuted is the default)
- Is marked as post-deployment for manual execution in production

Test verifies:
- Muted monitor environments are updated to is_muted=True
- Unmuted monitor environments remain unchanged
- Monitors without environments are unaffected
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-crons-add-migration-to-backfill-monitorenvironment-is-muted branch from 7b5bb18 to bd3e3d1 Compare November 18, 2025 22:04
@evanpurkhiser evanpurkhiser merged commit 7962703 into master Nov 18, 2025
65 of 66 checks passed
@evanpurkhiser evanpurkhiser deleted the evanpurkhiser/ref-crons-add-migration-to-backfill-monitorenvironment-is-muted branch November 18, 2025 22:25
@github-actions github-actions bot locked and limited conversation to collaborators Dec 4, 2025
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

Development

Successfully merging this pull request may close these issues.

4 participants