Skip to content

Conversation

evanpurkhiser
Copy link
Member

This systemically removes ProjectUptimeSubscription usages from uptime endpoints.

  • Remove legacy dual ID handling logic and query parameter dependencies. The useDetectorId query parameter no longer has any affect, all IDs are treated as detector Ids.

  • Update all endpoints to use Detector model instead of ProjectUptimeSubscription.

  • Refactor serializers to work with Detector objects and associated UptimeSubscription data.

  • Update validators to create and update Detector instances directly

  • Update audit logging to use detector IDs and consolidated audit log data functions. Previously the get_audit_log_data method was part of the ProjectUptimeSubscription, which is no longer used.

  • Remove unused ProjectUptimeSubscription references throughout codebase

IMPORTANTLY the tests have very little changes to them, this is because this change does NOT change how data is returned.

Requires #98527

@evanpurkhiser evanpurkhiser requested review from a team as code owners September 4, 2025 14:29
@evanpurkhiser evanpurkhiser requested review from a team and removed request for a team September 4, 2025 14:29
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Sep 4, 2025
Copy link
Member Author

Choose a reason for hiding this comment

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

Removes querying for ProejctUptimeSubscriptions, now only passes in uptime detectors.

cursor[bot]

This comment was marked as outdated.

Copy link

codecov bot commented Sep 4, 2025

Codecov Report

❌ Patch coverage is 97.89474% with 2 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/uptime/endpoints/serializers.py 90.90% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master   #98794   +/-   ##
=======================================
  Coverage   81.22%   81.22%           
=======================================
  Files        8534     8534           
  Lines      376905   376920   +15     
  Branches    23890    23890           
=======================================
+ Hits       306148   306165   +17     
+ Misses      70389    70387    -2     
  Partials      368      368           

@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-uptime-remove-usage-of-projectuptimesubscription-from-endpoints branch from dabe5d0 to 545fb75 Compare September 4, 2025 16:51
@evanpurkhiser evanpurkhiser requested a review from a team as a code owner September 4, 2025 16:51
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-uptime-remove-usage-of-projectuptimesubscription-from-endpoints branch from 545fb75 to 0ecd18a Compare September 4, 2025 17:51
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-uptime-remove-usage-of-projectuptimesubscription-from-endpoints branch from 0ecd18a to 4792899 Compare September 4, 2025 18:00
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-uptime-remove-usage-of-projectuptimesubscription-from-endpoints branch from 4792899 to 38ced18 Compare September 4, 2025 19:28
Copy link
Member

@wedamija wedamija left a comment

Choose a reason for hiding this comment

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

Does this pr change at all after #98849? Or is the idea that we merge this after we've enabled that flag for a while?

Comment on lines 445 to 452
"id": item_id,
"issue_rule": isinstance(item, Rule),
"metric_rule": isinstance(item, AlertRule),
"uptime_rule": isinstance(item, ProjectUptimeSubscription),
"uptime_rule": (
isinstance(item, Detector)
and item.type == GROUP_TYPE_UPTIME_DOMAIN_CHECK_FAILURE
),
"crons_rule": isinstance(item, Monitor),
Copy link
Member

Choose a reason for hiding this comment

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

This is kind of a weird structure... shouldn't this just be item_type: type(item)?

I know this isn't your code, but maybe rather than adding to this pattern, just add both type(item) and item.type here, so that others don't have to keep adding this weird logic

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you mean exactly?

@@ -455,7 +467,7 @@ def serialize(
updated_attrs["type"] = "alert_rule"
elif isinstance(obj, Rule):
updated_attrs["type"] = "rule"
elif isinstance(obj, ProjectUptimeSubscription):
elif isinstance(obj, Detector) and obj.type == GROUP_TYPE_UPTIME_DOMAIN_CHECK_FAILURE:
Copy link
Member

Choose a reason for hiding this comment

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

This is also not a great pattern... do you know if this is a long term pattern or just transitional? People shouldn't need to add things like this in a bunch of places, it should just be on the grouptype

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is just because of what we're doing here in this combined alert serializer, which would go away in the future right?

Comment on lines +448 to +460
# Create DetectorState based on the uptime_status from the uptime_subscription
if project_sub.uptime_subscription.uptime_status == UptimeStatus.FAILED:
DetectorState.objects.create(
detector=detector,
state=DetectorPriorityLevel.HIGH,
is_triggered=True,
)
else:
DetectorState.objects.create(
detector=detector,
state=DetectorPriorityLevel.OK,
is_triggered=False,
)
Copy link
Member

Choose a reason for hiding this comment

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

Why do we create the state here? Isn't this just happening on detector creation? So presumably the state is not failed?

Copy link
Member Author

@evanpurkhiser evanpurkhiser Sep 4, 2025

Choose a reason for hiding this comment

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

One of the tests for the alert rules combined index that was testing sorting for rules that are in a failing state vs rules that are in an OK state needed this.

Previously it was reading the uptime status on the uptime_subscription relationship of the ProjectUptimeSubscription. When I switched that endpoint over to reading from detectors I had it subquery the DetectorState table (instead of looking at uptime_status, since that will go away in the future). Something that was missing previously from this test fixture was setting the detector state to the correct state when the uptime_status parameter was passed as failing.

@evanpurkhiser
Copy link
Member Author

evanpurkhiser commented Sep 4, 2025

Does this pr change at all after #98849

I'll update this PR once I've merged #98849, but yeah we won't merge this until we're happy that we can remove project subscription Id lookups.

Edit: It's updated now, the feature flag just get's removed.

This systemically removes ProjectUptimeSubscription usages from uptime
endpoints.

- Remove legacy dual ID handling logic and query parameter dependencies.
  The useDetectorId query parameter no longer has any affect, all IDs
  are treated as detector Ids.

- Update all endpoints to use Detector model instead of
  ProjectUptimeSubscription.

- Refactor serializers to work with Detector objects and associated
  UptimeSubscription data.

- Update validators to create and update Detector instances directly

- Update audit logging to use detector IDs and consolidated audit log
  data functions. Previously the get_audit_log_data method was part of
  the ProjectUptimeSubscription, which is no longer used.

- Remove unused ProjectUptimeSubscription references throughout codebase

IMPORTANTLY the tests have very little changes to them, this is because
this change does NOT change how data is returned.

Requires #98527
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-uptime-remove-usage-of-projectuptimesubscription-from-endpoints branch from 38ced18 to 2cec51e Compare September 4, 2025 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants