Skip to content
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

feat(workflow_engine): Add DataConditions #77448

Merged
merged 40 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a7c1f80
WIP
saponifi3d Sep 11, 2024
4295967
created the DataCondition model
saponifi3d Sep 12, 2024
cd01766
create relationships for the data condition model
saponifi3d Sep 12, 2024
2f93ff3
manual updates for the fixtures / comparators / factories
saponifi3d Sep 12, 2024
051e9be
Fix merge conflict issue where return type was removed
saponifi3d Sep 16, 2024
de21f49
move the link to detectors / workflows off of the data condition, cre…
saponifi3d Sep 18, 2024
83673df
Updates to the models based on discussions throughout the week.
saponifi3d Sep 20, 2024
0b1ef48
export new classes in init file
saponifi3d Sep 20, 2024
4955902
Add data_condition_group_actions
saponifi3d Sep 20, 2024
45d17ce
dont need a relationship here, using a lookup table instead
saponifi3d Sep 20, 2024
cfae497
-s on file name
saponifi3d Sep 20, 2024
de0d3d5
fix typo in import
saponifi3d Sep 20, 2024
885919e
shakes fist at copilot
saponifi3d Sep 20, 2024
01f25e2
remaining model changes to get sql to generate corretly
saponifi3d Sep 20, 2024
057382b
Fix the repr a little
saponifi3d Sep 23, 2024
e4ca853
update factories
saponifi3d Sep 24, 2024
2cce1ab
update comprators
saponifi3d Sep 24, 2024
2a6c8ee
Updated the backups, i think that's a complete model of a simple inte…
saponifi3d Sep 24, 2024
6180db9
update backups to work
saponifi3d Sep 24, 2024
10e9c17
update the data condition to have 'comparison' field as well, for str…
saponifi3d Sep 24, 2024
90fae81
Re-introduce the workflow_action model to get CI green, will remove i…
saponifi3d Sep 24, 2024
d3e07f4
re-add the model to the import so makemigrations doesnt delete the model
saponifi3d Sep 24, 2024
4a66f37
make sure the data condition group action is set correctly
saponifi3d Sep 24, 2024
5d8375d
add the workflowaction to the org relocation scope to avoid test fail…
saponifi3d Sep 24, 2024
129a197
that one time, at band camp... i forgot **kwargs.
saponifi3d Sep 24, 2024
f85718b
Add a comment about what required actions are, they're basically syst…
saponifi3d Sep 25, 2024
857f070
Add comments about each field in the data_condition class
saponifi3d Sep 25, 2024
6b4dbd5
SQL Changes - Update the name of the condition groups on workflows an…
saponifi3d Sep 25, 2024
0484597
rebase - comparators
saponifi3d Sep 25, 2024
3d8a4e7
Improve the comment a bit more for action.required
saponifi3d Sep 25, 2024
2000631
update condition_group to be workflow_condition_group when creating t…
saponifi3d Sep 25, 2024
6de4826
simple json schema validation
saponifi3d Sep 25, 2024
f2d954d
remove threshold, change comparison to json
saponifi3d Sep 25, 2024
b24b5e8
Add more database constraints
saponifi3d Sep 25, 2024
9389c1d
Add organization to the data condition group to improve exports here
saponifi3d Sep 25, 2024
1d7d18a
Exclude the actions from the relocation scope for now, we may want th…
saponifi3d Sep 26, 2024
0079516
GENERATED - SQL Migration
saponifi3d Sep 26, 2024
9ae7890
GENERATED - Fixture updates
saponifi3d Sep 26, 2024
e8c240b
GENERATED - Update snapshots
saponifi3d Sep 26, 2024
67d065d
Generated - Fixture Updates... again?
saponifi3d Sep 26, 2024
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
134 changes: 134 additions & 0 deletions fixtures/backup/model_dependencies/detailed.json
Original file line number Diff line number Diff line change
Expand Up @@ -6218,6 +6218,77 @@
]
]
},
"workflow_engine.action": {
"dangling": false,
"foreign_keys": {},
"model": "workflow_engine.action",
"relocation_dependencies": [],
"relocation_scope": "Excluded",
"silos": [
"Region"
],
"table_name": "workflow_engine_action",
"uniques": []
},
"workflow_engine.datacondition": {
"dangling": false,
"foreign_keys": {
"condition_group": {
"kind": "DefaultForeignKey",
"model": "workflow_engine.dataconditiongroup",
"nullable": false
}
},
"model": "workflow_engine.datacondition",
"relocation_dependencies": [],
"relocation_scope": "Organization",
"silos": [
"Region"
],
"table_name": "workflow_engine_datacondition",
"uniques": []
},
"workflow_engine.dataconditiongroup": {
"dangling": false,
"foreign_keys": {
"organization": {
"kind": "DefaultForeignKey",
"model": "sentry.organization",
"nullable": false
}
},
"model": "workflow_engine.dataconditiongroup",
"relocation_dependencies": [],
"relocation_scope": "Organization",
"silos": [
"Region"
],
"table_name": "workflow_engine_dataconditiongroup",
"uniques": []
},
"workflow_engine.dataconditiongroupaction": {
"dangling": false,
"foreign_keys": {
"action": {
"kind": "FlexibleForeignKey",
"model": "workflow_engine.action",
"nullable": false
},
"condition_group": {
"kind": "FlexibleForeignKey",
"model": "workflow_engine.dataconditiongroup",
"nullable": false
}
},
"model": "workflow_engine.dataconditiongroupaction",
"relocation_dependencies": [],
"relocation_scope": "Excluded",
"silos": [
"Region"
],
"table_name": "workflow_engine_dataconditiongroupaction",
"uniques": []
},
"workflow_engine.datasource": {
"dangling": false,
"foreign_keys": {
Expand Down Expand Up @@ -6281,6 +6352,11 @@
"kind": "HybridCloudForeignKey",
"model": "sentry.user",
"nullable": true
},
"workflow_condition_group": {
"kind": "FlexibleForeignKey",
"model": "workflow_engine.dataconditiongroup",
"nullable": true
}
},
"model": "workflow_engine.detector",
Expand All @@ -6294,16 +6370,47 @@
[
"name",
"organization"
],
[
"workflow_condition_group"
]
]
},
"workflow_engine.detectorworkflow": {
"dangling": false,
"foreign_keys": {
"detector": {
"kind": "FlexibleForeignKey",
"model": "workflow_engine.detector",
"nullable": false
},
"workflow": {
"kind": "FlexibleForeignKey",
"model": "workflow_engine.workflow",
"nullable": false
}
},
"model": "workflow_engine.detectorworkflow",
"relocation_dependencies": [],
"relocation_scope": "Organization",
"silos": [
"Region"
],
"table_name": "workflow_engine_detectorworkflow",
"uniques": []
},
"workflow_engine.workflow": {
"dangling": false,
"foreign_keys": {
"organization": {
"kind": "FlexibleForeignKey",
"model": "sentry.organization",
"nullable": false
},
"when_condition_group": {
"kind": "FlexibleForeignKey",
"model": "workflow_engine.dataconditiongroup",
"nullable": true
}
},
"model": "workflow_engine.workflow",
Expand Down Expand Up @@ -6337,5 +6444,32 @@
],
"table_name": "workflow_engine_workflowaction",
"uniques": []
},
"workflow_engine.workflowdataconditiongroup": {
"dangling": false,
"foreign_keys": {
"condition_group": {
"kind": "FlexibleForeignKey",
"model": "workflow_engine.dataconditiongroup",
"nullable": false
},
"workflow": {
"kind": "FlexibleForeignKey",
"model": "workflow_engine.workflow",
"nullable": false
}
},
"model": "workflow_engine.workflowdataconditiongroup",
"relocation_dependencies": [],
"relocation_scope": "Organization",
"silos": [
"Region"
],
"table_name": "workflow_engine_workflowdataconditiongroup",
"uniques": [
[
"condition_group"
]
]
}
}
25 changes: 23 additions & 2 deletions fixtures/backup/model_dependencies/flat.json
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,17 @@
"uptime.uptimesubscription"
],
"uptime.uptimesubscription": [],
"workflow_engine.action": [],
"workflow_engine.datacondition": [
"workflow_engine.dataconditiongroup"
],
"workflow_engine.dataconditiongroup": [
"sentry.organization"
],
"workflow_engine.dataconditiongroupaction": [
"workflow_engine.action",
"workflow_engine.dataconditiongroup"
],
"workflow_engine.datasource": [
"sentry.organization"
],
Expand All @@ -866,12 +877,22 @@
"workflow_engine.detector": [
"sentry.organization",
"sentry.team",
"sentry.user"
"sentry.user",
"workflow_engine.dataconditiongroup"
],
"workflow_engine.detectorworkflow": [
"workflow_engine.detector",
"workflow_engine.workflow"
],
"workflow_engine.workflow": [
"sentry.organization"
"sentry.organization",
"workflow_engine.dataconditiongroup"
],
"workflow_engine.workflowaction": [
"workflow_engine.workflow"
],
"workflow_engine.workflowdataconditiongroup": [
"workflow_engine.dataconditiongroup",
"workflow_engine.workflow"
]
}
6 changes: 6 additions & 0 deletions fixtures/backup/model_dependencies/sorted.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,17 @@
"sentry.userroleuser",
"social_auth.usersocialauth",
"uptime.uptimesubscription",
"workflow_engine.action",
"workflow_engine.dataconditiongroup",
"workflow_engine.dataconditiongroupaction",
"workflow_engine.datasource",
"workflow_engine.detector",
"workflow_engine.workflow",
"workflow_engine.workflowaction",
"workflow_engine.workflowdataconditiongroup",
"workflow_engine.detectorworkflow",
"workflow_engine.datasourcedetector",
"workflow_engine.datacondition",
"sentry.savedsearch",
"sentry.relocation",
"sentry.recentsearch",
Expand Down
6 changes: 6 additions & 0 deletions fixtures/backup/model_dependencies/truncate.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,17 @@
"sentry_userrole_users",
"social_auth_usersocialauth",
"uptime_uptimesubscription",
"workflow_engine_action",
"workflow_engine_dataconditiongroup",
"workflow_engine_dataconditiongroupaction",
"workflow_engine_datasource",
"workflow_engine_detector",
"workflow_engine_workflow",
"workflow_engine_workflowaction",
"workflow_engine_workflowdataconditiongroup",
"workflow_engine_detectorworkflow",
"workflow_engine_datasourcedetector",
"workflow_engine_datacondition",
"sentry_savedsearch",
"sentry_relocation",
"sentry_recentsearch",
Expand Down
2 changes: 1 addition & 1 deletion migrations_lockfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ replays: 0004_index_together
sentry: 0768_fix_old_group_first_seen_dates
social_auth: 0002_default_auto_field
uptime: 0013_uptime_subscription_new_unique
workflow_engine: 0005_data_source_detector
workflow_engine: 0006_data_conditions
14 changes: 14 additions & 0 deletions src/sentry/backup/comparators.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,13 +865,27 @@ def get_default_comparators() -> dict[str, list[JSONScrubbingComparator]]:
],
"sentry.userrole": [DateUpdatedComparator("date_updated")],
"sentry.userroleuser": [DateUpdatedComparator("date_updated")],
"workflow_engine.action": [DateUpdatedComparator("date_updated", "date_added")],
"workflow_engine.datacondition": [DateUpdatedComparator("date_updated", "date_added")],
Copy link
Member

