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(ACI): Detector details PUT endpoint #84098

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

ceorourke
Copy link
Member

Create a PUT endpoint for detector details.

Addresses https://getsentry.atlassian.net/browse/ACI-114

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jan 27, 2025
Copy link

codecov bot commented Jan 27, 2025

❌ 2 Tests Failed:

Tests completed Failed Passed Skipped
23503 2 23501 290
View the top 2 failed test(s) by shortest run time
tests.sentry.workflow_engine.endpoints.test_project_detector_details.ProjectDetectorDetailsPutTest::test_update_add_data_condition
Stack Traces | 3.06s run time
#x1B[1m#x1B[.../workflow_engine/endpoints/test_project_detector_details.py#x1B[0m:213: in test_update_add_data_condition
    response = self.get_success_response(
#x1B[1m#x1B[.../sentry/testutils/cases.py#x1B[0m:688: in get_success_response
    assert_status_code(response, status_code)
#x1B[1m#x1B[.../sentry/testutils/asserts.py#x1B[0m:40: in assert_status_code
    assert minimum <= response.status_code < maximum, (
#x1B[1m#x1B[31mE   AssertionError: (400, b'["SnubaQuery not found, can\'t update"]')#x1B[0m
#x1B[1m#x1B[31mE   assert 400 < 201#x1B[0m
#x1B[1m#x1B[31mE    +  where 400 = <Response status_code=400, "application/json">.status_code#x1B[0m
tests.sentry.workflow_engine.endpoints.test_project_detector_details.ProjectDetectorDetailsPutTest::test_update
Stack Traces | 3.53s run time
#x1B[1m#x1B[.../workflow_engine/endpoints/test_project_detector_details.py#x1B[0m:168: in test_update
    response = self.get_success_response(
#x1B[1m#x1B[.../sentry/testutils/cases.py#x1B[0m:688: in get_success_response
    assert_status_code(response, status_code)
#x1B[1m#x1B[.../sentry/testutils/asserts.py#x1B[0m:40: in assert_status_code
    assert minimum <= response.status_code < maximum, (
#x1B[1m#x1B[31mE   AssertionError: (400, b'["SnubaQuery not found, can\'t update"]')#x1B[0m
#x1B[1m#x1B[31mE   assert 400 < 201#x1B[0m
#x1B[1m#x1B[31mE    +  where 400 = <Response status_code=400, "application/json">.status_code#x1B[0m

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

Comment on lines +108 to +115
group_type = None
detector_group_type = detector.group_type

if detector_group_type:
group_type = request.data.get("detector_type") or detector_group_type.slug

if not group_type:
return Response(status=status.HTTP_400_BAD_REQUEST)
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 all for annoying typing reasons - if detector.group_type is None we can't get the slug

Copy link
Member

Choose a reason for hiding this comment

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

should we raise an exception if it's None in Detector.group_type so we can assume the return type is GroupType?

Comment on lines +108 to +115
group_type = None
detector_group_type = detector.group_type

if detector_group_type:
group_type = request.data.get("detector_type") or detector_group_type.slug

if not group_type:
return Response(status=status.HTTP_400_BAD_REQUEST)
Copy link
Member

Choose a reason for hiding this comment

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

should we raise an exception if it's None in Detector.group_type so we can assume the return type is GroupType?

raise serializers.ValidationError("DataConditionGroup not found, can't update")
# TODO make one if it doesn't exist and data is passed?

for data_condition in data_conditions:
Copy link
Member

Choose a reason for hiding this comment

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

would it be better to collect all the data conditions for the data condition group, delete them if they exist, and create new data conditions? we could use bulk_delete and bulk_create that way instead of one by one (fewer db hits) 🤔

def update_data_source(self, instance, data_source):
try:
source_instance = DataSource.objects.get(detector=instance)
except DataSource.DoesNotExist:
Copy link
Member

Choose a reason for hiding this comment

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

does the data source need to be created if you add it to an existing detector?

def update(self, instance, validated_data):
instance.name = validated_data.get("name", instance.name)
instance.type = validated_data.get("detector_type", instance.group_type).slug
condition_group = validated_data.pop("condition_group")
Copy link
Member

Choose a reason for hiding this comment

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

nit: is there a reason this is pop instead of get?

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.

3 participants