Skip to content

ref(uptime): Rename detectors module to autodetect#101534

Merged
evanpurkhiser merged 1 commit into
masterfrom
evanpurkhiser/ref-uptime-rename-detectors-module-to-autodetect
Oct 16, 2025
Merged

ref(uptime): Rename detectors module to autodetect#101534
evanpurkhiser merged 1 commit into
masterfrom
evanpurkhiser/ref-uptime-rename-detectors-module-to-autodetect

Conversation

@evanpurkhiser

Copy link
Copy Markdown
Member

Renames the uptime.detectors module to uptime.autodetect to avoid
confusion with the workflow engine's detector concept.

Changes:

  • Renamed src/sentry/uptime/detectors/ → src/sentry/uptime/autodetect/
  • Renamed tests/sentry/uptime/detectors/ → tests/sentry/uptime/autodetect/
  • Renamed functions: detect_base_url_for_project → autodetect_base_url_for_project
  • Renamed functions: should_detect_for_* → should_autodetect_for_*
  • Updated all import statements and mock.patch references

IMPORTANT - NOT CHANGED (to avoid breaking production):

  • Celery task names remain unchanged to prevent breaking in-flight tasks:
    • "sentry.uptime.detectors.tasks.schedule_detections"
    • "sentry.uptime.detectors.tasks.process_detection_bucket"
    • "sentry.uptime.detectors.tasks.process_organization_url_ranking"
  • Redis keys remain unchanged (11 keys) to prevent breaking lookups
  • Lock name "uptime.detection.schedule_detections" remains unchanged
  • Django setting SENTRY_UPTIME_DETECTOR_CLUSTER remains unchanged
  • Feature flags remain unchanged
  • Metrics remain unchanged to avoid breaking dashboards

@evanpurkhiser evanpurkhiser requested review from a team as code owners October 15, 2025 18:17
@evanpurkhiser evanpurkhiser requested review from wedamija and removed request for a team October 15, 2025 18:17
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 15, 2025
Comment on lines 53 to +58
@instrumented_task(
name="sentry.uptime.detectors.tasks.schedule_detections",
namespace=uptime_tasks,
processing_deadline_duration=60,
)
def schedule_detections():
def schedule_autodetections():

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@markstory Just want to double triple check here.

I've renamed this module and I've renamed this function. However the @instrumented_task annotation has NOT changed. This IS safe correct?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes those changes are both safe. The task name and namespace attributes are what is serialized into activations and need to be consistent across deploys.

metrics.incr("uptime.detectors.scheduler.scheduled_bucket")
last_processed = last_processed + timedelta(minutes=1)
process_detection_bucket.delay(last_processed.isoformat())
process_autodetection_bucket.delay(last_processed.isoformat())

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@markstory when it dispatches this task, it's using the name from the annotation to dispatch the queued task right

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

when it dispatches this task, it's using the name from the annotation to dispatch the queued task right

Correct.

return TaskActivation(
id=uuid4().hex,
namespace=self._namespace.name,
taskname=self.name,
headers=headers,
parameters=parameters_str,
retry_state=self._create_retry_state(),
received_at=received_at,
processing_deadline_duration=processing_deadline,
expires=expires,
delay=countdown,
)

Is what is stored in kafka when a task is spawned.

