Skip to content

Commit

Permalink
🔧 chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iamrajjoshi committed Feb 26, 2025
1 parent 2a016c2 commit 710007f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
18 changes: 8 additions & 10 deletions src/sentry/integrations/metric_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def get_metric_count_from_incident(incident: Incident) -> float | None:
def get_incident_status_text(
snuba_query: SnubaQuery,
threshold_type: AlertRuleThresholdType | None,
comparison_delta: ComparisonDeltaChoices | None,
comparison_delta: int | None,
metric_value: str,
) -> str:
"""Returns a human readable current status of an incident"""
Expand All @@ -118,10 +118,8 @@ def get_incident_status_text(
# % change alerts have a comparison delta
if comparison_delta:
metric_and_agg_text = f"{agg_text.capitalize()} {int(float(metric_value))}%"
higher_or_lower = (
"higher" if threshold_type.value == AlertRuleThresholdType.ABOVE.value else "lower"
)
comparison_delta_minutes = comparison_delta.value // 60
higher_or_lower = "higher" if threshold_type == AlertRuleThresholdType.ABOVE else "lower"
comparison_delta_minutes = comparison_delta // 60
comparison_string = TEXT_COMPARISON_DELTA.get(
comparison_delta_minutes, f"same time {comparison_delta_minutes} minutes ago"
)
Expand Down Expand Up @@ -179,12 +177,12 @@ def incident_attachment_info(

text = get_incident_status_text(
alert_rule.snuba_query,
AlertRuleThresholdType(alert_rule.threshold_type) if alert_rule.threshold_type else None,
(
ComparisonDeltaChoices(alert_rule.comparison_delta)
if alert_rule.comparison_delta
AlertRuleThresholdType(alert_rule.threshold_type)
if alert_rule.threshold_type is not None
else None
),
alert_rule.comparison_delta,
str(metric_value),
)
if features.has(
Expand Down Expand Up @@ -270,12 +268,12 @@ def metric_alert_unfurl_attachment_info(
alert_rule.snuba_query,
(
AlertRuleThresholdType(alert_rule.threshold_type)
if alert_rule.threshold_type
if alert_rule.threshold_type is not None
else None
),
(
ComparisonDeltaChoices(alert_rule.comparison_delta)
if alert_rule.comparison_delta
if alert_rule.comparison_delta is not None
else None
),
str(metric_value),
Expand Down
13 changes: 9 additions & 4 deletions tests/sentry/integrations/test_metric_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.utils import timezone

from sentry.incidents.logic import CRITICAL_TRIGGER_LABEL
from sentry.incidents.models.alert_rule import AlertRuleDetectionType
from sentry.incidents.models.alert_rule import AlertRuleDetectionType, AlertRuleThresholdType
from sentry.incidents.models.incident import IncidentStatus, IncidentTrigger
from sentry.integrations.metric_alerts import incident_attachment_info
from sentry.snuba.dataset import Dataset
Expand Down Expand Up @@ -134,7 +134,9 @@ def test_with_incident_trigger(self):
def test_percent_change_alert(self):
# 1 hour comparison_delta
alert_rule = self.create_alert_rule(
comparison_delta=60, detection_type=AlertRuleDetectionType.PERCENT
comparison_delta=60,
detection_type=AlertRuleDetectionType.PERCENT,
threshold_type=AlertRuleThresholdType.ABOVE,
)
date_started = self.now
incident = self.create_incident(
Expand All @@ -161,6 +163,7 @@ def test_percent_change_alert_rpc(self):
alert_rule = self.create_alert_rule(
comparison_delta=60,
detection_type=AlertRuleDetectionType.PERCENT,
threshold_type=AlertRuleThresholdType.ABOVE,
dataset=Dataset.EventsAnalyticsPlatform,
query_type=SnubaQuery.Type.PERFORMANCE,
)
Expand All @@ -185,9 +188,11 @@ def test_percent_change_alert_rpc(self):
)

def test_percent_change_alert_custom_comparison_delta(self):
# 12 hour comparison_delta
alert_rule = self.create_alert_rule(
comparison_delta=60 * 12, detection_type=AlertRuleDetectionType.PERCENT
# 1 month comparison_delta
comparison_delta=720,
threshold_type=AlertRuleThresholdType.ABOVE,
detection_type=AlertRuleDetectionType.PERCENT,
)
date_started = self.now
incident = self.create_incident(
Expand Down

0 comments on commit 710007f

Please sign in to comment.