Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,10 @@ def get(self, request: Request, organization) -> Response:
incident_status=Case(
# If an uptime monitor is failing we want to treat it the same as if an alert is failing, so sort
# by the critical status
When(uptime_status=UptimeStatus.FAILED, then=IncidentStatus.CRITICAL.value),
When(
uptime_subscription__uptime_status=UptimeStatus.FAILED,
then=IncidentStatus.CRITICAL.value,
),
default=-2,
)
)
Expand Down
4 changes: 0 additions & 4 deletions src/sentry/testutils/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2048,8 +2048,6 @@ def create_project_uptime_subscription(
mode: ProjectUptimeSubscriptionMode,
name: str | None,
owner: Actor | None,
uptime_status: UptimeStatus,
uptime_status_update_date: datetime,
id: int | None,
):
if name is None:
Expand All @@ -2071,8 +2069,6 @@ def create_project_uptime_subscription(
name=name,
owner_team_id=owner_team_id,
owner_user_id=owner_user_id,
uptime_status=uptime_status,
uptime_status_update_date=uptime_status_update_date,
pk=id,
)

Expand Down
4 changes: 0 additions & 4 deletions src/sentry/testutils/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,6 @@ def create_project_uptime_subscription(
project = self.project
if env is None:
env = self.environment
if uptime_status_update_date is None:
uptime_status_update_date = timezone.now()

if uptime_subscription is None:
uptime_subscription = self.create_uptime_subscription(
Expand All @@ -787,8 +785,6 @@ def create_project_uptime_subscription(
mode,
name,
Actor.from_object(owner) if owner else None,
uptime_status,
uptime_status_update_date,
id,
)
# TODO(epurkhiser): Dual create a detector as well, can be removed
Expand Down
13 changes: 8 additions & 5 deletions src/sentry/uptime/consumers/results_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,12 @@ def produce_snuba_uptime_result(
result: The check result to be sent to Snuba
"""
try:
uptime_subscription = project_subscription.uptime_subscription
project = project_subscription.project

retention_days = quotas.backend.get_event_retention(organization=project.organization) or 90

if project_subscription.uptime_status == UptimeStatus.FAILED:
if uptime_subscription.uptime_status == UptimeStatus.FAILED:
incident_status = IncidentStatus.IN_INCIDENT
else:
incident_status = IncidentStatus.NO_INCIDENT
Expand Down Expand Up @@ -300,7 +302,8 @@ def handle_active_result(
result: CheckResult,
metric_tags: dict[str, str],
):
uptime_status = project_subscription.uptime_status
uptime_subscription = project_subscription.uptime_subscription
uptime_status = uptime_subscription.uptime_status
result_status = result["status"]

redis = _get_cluster()
Expand All @@ -322,7 +325,7 @@ def handle_active_result(
restricted_host_provider_ids = options.get(
"uptime.restrict-issue-creation-by-hosting-provider-id"
)
host_provider_id = project_subscription.uptime_subscription.host_provider_id
host_provider_id = uptime_subscription.host_provider_id
issue_creation_restricted_by_provider = host_provider_id in restricted_host_provider_ids

if issue_creation_restricted_by_provider:
Expand All @@ -346,7 +349,7 @@ def handle_active_result(
"uptime_active_sent_occurrence",
extra={
"project_id": project_subscription.project_id,
"url": project_subscription.uptime_subscription.url,
"url": uptime_subscription.url,
**result,
},
)
Expand Down Expand Up @@ -378,7 +381,7 @@ def handle_active_result(
"uptime_active_resolved",
extra={
"project_id": project_subscription.project_id,
"url": project_subscription.uptime_subscription.url,
"url": uptime_subscription.url,
**result,
},
)
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/uptime/endpoints/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def serialize(
"environment": obj.environment.name if obj.environment else None,
"name": obj.name or f"Uptime Monitoring for {obj.uptime_subscription.url}",
"status": obj.get_status_display(),
"uptimeStatus": obj.uptime_status,
"uptimeStatus": obj.uptime_subscription.uptime_status,
"mode": obj.mode,
"url": obj.uptime_subscription.url,
"headers": obj.uptime_subscription.headers,
Expand Down
6 changes: 3 additions & 3 deletions src/sentry/uptime/subscriptions/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,15 +345,15 @@ def disable_uptime_detector(detector: Detector):
also be disabled.
"""
uptime_monitor = get_project_subscription(detector)
uptime_subscription = uptime_monitor.uptime_subscription

if uptime_monitor.status == ObjectStatus.DISABLED:
return

if uptime_monitor.uptime_status == UptimeStatus.FAILED:
if uptime_subscription.uptime_status == UptimeStatus.FAILED:
# Resolve the issue so that we don't see it in the ui anymore
resolve_uptime_issue(uptime_monitor)

uptime_subscription = uptime_monitor.uptime_subscription

uptime_monitor.update(
status=ObjectStatus.DISABLED,
# We set the status back to ok here so that if we re-enable we'll start
Expand Down
6 changes: 0 additions & 6 deletions tests/sentry/uptime/consumers/test_results_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ def test(self):
assignee = group.get_assignee()
assert assignee and (assignee.id == self.user.id)
self.project_subscription.refresh_from_db()
assert self.project_subscription.uptime_status == UptimeStatus.FAILED
assert self.project_subscription.uptime_subscription.uptime_status == UptimeStatus.FAILED

def test_does_nothing_when_missing_project_subscription(self):
Expand Down Expand Up @@ -221,7 +220,6 @@ def test_restricted_host_provider_id(self):

# subscription status is still updated
self.project_subscription.refresh_from_db()
assert self.project_subscription.uptime_status == UptimeStatus.FAILED
assert self.project_subscription.uptime_subscription.uptime_status == UptimeStatus.FAILED

def test_reset_fail_count(self):
Expand Down Expand Up @@ -318,7 +316,6 @@ def test_reset_fail_count(self):
with pytest.raises(Group.DoesNotExist):
Group.objects.get(grouphash__hash=hashed_fingerprint)
self.project_subscription.refresh_from_db()
assert self.project_subscription.uptime_status == UptimeStatus.OK
assert self.project_subscription.uptime_subscription.uptime_status == UptimeStatus.OK

def test_no_create_issues_feature(self):
Expand Down Expand Up @@ -351,7 +348,6 @@ def test_no_create_issues_feature(self):
with pytest.raises(Group.DoesNotExist):
Group.objects.get(grouphash__hash=hashed_fingerprint)
self.project_subscription.refresh_from_db()
assert self.project_subscription.uptime_status == UptimeStatus.FAILED
assert self.project_subscription.uptime_subscription.uptime_status == UptimeStatus.FAILED

def test_resolve(self):
Expand Down Expand Up @@ -412,7 +408,6 @@ def test_resolve(self):
assert group.issue_type == UptimeDomainCheckFailure
assert group.status == GroupStatus.UNRESOLVED
self.project_subscription.refresh_from_db()
assert self.project_subscription.uptime_status == UptimeStatus.FAILED
assert self.project_subscription.uptime_subscription.uptime_status == UptimeStatus.FAILED

result = self.create_uptime_result(
Expand Down Expand Up @@ -443,7 +438,6 @@ def test_resolve(self):
group.refresh_from_db()
assert group.status == GroupStatus.RESOLVED
self.project_subscription.refresh_from_db()
assert self.project_subscription.uptime_status == UptimeStatus.OK
assert self.project_subscription.uptime_subscription.uptime_status == UptimeStatus.OK

def test_no_subscription(self):
Expand Down
6 changes: 3 additions & 3 deletions tests/sentry/uptime/endpoints/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test(self):
"name": uptime_monitor.name,
"environment": uptime_monitor.environment.name if uptime_monitor.environment else None,
"status": uptime_monitor.get_status_display(),
"uptimeStatus": uptime_monitor.uptime_status,
"uptimeStatus": uptime_monitor.uptime_subscription.uptime_status,
"mode": uptime_monitor.mode,
"url": uptime_monitor.uptime_subscription.url,
"method": uptime_monitor.uptime_subscription.method,
Expand All @@ -38,7 +38,7 @@ def test_default_name(self):
"name": f"Uptime Monitoring for {uptime_monitor.uptime_subscription.url}",
"environment": uptime_monitor.environment.name if uptime_monitor.environment else None,
"status": uptime_monitor.get_status_display(),
"uptimeStatus": uptime_monitor.uptime_status,
"uptimeStatus": uptime_monitor.uptime_subscription.uptime_status,
"mode": uptime_monitor.mode,
"url": uptime_monitor.uptime_subscription.url,
"method": uptime_monitor.uptime_subscription.method,
Expand All @@ -60,7 +60,7 @@ def test_owner(self):
"name": uptime_monitor.name,
"environment": uptime_monitor.environment.name if uptime_monitor.environment else None,
"status": uptime_monitor.get_status_display(),
"uptimeStatus": uptime_monitor.uptime_status,
"uptimeStatus": uptime_monitor.uptime_subscription.uptime_status,
"mode": uptime_monitor.mode,
"url": uptime_monitor.uptime_subscription.url,
"method": uptime_monitor.uptime_subscription.method,
Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/uptime/subscriptions/test_subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ def test_disable_failed(self, mock_remove_seat):

proj_sub.refresh_from_db()
assert proj_sub.status == ObjectStatus.DISABLED
assert proj_sub.uptime_status == UptimeStatus.OK
assert proj_sub.uptime_subscription.uptime_status == UptimeStatus.OK
assert proj_sub.uptime_subscription.status == UptimeSubscription.Status.DISABLED.value
mock_remove_seat.assert_called_with(DataCategory.UPTIME, proj_sub)

Expand Down
1 change: 0 additions & 1 deletion tests/sentry/uptime/subscriptions/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,6 @@ def run_test(

proj_sub.refresh_from_db()
assert proj_sub.status == expected_status
assert proj_sub.uptime_status == expected_uptime_status
assert proj_sub.uptime_subscription.uptime_status == expected_uptime_status

detector = get_detector(proj_sub.uptime_subscription)
Expand Down
Loading