Choose a reason for hiding this comment

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

You'll need to add all the new models here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 thanks - yeah, i was avoiding doing all those changes initially just cause of all the things. updated! (hopefully the tests are green now too 🤞)

"workflow_engine.dataconditiongroup": [
DateUpdatedComparator("date_updated", "date_added")
],
"workflow_engine.dataconditiongroupaction": [
DateUpdatedComparator("date_updated", "date_added")
],
"workflow_engine.datasource": [DateUpdatedComparator("date_updated", "date_added")],
"workflow_engine.datasourcedetector": [
DateUpdatedComparator("date_updated", "date_added")
],
"workflow_engine.detector": [DateUpdatedComparator("date_updated", "date_added")],
"workflow_engine.detectorworkflow": [
DateUpdatedComparator("date_updated", "date_added")
],
"workflow_engine.workflow": [DateUpdatedComparator("date_updated", "date_added")],
"workflow_engine.workflowaction": [DateUpdatedComparator("date_updated", "date_added")],
"workflow_engine.workflowdataconditiongroup": [
DateUpdatedComparator("date_updated", "date_added")
],
},
)

Expand Down
73 changes: 70 additions & 3 deletions src/sentry/testutils/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,17 @@
from sentry.utils import loremipsum
from sentry.utils.performance_issues.performance_problem import PerformanceProblem
from sentry.workflow_engine.models import (
Action,
DataCondition,
DataConditionGroup,
DataConditionGroupAction,
DataSource,
DataSourceDetector,
Detector,
DetectorWorkflow,
Workflow,
WorkflowAction,
WorkflowDataConditionGroup,
)
from social_auth.models import UserSocialAuth

