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

chore(aci): enforce config schema without subclassing #81979

Merged
merged 12 commits into from
Dec 13, 2024

Conversation

cathteng
Copy link
Member

@cathteng cathteng commented Dec 11, 2024

We will have many detectors of different types with different config schemas that need to be enforced. Instead of subclassing and using a Django proxy model we can link the config schema to GroupType and enforce it via a pre-save signal.

Workflows similarly have a config schema to enforce but all of them have the same schema. So we use a different pre-save signal function for it and a hardcoded schema.

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Dec 11, 2024
Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 96.15385% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/sentry/workflow_engine/models/detector.py 88.88% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master   #81979   +/-   ##
=======================================
  Coverage   80.35%   80.36%           
=======================================
  Files        7279     7280    +1     
  Lines      321322   321394   +72     
  Branches    20957    20957           
=======================================
+ Hits       258207   258284   +77     
+ Misses      62701    62696    -5     
  Partials      414      414           

cathteng

This comment was marked as outdated.

@@ -121,9 +121,16 @@ def test_state_results_multi_group(self, mock_produce_occurrence_to_kafka):
)

def test_no_issue_type(self):
detector = self.create_detector(type="invalid slug")
Copy link
Member Author

Choose a reason for hiding this comment

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

with this PR we can no longer create a detector with an invalid slug, so substituting with creating a valid detector and mocking that the GroupType gets deleted

@cathteng cathteng marked this pull request as ready for review December 12, 2024 17:31
@cathteng cathteng requested review from a team as code owners December 12, 2024 17:31
@cathteng cathteng requested a review from a team December 12, 2024 17:31
Comment on lines 175 to 177
detector_handler: type[DetectorHandler] | None = None
detector_validator: type[BaseGroupTypeDetectorValidator] | None = None
detector_config_schema: dict[str, Any] | None = None
Copy link
Member

Choose a reason for hiding this comment

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

It's starting to feel like we just need something like DetectorConfig that encapsulates all of these. Probably something for a separate pr

src/sentry/workflow_engine/models/detector.py Outdated Show resolved Hide resolved
Comment on lines +41 to +42
# TODO: fill in
return {}
Copy link
Member

Choose a reason for hiding this comment

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

Is the plan to use subclasses here? Won't we run into the same problem we proxy models?

Copy link
Member Author

Choose a reason for hiding this comment

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

there isn't a type on workflow so all of them should have the same config schema

Copy link
Member

Choose a reason for hiding this comment

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

I'm not too clear on what these configs are going to be... If they're consistent for all Workflows this is fine though

src/sentry/issues/grouptype.py Outdated Show resolved Hide resolved
src/sentry/utils/registry.py Outdated Show resolved Hide resolved
Comment on lines +112 to +113
config_schema = group_type.detector_config_schema
instance.validate_config(config_schema)
Copy link
Member

Choose a reason for hiding this comment

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

We should probably also check that detector_config_schema is set too

Copy link
Member Author

Choose a reason for hiding this comment

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

this is set to an empty dict by default in GroupType, do we need anything else?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I guess that's fine... One problem with defaulting it to an empty dict is that if people forget to add it then they won't get an error, but this works as is

src/sentry/workflow_engine/models/workflow.py Outdated Show resolved Hide resolved
src/sentry/workflow_engine/models/workflow.py Outdated Show resolved Hide resolved
@cathteng cathteng merged commit 4e3eed6 into master Dec 13, 2024
49 checks passed
@cathteng cathteng deleted the cathy/aci/enforce-schema-sans-proxy branch December 13, 2024 19:17
Copy link

sentry-io bot commented Dec 15, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ IntegrityError: UniqueViolation('duplicate key value violates unique constraint "auth_user_username_key"\nDETAIL:... pytest.runtest.protocol tests/sentry/workflow_e... View Issue

Did you find this useful? React with a 👍 or 👎

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