Comment on lines 21 to 28
get_candidate_projects_for_org,
get_candidate_urls_for_project,
get_organization_bucket,
should_detect_for_organization,
should_detect_for_project,
should_autodetect_for_organization,
should_autodetect_for_project,
)
from sentry.uptime.subscriptions.subscriptions import (
create_uptime_detector,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Potential bug: The TASKWORKER_IMPORTS configuration contains a stale import path, "sentry.uptime.detectors.tasks", which will cause worker processes to crash on startup with a ModuleNotFoundError.
  • Description: The module sentry.uptime.detectors.tasks was moved to sentry.uptime.autodetect.tasks, but the TASKWORKER_IMPORTS tuple in src/sentry/conf/server.py was not updated. When a taskworker process starts, it calls app.load_modules(), which iterates through TASKWORKER_IMPORTS and imports each module. The attempt to import the now non-existent path "sentry.uptime.detectors.tasks" will raise a ModuleNotFoundError, causing the worker process to crash on startup and preventing any background tasks from running.

  • Suggested fix: Update the stale import path in src/sentry/conf/server.py. Change "sentry.uptime.detectors.tasks" to "sentry.uptime.autodetect.tasks" within the TASKWORKER_IMPORTS tuple.
    severity: 0.95, confidence: 1.0

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's right about this

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

oh I thought I fixed this, let me double check

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Comment thread tests/sentry/uptime/consumers/test_results_consumer.py
@codecov

codecov Bot commented Oct 15, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.00000% with 1 line in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/uptime/autodetect/tasks.py 87.50% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #101534   +/-   ##
========================================
  Coverage   80.97%    80.97%           
========================================
  Files        8706      8706           
  Lines      386918    386918           
  Branches    24520     24520           
========================================
  Hits       313315    313315           
  Misses      73252     73252           
  Partials      351       351           

@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-uptime-rename-detectors-module-to-autodetect branch from 3f2bd7e to 6427973 Compare October 15, 2025 18:37
Renames the uptime.detectors module to uptime.autodetect to avoid
confusion with the workflow engine's detector concept.

Changes:
- Renamed src/sentry/uptime/detectors/ → src/sentry/uptime/autodetect/
- Renamed tests/sentry/uptime/detectors/ → tests/sentry/uptime/autodetect/
- Renamed functions: detect_base_url_for_project → autodetect_base_url_for_project
- Renamed functions: should_detect_for_* → should_autodetect_for_*
- Updated all import statements and mock.patch references

IMPORTANT - NOT CHANGED (to avoid breaking production):
- Celery task names remain unchanged to prevent breaking in-flight tasks:
  * "sentry.uptime.detectors.tasks.schedule_detections"
  * "sentry.uptime.detectors.tasks.process_detection_bucket"
  * "sentry.uptime.detectors.tasks.process_organization_url_ranking"
- Redis keys remain unchanged (11 keys) to prevent breaking lookups
- Lock name "uptime.detection.schedule_detections" remains unchanged
- Django setting SENTRY_UPTIME_DETECTOR_CLUSTER remains unchanged
- Feature flags remain unchanged
- Metrics remain unchanged to avoid breaking dashboards
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-uptime-rename-detectors-module-to-autodetect branch from 6427973 to fb485d3 Compare October 15, 2025 20:04
@evanpurkhiser evanpurkhiser requested a review from a team as a code owner October 15, 2025 20:04
Comment on lines 53 to +58
@instrumented_task(
name="sentry.uptime.detectors.tasks.schedule_detections",
namespace=uptime_tasks,
processing_deadline_duration=60,
)
def schedule_detections():
def schedule_autodetections():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes those changes are both safe. The task name and namespace attributes are what is serialized into activations and need to be consistent across deploys.

metrics.incr("uptime.detectors.scheduler.scheduled_bucket")
last_processed = last_processed + timedelta(minutes=1)
process_detection_bucket.delay(last_processed.isoformat())
process_autodetection_bucket.delay(last_processed.isoformat())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

when it dispatches this task, it's using the name from the annotation to dispatch the queued task right

Correct.

return TaskActivation(
id=uuid4().hex,
namespace=self._namespace.name,
taskname=self.name,
headers=headers,
parameters=parameters_str,
retry_state=self._create_retry_state(),
received_at=received_at,
processing_deadline_duration=processing_deadline,
expires=expires,
delay=countdown,
)

Is what is stored in kafka when a task is spawned.

@evanpurkhiser

Copy link
Copy Markdown
Member Author

Going to wait until tomorrow to merge

@evanpurkhiser evanpurkhiser merged commit fc769a4 into master Oct 16, 2025
67 checks passed
@evanpurkhiser evanpurkhiser deleted the evanpurkhiser/ref-uptime-rename-detectors-module-to-autodetect branch October 16, 2025 15:54
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 1, 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.

3 participants