36
36
}
37
37
38
38
39
- def fetch_threshold_type (type : Condition ) -> AlertRuleThresholdType :
40
- return CONDITION_TO_ALERT_RULE_THRESHOLD_TYPE [type ]
39
+ def fetch_threshold_type (condition : dict [str , Any ]) -> AlertRuleThresholdType :
40
+ condition_type = condition ["type" ]
41
+ if condition_type == Condition .ANOMALY_DETECTION :
42
+ return condition ["comparison" ]["threshold_type" ]
43
+ return CONDITION_TO_ALERT_RULE_THRESHOLD_TYPE [condition_type ]
41
44
42
45
43
- def fetch_alert_threshold (comparison_value : float , group_status : GroupStatus ) -> float | None :
46
+ def fetch_alert_threshold (condition : dict [str , Any ], group_status : GroupStatus ) -> float | None :
47
+ condition_type = condition ["type" ]
48
+ if condition_type == Condition .ANOMALY_DETECTION :
49
+ return None
50
+ comparison_value = condition ["comparison" ]
44
51
if group_status == GroupStatus .RESOLVED or group_status == GroupStatus .IGNORED :
45
52
return None
46
53
else :
47
54
return comparison_value
48
55
49
56
50
- def fetch_resolve_threshold (comparison_value : float , group_status : GroupStatus ) -> float | None :
57
+ def fetch_resolve_threshold (condition : dict [ str , Any ] , group_status : GroupStatus ) -> float | None :
51
58
"""
52
59
This is the opposite of `fetch_alert_threshold`.
53
60
We keep it explicitly separate to make it clear that we are fetching the resolve threshold and to consolidate tech debt.
54
61
"""
62
+ condition_type = condition ["type" ]
63
+ if condition_type == Condition .ANOMALY_DETECTION :
64
+ return None
65
+ comparison_value = condition ["comparison" ]
55
66
if group_status == GroupStatus .RESOLVED or group_status == GroupStatus .IGNORED :
56
67
return comparison_value
57
68
else :
@@ -79,6 +90,12 @@ class AlertContext:
79
90
def from_alert_rule_incident (
80
91
cls , alert_rule : AlertRule , alert_rule_threshold : float | None = None
81
92
) -> AlertContext :
93
+ resolve_threshold = alert_rule .resolve_threshold
94
+
95
+ if alert_rule .detection_type == AlertRuleDetectionType .DYNAMIC :
96
+ alert_rule_threshold = None
97
+ resolve_threshold = None
98
+
82
99
return cls (
83
100
name = alert_rule .name ,
84
101
action_identifier_id = alert_rule .id ,
@@ -87,7 +104,7 @@ def from_alert_rule_incident(
87
104
comparison_delta = alert_rule .comparison_delta ,
88
105
sensitivity = alert_rule .sensitivity ,
89
106
alert_threshold = alert_rule_threshold ,
90
- resolve_threshold = alert_rule . resolve_threshold ,
107
+ resolve_threshold = resolve_threshold ,
91
108
)
92
109
93
110
@classmethod
@@ -109,9 +126,9 @@ def from_workflow_engine_models(
109
126
for cond in evidence_data .conditions
110
127
if cond ["condition_result" ] == target_priority
111
128
)
112
- threshold_type = fetch_threshold_type (Condition ( condition [ "type" ]) )
113
- resolve_threshold = fetch_resolve_threshold (condition [ "comparison" ] , group_status )
114
- alert_threshold = fetch_alert_threshold (condition [ "comparison" ] , group_status )
129
+ threshold_type = fetch_threshold_type (condition )
130
+ resolve_threshold = fetch_resolve_threshold (condition , group_status )
131
+ alert_threshold = fetch_alert_threshold (condition , group_status )
115
132
sensitivity = fetch_sensitivity (condition )
116
133
except StopIteration :
117
134
raise ValueError ("No threshold type found for metric issues" )
0 commit comments