Skip to content

feat(detectors): Add "make new detector" script #97429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thetruecpaul
Copy link
Contributor

Summary

Adding a new detector is a very involved process.

This PR adds a helper script to do as much work in an automated manner as possible to make it easier to add new detectors.

Test Plan

Ran python3 scripts/create_detector.py solar_eclipse and observed that modified files looked about right.

@thetruecpaul thetruecpaul requested a review from a team as a code owner August 7, 2025 20:34
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Aug 7, 2025
@thetruecpaul thetruecpaul requested a review from a team August 7, 2025 20:34
cursor[bot]

This comment was marked as outdated.

Comment on lines 110 to 111
class MonitorIncidentType(GroupType):
type_id = None # TODO
Copy link
Contributor

Choose a reason for hiding this comment

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

Potential bug: The `create_detector.py` script hardcodes the `MonitorIncidentType` class name, which will cause duplicate class definition errors and crash the server on import.
  • Description: The create_detector.py script appends a hardcoded GroupType class definition to src/sentry/issues/grouptype.py. The class is always named MonitorIncidentType. Since this class already exists in the target file, running the script will create a duplicate class definition. This results in a Python syntax error when grouptype.py is imported, which will crash any Sentry service that depends on this module, preventing the application from starting.
  • Suggested fix: Generate the GroupType class name dynamically based on the detector_name input, similar to how detector_classname is created. A new variable, like grouptype_classname, should be created from detector_name and used within the template string written to grouptype.py.
    severity: 0.9, confidence: 0.95

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

@@ -0,0 +1,126 @@
"""
Copy link
Member

Choose a reason for hiding this comment

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

the scripts directory is meant to be tools for the build system and development environment

admittedly one off scripts like this are sort of frowned upon because they almost instantly become outdated, unused, untested, and unmaintained

it may make sense to make a separate repository where you can adequately test this and maintain it?

Copy link
Contributor Author

@thetruecpaul thetruecpaul Aug 7, 2025

Choose a reason for hiding this comment

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

the scripts directory is meant to be tools for the build system and development environment

Moved out of the scripts directory and to the tools directory.

admittedly one off scripts like this are sort of frowned upon because they almost instantly become outdated, unused, untested, and unmaintained

Generally fair.

  • I can push back a little on "unused" — this would be pretty heavily linked from our documentation (replacing half of that 25-step checklist), so it should be fairly discoverable.
  • Untested, well, I could do a snapshot test to ensure that any change to outputs would be noted, but that feels like cheating to me (basically just "testing" that it works in its current state and doesn't change from current state).
  • No argument on "outdated" + "unmaintained", not sure what I can say there except that I would be fairly willing to delete this if it stops working (since once it's committed it's easy to find in version history).

it may make sense to make a separate repository where you can adequately test this and maintain it?

The goal of this script is "make detector-creation as close to zero friction as possible"; having to check out a new repo and run a script cross-repo is more friction than I'd like.

Copy link
Member

Choose a reason for hiding this comment

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

tools is also a build system / development environment namespace too 😆

let's take a step back -- if it's hard to add one of these things why not make the actual steps to adding them simpler rather than adding a hacky script?

@thetruecpaul thetruecpaul force-pushed the cpaul/080625/newdetectorscript branch from a8d2f89 to a104b29 Compare August 7, 2025 20:45
cursor[bot]

This comment was marked as outdated.

performance_detection_file_contents,
)
performance_detection_file_contents = sub(
r"(def get_detection_settings[\(\):.\w\s=\|\[\]\->_,]+return \{)(([.\s]*DetectorType\.[^\{]+[^\}]+\},?)+)(\s+\})",

Check failure

Code scanning / CodeQL

Inefficient regular expression High

This part of the regular expression may cause exponential backtracking on strings starting with 'def get_detection_settings\treturn {DetectorType.' and containing many repetitions of 'zz}DetectorType.'.
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