-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(ACI): Send updated data to Seer on all snuba query changes #103332
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| from datetime import timedelta | ||
| from typing import Any, cast | ||
| from typing import Any | ||
|
|
||
| from rest_framework import serializers | ||
|
|
||
|
|
@@ -241,7 +241,9 @@ def is_editing_transaction_dataset( | |
| return True | ||
| return False | ||
|
|
||
| def update_data_source(self, instance: Detector, data_source: SnubaQueryDataSourceType): | ||
| def update_data_source( | ||
| self, instance: Detector, data_source: SnubaQueryDataSourceType, seer_updated: bool = False | ||
| ): | ||
| try: | ||
| source_instance = DataSource.objects.get(detector=instance) | ||
| except DataSource.DoesNotExist: | ||
|
|
@@ -276,17 +278,15 @@ def update_data_source(self, instance: Detector, data_source: SnubaQueryDataSour | |
|
|
||
| # Handle a dynamic detector's snuba query changing | ||
| if instance.config.get("detection_type") == AlertRuleDetectionType.DYNAMIC: | ||
| if snuba_query.query != data_source.get( | ||
| "query" | ||
| ) or snuba_query.aggregate != data_source.get("aggregate"): | ||
| try: | ||
| validated_data_source = cast(dict[str, Any], data_source) | ||
| try: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Incorrect Enum Comparison Always FailsThe comparison checks if
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think cursor understands string enums. My tests would fail if this were true. |
||
| validated_data_source: dict[str, Any] = {"data_sources": [data_source]} | ||
| if not seer_updated: | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| update_detector_data(instance, validated_data_source) | ||
| except Exception: | ||
| # don't update the snuba query if we failed to send data to Seer | ||
| raise serializers.ValidationError( | ||
| "Failed to send data to Seer, cannot update detector" | ||
| ) | ||
| except Exception: | ||
| # don't update the snuba query if we failed to send data to Seer | ||
| raise serializers.ValidationError( | ||
| "Failed to send data to Seer, cannot update detector" | ||
| ) | ||
|
|
||
| update_snuba_query( | ||
| snuba_query=snuba_query, | ||
|
|
@@ -304,6 +304,7 @@ def update_data_source(self, instance: Detector, data_source: SnubaQueryDataSour | |
| ) | ||
|
|
||
| def update(self, instance: Detector, validated_data: dict[str, Any]): | ||
| seer_updated = False | ||
| # Handle anomaly detection changes first in case we need to exit before saving | ||
| if ( | ||
| not instance.config.get("detection_type") == AlertRuleDetectionType.DYNAMIC | ||
|
|
@@ -313,6 +314,8 @@ def update(self, instance: Detector, validated_data: dict[str, Any]): | |
| # Detector has been changed to become a dynamic detector | ||
| try: | ||
| update_detector_data(instance, validated_data) | ||
| seer_updated = True | ||
|
|
||
| except Exception: | ||
| # Don't update if we failed to send data to Seer | ||
| raise serializers.ValidationError( | ||
|
|
@@ -339,7 +342,7 @@ def update(self, instance: Detector, validated_data: dict[str, Any]): | |
| data_source = validated_data.pop("data_sources")[0] | ||
|
|
||
| if data_source is not None: | ||
| self.update_data_source(instance, data_source) | ||
| self.update_data_source(instance, data_source, seer_updated) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Transactional Flaw Leaves Detector InconsistentThe detector update lacks transactional consistency. The parent's |
||
|
|
||
| instance.save() | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,7 +100,7 @@ def update_detector_data( | |
| updated_data_source_data = updated_fields.get("data_sources") | ||
| if updated_data_source_data: | ||
| data_source_data = updated_data_source_data[0] | ||
| event_types = data_source_data.get("eventTypes") | ||
| event_types = data_source_data.get("event_types") | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was just incorrect before, oops
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mind adding a test for this to ensure everything is working as expected with this change?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added 👍
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Inconsistent Data: Mixing Stale and Current ValuesWhen |
||
|
|
||
| for k, v in data_source_data.items(): | ||
| if k == "dataset": | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.