Expand Down Expand Up @@ -2065,13 +2071,41 @@ def create_workflow(

@staticmethod
@assume_test_silo_mode(SiloMode.REGION)
def create_workflowaction(
workflow: Workflow | None = None,
def create_workflow_action(
**kwargs,
) -> WorkflowAction:
return WorkflowAction.objects.create(**kwargs)

@staticmethod
@assume_test_silo_mode(SiloMode.REGION)
def create_data_condition_group(
**kwargs,
) -> DataConditionGroup:
return DataConditionGroup.objects.create(**kwargs)

@staticmethod
@assume_test_silo_mode(SiloMode.REGION)
def create_workflow_data_condition_group(
workflow: Workflow | None = None,
condition_group: DataConditionGroup | None = None,
**kwargs,
) -> WorkflowDataConditionGroup:
if workflow is None:
workflow = Factories.create_workflow()
return WorkflowAction.objects.create(workflow=workflow, **kwargs)

if not condition_group:
condition_group = Factories.create_data_condition_group()

return WorkflowDataConditionGroup.objects.create(
workflow=workflow, condition_group=condition_group
)

@staticmethod
@assume_test_silo_mode(SiloMode.REGION)
def create_data_condition(
**kwargs,
) -> DataCondition:
return DataCondition.objects.create(**kwargs)

@staticmethod
@assume_test_silo_mode(SiloMode.REGION)
Expand Down Expand Up @@ -2118,3 +2152,36 @@ def create_data_source_detector(
if detector is None:
detector = Factories.create_detector()
return DataSourceDetector.objects.create(data_source=data_source, detector=detector)

@staticmethod
@assume_test_silo_mode(SiloMode.REGION)
def create_action(**kwargs) -> Action:
return Action.objects.create(**kwargs)

@staticmethod
@assume_test_silo_mode(SiloMode.REGION)
def create_detector_workflow(
detector: Detector | None = None,
workflow: Workflow | None = None,
**kwargs,
) -> DetectorWorkflow:
if detector is None:
detector = Factories.create_detector()
if workflow is None:
workflow = Factories.create_workflow()
return DetectorWorkflow.objects.create(detector=detector, workflow=workflow, **kwargs)

@staticmethod
@assume_test_silo_mode(SiloMode.REGION)
def create_data_condition_group_action(
action: Action | None = None,
condition_group: DataConditionGroup | None = None,
**kwargs,
) -> DataConditionGroupAction:
if action is None:
action = Factories.create_action()
if condition_group is None:
condition_group = Factories.create_data_condition_group()
return DataConditionGroupAction.objects.create(
action=action, condition_group=condition_group, **kwargs
)
Loading
Loading