Skip to content

Commit 5936c6e

Browse files
committed
a bit fancier
1 parent 84ecdab commit 5936c6e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/sentry/workflow_engine/processors/workflow.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ def from_results(cls, results: Iterable[TriggerResult]) -> "EvaluationStats":
6969
untainted += 1
7070
return cls(tainted=tainted, untainted=untainted)
7171

72+
def __add__(self, other: "EvaluationStats") -> "EvaluationStats":
73+
return EvaluationStats(
74+
tainted=self.tainted + other.tainted,
75+
untainted=self.untainted + other.untainted,
76+
)
77+
7278
def report_metrics(self, metric_name: str) -> None:
7379
metrics_incr(metric_name, self.tainted, tags={"tainted": True})
7480
metrics_incr(metric_name, self.untainted, tags={"tainted": False})
@@ -567,11 +573,11 @@ def process_workflows(
567573
triggered_workflows, queue_items_by_workflow_id, trigger_stats = evaluate_workflow_triggers(
568574
workflows, event_data, event_start_time
569575
)
570-
trigger_stats.report_metrics("process_workflows.workflows_evaluated")
571576

572577
workflow_evaluation_data.triggered_workflows = set(triggered_workflows.keys())
573578

574579
if not triggered_workflows and not queue_items_by_workflow_id:
580+
trigger_stats.report_metrics("process_workflows.workflows_evaluated")
575581
# TODO - re-think tainted once the actions are removed from process_workflows.
576582
return WorkflowEvaluation(
577583
tainted=True,
@@ -586,7 +592,7 @@ def process_workflows(
586592
triggered_workflows, event_data, queue_items_by_workflow_id, event_start_time
587593
)
588594
)
589-
action_stats.report_metrics("process_workflows.workflows_evaluated")
595+
(trigger_stats + action_stats).report_metrics("process_workflows.workflows_evaluated")
590596

591597
enqueue_workflows(batch_client, queue_items_by_workflow_id)
592598

tests/sentry/workflow_engine/processors/test_workflow.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,11 @@ def test_action_filter_stats_excludes_delayed_workflows(self) -> None:
755755
assert self.workflow in queue_items
756756
assert stats == EvaluationStats(tainted=0, untainted=0)
757757

758+
def test_evaluation_stats_add(self) -> None:
759+
a = EvaluationStats(tainted=1, untainted=2)
760+
b = EvaluationStats(tainted=3, untainted=4)
761+
assert a + b == EvaluationStats(tainted=4, untainted=6)
762+
758763

759764
@freeze_time(FROZEN_TIME)
760765
class TestWorkflowEnqueuing(BaseWorkflowTest):

0 commit comments

Comments
 (0)