-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(workflow_engine): Add
process_data_packets
method (#82002)
## Description Adding a wrapper method, `process_data_packets` to merge the process_data_sources and process_detectors. Still thinking through higher level abstractions to simplify using the workflow_engine, but this should simplify integrations a little further for now.
- Loading branch information
1 parent
f6caae2
commit 0142957
Showing
8 changed files
with
109 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from sentry.workflow_engine.handlers.detector import DetectorEvaluationResult | ||
from sentry.workflow_engine.models import DataPacket, Detector | ||
from sentry.workflow_engine.processors.data_source import process_data_sources | ||
from sentry.workflow_engine.processors.detector import process_detectors | ||
from sentry.workflow_engine.types import DetectorGroupKey | ||
|
||
|
||
def process_data_packets( | ||
data_packets: list[DataPacket], query_type: str | ||
) -> list[tuple[Detector, dict[DetectorGroupKey, DetectorEvaluationResult]]]: | ||
""" | ||
This method ties the two main pre-processing methods together to process | ||
the incoming data and create issue occurrences. | ||
""" | ||
processed_sources = process_data_sources(data_packets, query_type) | ||
|
||
results: list[tuple[Detector, dict[DetectorGroupKey, DetectorEvaluationResult]]] = [] | ||
for data_packet, detectors in processed_sources: | ||
detector_results = process_detectors(data_packet, detectors) | ||
|
||
for detector, detector_state in detector_results: | ||
results.append((detector, detector_state)) | ||
|
||
return results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
tests/sentry/workflow_engine/processors/test_data_packet.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from sentry.workflow_engine.processors.data_packet import process_data_packets | ||
from sentry.workflow_engine.types import DetectorPriorityLevel | ||
from tests.sentry.workflow_engine.test_base import BaseWorkflowTest | ||
|
||
|
||
class TestProcessDataPacket(BaseWorkflowTest): | ||
def setUp(self): | ||
self.snuba_query = self.create_snuba_query() | ||
|
||
(self.workflow, self.detector, self.detector_workflow, self.workflow_triggers) = ( | ||
self.create_detector_and_workflow() | ||
) | ||
|
||
self.data_source, self.data_packet = self.create_test_query_data_source(self.detector) | ||
|
||
def test_single_data_packet(self): | ||
results = process_data_packets([self.data_packet], "snuba_query_subscription") | ||
assert len(results) == 1 | ||
|
||
detector, detector_evaluation_result = results[0] | ||
assert detector_evaluation_result[None].priority == DetectorPriorityLevel.HIGH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters