-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(workflow_engine): Add Detector model (#77298)
This adds in the Detector model and boilerplate needed to create it <!-- Describe your PR here. -->
- Loading branch information
Showing
16 changed files
with
233 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from __future__ import annotations | ||
|
||
from django.conf import settings | ||
from django.db import models | ||
from django.db.models import BaseConstraint | ||
|
||
from sentry.db.models import FlexibleForeignKey, Model | ||
from sentry.db.models.fields.hybrid_cloud_foreign_key import HybridCloudForeignKey | ||
from sentry.types.actor import Actor | ||
|
||
|
||
class OwnerModel(Model): | ||
""" | ||
A base model that adds ownership fields to existing models. | ||
""" | ||
|
||
owner_user_id = HybridCloudForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete="SET_NULL") | ||
owner_team = FlexibleForeignKey("sentry.Team", null=True, on_delete=models.SET_NULL) | ||
|
||
class Meta: | ||
abstract = True | ||
|
||
constraints: list[BaseConstraint] = [ | ||
models.CheckConstraint( | ||
condition=( | ||
models.Q(owner_user_id__isnull=True, owner_team__isnull=False) | ||
| models.Q(owner_user_id__isnull=False, owner_team__isnull=True) | ||
| models.Q(owner_user_id__isnull=True, owner_team__isnull=True) | ||
), | ||
name="%(app_label)s_%(class)s_owner_constraints", | ||
), | ||
] | ||
|
||
@property | ||
def owner(self) -> Actor | None: | ||
return Actor.from_id(user_id=self.owner_user_id, team_id=self.owner_team_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Generated by Django 5.1.1 on 2024-09-11 21:13 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
import sentry.db.models.fields.bounded | ||
import sentry.db.models.fields.foreignkey | ||
import sentry.db.models.fields.hybrid_cloud_foreign_key | ||
from sentry.new_migrations.migrations import CheckedMigration | ||
|
||
|
||
class Migration(CheckedMigration): | ||
# This flag is used to mark that a migration shouldn't be automatically run in production. | ||
# This should only be used for operations where it's safe to run the migration after your | ||
# code has deployed. So this should not be used for most operations that alter the schema | ||
# of a table. | ||
# Here are some things that make sense to mark as post deployment: | ||
# - Large data migrations. Typically we want these to be run manually so that they can be | ||
# monitored and not block the deploy for a long period of time while they run. | ||
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to | ||
# run this outside deployments so that we don't block them. Note that while adding an index | ||
# is a schema change, it's completely safe to run the operation after the code has deployed. | ||
# Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment | ||
|
||
is_post_deployment = False | ||
|
||
dependencies = [ | ||
("sentry", "0759_remove_spanattributeextraction_tables"), | ||
("workflow_engine", "0002_data_source"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Detector", | ||
fields=[ | ||
( | ||
"id", | ||
sentry.db.models.fields.bounded.BoundedBigAutoField( | ||
primary_key=True, serialize=False | ||
), | ||
), | ||
("date_updated", models.DateTimeField(auto_now=True)), | ||
("date_added", models.DateTimeField(auto_now_add=True)), | ||
( | ||
"owner_user_id", | ||
sentry.db.models.fields.hybrid_cloud_foreign_key.HybridCloudForeignKey( | ||
"sentry.User", db_index=True, null=True, on_delete="SET_NULL" | ||
), | ||
), | ||
("name", models.CharField(max_length=200)), | ||
( | ||
"organization", | ||
sentry.db.models.fields.foreignkey.FlexibleForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to="sentry.organization" | ||
), | ||
), | ||
( | ||
"owner_team", | ||
sentry.db.models.fields.foreignkey.FlexibleForeignKey( | ||
null=True, on_delete=django.db.models.deletion.SET_NULL, to="sentry.team" | ||
), | ||
), | ||
], | ||
options={ | ||
"abstract": False, | ||
"constraints": [ | ||
models.CheckConstraint( | ||
condition=models.Q( | ||
models.Q( | ||
("owner_team__isnull", False), ("owner_user_id__isnull", True) | ||
), | ||
models.Q( | ||
("owner_team__isnull", True), ("owner_user_id__isnull", False) | ||
), | ||
models.Q(("owner_team__isnull", True), ("owner_user_id__isnull", True)), | ||
_connector="OR", | ||
), | ||
name="workflow_engine_detector_owner_constraints", | ||
), | ||
models.UniqueConstraint( | ||
fields=("organization", "name"), name="workflow_engine_detector_org_name" | ||
), | ||
], | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
__all__ = ["DataSource", "Workflow"] | ||
__all__ = ["DataSource", "Detector", "Workflow"] | ||
|
||
from .data_source import DataSource | ||
from .detector import Detector | ||
from .workflow import Workflow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from django.db import models | ||
from django.db.models import UniqueConstraint | ||
|
||
from sentry.backup.scopes import RelocationScope | ||
from sentry.db.models import DefaultFieldsModel, FlexibleForeignKey, region_silo_model | ||
from sentry.models.owner_base import OwnerModel | ||
|
||
|
||
@region_silo_model | ||
class Detector(DefaultFieldsModel, OwnerModel): | ||
__relocation_scope__ = RelocationScope.Organization | ||
|
||
organization = FlexibleForeignKey("sentry.Organization") | ||
name = models.CharField(max_length=200) | ||
|
||
class Meta(OwnerModel.Meta): | ||
constraints = OwnerModel.Meta.constraints + [ | ||
UniqueConstraint( | ||
fields=["organization", "name"], | ||
name="workflow_engine_detector_org_name", | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters