Skip to content

Commit 92b3be9

Browse files
committed
fix(uptime): Disable uptime autodetection when a manual uptime monitor is created
If someone manually creates a monitor, we don't need to perform any more auto detection since they're now aware of the feature. So disable auto-detection, and remove any onboarding uptime monitors.
1 parent ba7bc8f commit 92b3be9

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

src/sentry/uptime/subscriptions/subscriptions.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ def create_project_uptime_subscription(
191191
project__organization=project.organization,
192192
config__mode=ProjectUptimeSubscriptionMode.MANUAL,
193193
).count()
194+
195+
# Once a user has created a subscription manually, make sure we disable all autodetection, and remove any
196+
# onboarding monitors
197+
if project.organization.get_option("sentry:uptime_autodetection", False):
198+
project.organization.update_option("sentry:uptime_autodetection", False)
199+
for detector in get_auto_monitored_detectors_for_project(
200+
project, modes=[ProjectUptimeSubscriptionMode.AUTO_DETECTED_ONBOARDING]
201+
):
202+
delete_uptime_detector(detector)
203+
194204
if (
195205
not override_manual_org_limit
196206
and manual_subscription_count >= MAX_MANUAL_SUBSCRIPTIONS_PER_ORG
@@ -456,15 +466,16 @@ def is_url_auto_monitored_for_project(project: Project, url: str) -> bool:
456466
).exists()
457467

458468

459-
def get_auto_monitored_detectors_for_project(project: Project) -> list[Detector]:
469+
def get_auto_monitored_detectors_for_project(
470+
project: Project,
471+
modes: Sequence[ProjectUptimeSubscriptionMode] = (
472+
ProjectUptimeSubscriptionMode.AUTO_DETECTED_ONBOARDING.value,
473+
ProjectUptimeSubscriptionMode.AUTO_DETECTED_ACTIVE.value,
474+
),
475+
) -> list[Detector]:
460476
return list(
461477
Detector.objects.filter(
462-
type=UptimeDomainCheckFailure.slug,
463-
project=project,
464-
config__mode__in=(
465-
ProjectUptimeSubscriptionMode.AUTO_DETECTED_ONBOARDING.value,
466-
ProjectUptimeSubscriptionMode.AUTO_DETECTED_ACTIVE.value,
467-
),
478+
type=UptimeDomainCheckFailure.slug, project=project, config__mode__in=modes
468479
)
469480
)
470481

tests/sentry/uptime/subscriptions/test_subscriptions.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,30 @@ def test_no_seat_assignment(self, _mock_check_assign_seat):
398398
assert detector
399399
assert not detector.enabled
400400

401+
def test_create_manual_removes_onboarding(self):
402+
assert self.organization.update_option("sentry:uptime_autodetection", True)
403+
onboarding_monitor = create_project_uptime_subscription(
404+
self.project,
405+
self.environment,
406+
url="https://sentry.io",
407+
interval_seconds=3600,
408+
timeout_ms=1000,
409+
mode=ProjectUptimeSubscriptionMode.AUTO_DETECTED_ONBOARDING,
410+
)
411+
assert self.organization.get_option("sentry:uptime_autodetection")
412+
413+
create_project_uptime_subscription(
414+
self.project,
415+
self.environment,
416+
url="https://sentry.io/manual",
417+
interval_seconds=3600,
418+
timeout_ms=1000,
419+
mode=ProjectUptimeSubscriptionMode.MANUAL,
420+
)
421+
assert not self.organization.get_option("sentry:uptime_autodetection")
422+
with pytest.raises(ProjectUptimeSubscription.DoesNotExist):
423+
onboarding_monitor.refresh_from_db()
424+
401425

402426
class UpdateProjectUptimeSubscriptionTest(UptimeTestCase):
403427
def test(self):

0 commit comments

Comments
 (0)