Skip to content

Commit

Permalink
ref(sessions): Remove sessions from incidents code (#68764)
Browse files Browse the repository at this point in the history
  • Loading branch information
lynnagara authored Apr 12, 2024
1 parent 3925c44 commit 3ae6392
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 21 deletions.
8 changes: 1 addition & 7 deletions src/sentry/incidents/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from django.utils import timezone as django_timezone
from snuba_sdk import Column, Condition, Limit, Op

from sentry import analytics, audit_log, features, quotas
from sentry import analytics, audit_log, quotas
from sentry.auth.access import SystemAccess
from sentry.constants import CRASH_RATE_ALERT_AGGREGATE_ALIAS, ObjectStatus
from sentry.incidents import tasks
Expand Down Expand Up @@ -467,7 +467,6 @@ class AlertRuleNameAlreadyUsedError(Exception):
Dataset.Events: SnubaQuery.Type.ERROR,
Dataset.Transactions: SnubaQuery.Type.PERFORMANCE,
Dataset.PerformanceMetrics: SnubaQuery.Type.PERFORMANCE,
Dataset.Sessions: SnubaQuery.Type.CRASH_RATE,
Dataset.Metrics: SnubaQuery.Type.CRASH_RATE,
}

Expand Down Expand Up @@ -726,11 +725,6 @@ def update_alert_rule(
if include_all_projects is not None:
updated_fields["include_all_projects"] = include_all_projects
if dataset is not None:
if dataset == Dataset.Sessions and features.has(
"organizations:alert-crash-free-metrics", alert_rule.organization, actor=user
):
dataset = Dataset.Metrics

if dataset.value != alert_rule.snuba_query.dataset:
updated_query_fields["dataset"] = dataset
if query_type is not None:
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/incidents/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
QUERY_TYPE_VALID_DATASETS = {
SnubaQuery.Type.ERROR: {Dataset.Events},
SnubaQuery.Type.PERFORMANCE: {Dataset.Transactions, Dataset.PerformanceMetrics},
SnubaQuery.Type.CRASH_RATE: {Dataset.Metrics, Dataset.Sessions},
SnubaQuery.Type.CRASH_RATE: {Dataset.Metrics},
}

# TODO(davidenwang): eventually we should pass some form of these to the event_search parser to raise an error
Expand Down
9 changes: 1 addition & 8 deletions src/sentry/incidents/serializers/alert_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,6 @@ def validate(self, data):

def _validate_query(self, data):
dataset = data.setdefault("dataset", Dataset.Events)
# If metric based crash rate alerts are enabled, coerce sessions over
if dataset == Dataset.Sessions and features.has(
"organizations:alert-crash-free-metrics",
self.context["organization"],
actor=self.context.get("user", None),
):
dataset = data["dataset"] = Dataset.Metrics

if features.has(
"organizations:custom-metrics",
Expand Down Expand Up @@ -413,7 +406,7 @@ def _translate_thresholds(self, threshold_type, comparison_delta, triggers, data

@staticmethod
def _validate_time_window(dataset, time_window):
if dataset in [Dataset.Sessions, Dataset.Metrics]:
if dataset == Dataset.Metrics:
# Validate time window
if time_window not in CRASH_RATE_ALERTS_ALLOWED_TIME_WINDOWS:
raise serializers.ValidationError(
Expand Down
4 changes: 1 addition & 3 deletions src/sentry/incidents/subscription_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,7 @@ def _get_crash_rate_alert_metrics_aggregation_value_v2(
return aggregation_value

def get_aggregation_value(self, subscription_update: QuerySubscriptionUpdate) -> float | None:
if self.subscription.snuba_query.dataset == Dataset.Sessions.value:
aggregation_value = self.get_crash_rate_alert_aggregation_value(subscription_update)
elif self.subscription.snuba_query.dataset == Dataset.Metrics.value:
if self.subscription.snuba_query.dataset == Dataset.Metrics.value:
aggregation_value = self.get_crash_rate_alert_metrics_aggregation_value(
subscription_update
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ def setUp(self):
"projects": [self.project.slug],
"owner": self.user.id,
"name": "JustAValidTestRule",
"dataset": "sessions",
"dataset": "metrics",
"eventTypes": [],
}

Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/integrations/slack/test_unfurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def test_unfurl_metric_alerts_chart_crash_free(self, mock_generate_chart):
alert_rule = self.create_alert_rule(
query="",
aggregate="percentage(sessions_crashed, sessions) AS _crash_rate_alert_aggregate",
dataset=Dataset.Sessions,
dataset=Dataset.Metrics,
time_window=60,
resolve_threshold=10,
threshold_period=1,
Expand Down

0 comments on commit 3ae6392

Please sign in to comment.