-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(aci): Add serialized data source to issue occurrence evidence data #103549
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 5 commits
d21d085
dfebb5f
0bcc481
2a5aed3
0c5c0c4
64225fe
bf0835b
9f39d35
3d4ea80
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 |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| from django.db.models import Q | ||
| from sentry_redis_tools.retrying_cluster import RetryingRedisCluster | ||
|
|
||
| from sentry.api.serializers import serialize | ||
| from sentry.issues.issue_occurrence import IssueOccurrence | ||
| from sentry.issues.status_change_message import StatusChangeMessage | ||
| from sentry.models.group import GroupStatus | ||
|
|
@@ -21,7 +22,7 @@ | |
| EventData, | ||
| GroupedDetectorEvaluationResult, | ||
| ) | ||
| from sentry.workflow_engine.models import DataPacket, Detector, DetectorState | ||
| from sentry.workflow_engine.models import DataPacket, DataSource, Detector, DetectorState | ||
| from sentry.workflow_engine.processors.data_condition_group import ( | ||
| ProcessedDataConditionGroup, | ||
| process_data_condition_group, | ||
|
|
@@ -353,6 +354,29 @@ def build_detector_evidence_data( | |
| """ | ||
| return {} | ||
|
|
||
| def _build_data_source_definition( | ||
| self, data_packet: DataPacket[DataPacketType] | ||
| ) -> dict[str, Any] | None: | ||
| try: | ||
| data_source = DataSource.objects.filter( | ||
| detectors=self.detector, source_id=data_packet.source_id | ||
| ).first() | ||
|
||
| if not data_source: | ||
| logger.warning( | ||
| "Matching data source not found for detector while generating occurrence evidence data", | ||
| extra={ | ||
| "detector_id": self.detector.id, | ||
| "data_packet_source_id": data_packet.source_id, | ||
| }, | ||
| ) | ||
| return None | ||
| return serialize(data_source) | ||
| except Exception: | ||
| logger.exception( | ||
| "Failed to serialize data source definition when building workflow engine evidence data" | ||
| ) | ||
| return None | ||
malwilley marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def _build_workflow_engine_evidence_data( | ||
| self, | ||
| evaluation_result: ProcessedDataConditionGroup, | ||
|
|
@@ -363,15 +387,18 @@ def _build_workflow_engine_evidence_data( | |
| Build the workflow engine specific evidence data. | ||
| This is data that is common to all detectors. | ||
| """ | ||
| return { | ||
| base: dict[str, Any] = { | ||
| "detector_id": self.detector.id, | ||
| "value": evaluation_value, | ||
| "data_packet_source_id": str(data_packet.source_id), | ||
| "conditions": [ | ||
| result.condition.get_snapshot() for result in evaluation_result.condition_results | ||
| ], | ||
| "data_source_definition": self._build_data_source_definition(data_packet), | ||
| } | ||
|
|
||
| return base | ||
malwilley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def evaluate_impl( | ||
| self, data_packet: DataPacket[DataPacketType] | ||
| ) -> GroupedDetectorEvaluationResult: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also wanted to call out that I'm adding a property to this dataclass and I know python will raise an exception when instantiating if it doesn't exist. Is it safe to do this? Want to make sure this won't start failing for old event data when this is merged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 it should be okay, but might want to set a default value to
Noneto be safe.afaik, we only apply this dataclass to the write on an issue occurrence, and when we're fetching for the API we just pass it through the serializer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay added a default value, but I agree I think it would probably be okay without one