Skip to content

Commit 2e59e02

Browse files
authored
ref(similarity): Catch all seer exceptions in backfill (#75104)
Catch all seer exceptions in retry in backfill
1 parent 709e8b2 commit 2e59e02

File tree

2 files changed

+46
-23
lines changed

2 files changed

+46
-23
lines changed

src/sentry/tasks/embeddings_grouping/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,12 @@ def _make_seer_call(
352352
create_grouping_records_request,
353353
retries=3,
354354
delay=2,
355-
exceptions=ServiceUnavailable,
355+
exceptions=Exception,
356356
)
357-
except ServiceUnavailable:
357+
except Exception as e:
358358
logger.exception(
359-
"tasks.backfill_seer_grouping_records.seer_service_unavailable",
360-
extra={"project_id": project_id},
359+
"tasks.backfill_seer_grouping_records.seer_exception_after_retries",
360+
extra={"project_id": project_id, "error": e},
361361
)
362362
raise
363363

tests/sentry/tasks/test_backfill_seer_grouping_records.py

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from random import choice
66
from string import ascii_uppercase
77
from typing import Any
8-
from unittest.mock import call, patch
8+
from unittest.mock import ANY, call, patch
99

1010
import pytest
1111
from django.test import override_settings
@@ -241,15 +241,15 @@ def test_lookup_group_data_stacktrace_bulk_exceptions(
241241
mock_get_multi.side_effect = exception
242242
with pytest.raises(Exception):
243243
lookup_group_data_stacktrace_bulk(self.project, rows)
244-
mock_logger.exception.assert_called_with(
245-
"tasks.backfill_seer_grouping_records.bulk_event_lookup_exception",
246-
extra={
247-
"organization_id": self.project.organization.id,
248-
"project_id": self.project.id,
249-
"group_data": json.dumps(rows),
250-
"error": exception.message,
251-
},
252-
)
244+
mock_logger.exception.assert_called_with(
245+
"tasks.backfill_seer_grouping_records.bulk_event_lookup_exception",
246+
extra={
247+
"organization_id": self.project.organization.id,
248+
"project_id": self.project.id,
249+
"node_keys": ANY,
250+
"error": exception.message,
251+
},
252+
)
253253

254254
def test_lookup_group_data_stacktrace_bulk_not_stacktrace_grouping(self):
255255
"""
@@ -446,7 +446,7 @@ def test_get_data_from_snuba(self):
446446
assert group_id in group_ids_results
447447

448448
@patch("sentry.tasks.embeddings_grouping.utils.logger")
449-
@patch("sentry.utils.snuba.bulk_snuba_queries")
449+
@patch("sentry.tasks.embeddings_grouping.utils.bulk_snuba_queries")
450450
def test_get_data_from_snuba_exception(self, mock_bulk_snuba_queries, mock_logger):
451451
mock_bulk_snuba_queries.side_effect = RateLimitExceeded
452452

@@ -455,14 +455,14 @@ def test_get_data_from_snuba_exception(self, mock_bulk_snuba_queries, mock_logge
455455
}
456456
with pytest.raises(Exception):
457457
get_data_from_snuba(self.project, group_ids_last_seen)
458-
mock_logger.exception.assert_called_with(
459-
"tasks.backfill_seer_grouping_records.snuba_query_exception",
460-
extra={
461-
"organization_id": self.project.organization.id,
462-
"project_id": self.project.id,
463-
"error": "Snuba Rate Limit Exceeded",
464-
},
465-
)
458+
mock_logger.exception.assert_called_with(
459+
"tasks.backfill_seer_grouping_records.snuba_query_exception",
460+
extra={
461+
"organization_id": self.project.organization.id,
462+
"project_id": self.project.id,
463+
"error": "Snuba Rate Limit Exceeded",
464+
},
465+
)
466466

467467
@with_feature("projects:similarity-embeddings-backfill")
468468
@patch("sentry.tasks.embeddings_grouping.utils.post_bulk_grouping_records")
@@ -1541,6 +1541,29 @@ def test_backfill_seer_grouping_records_no_enable_ingestion(
15411541

15421542
assert self.project.get_option("sentry:similarity_backfill_completed") is None
15431543

1544+
@with_feature("projects:similarity-embeddings-backfill")
1545+
@patch("time.sleep", return_value=None)
1546+
@patch("sentry.tasks.embeddings_grouping.utils.logger")
1547+
@patch("sentry.tasks.embeddings_grouping.utils.post_bulk_grouping_records")
1548+
def test_backfill_seer_grouping_records_seer_exception(
1549+
self, mock_post_bulk_grouping_records, mock_logger, mock_sleep
1550+
):
1551+
"""
1552+
Test log after seer exception and retries.
1553+
"""
1554+
exception = ServiceUnavailable(message="Service Unavailable")
1555+
mock_post_bulk_grouping_records.side_effect = exception
1556+
with pytest.raises(Exception), TaskRunner():
1557+
backfill_seer_grouping_records_for_project(self.project.id, None)
1558+
1559+
mock_logger.exception.assert_called_with(
1560+
"tasks.backfill_seer_grouping_records.seer_exception_after_retries",
1561+
extra={
1562+
"project_id": self.project.id,
1563+
"error": exception,
1564+
},
1565+
)
1566+
15441567
@with_feature("projects:similarity-embeddings-backfill")
15451568
@patch("sentry.tasks.embeddings_grouping.backfill_seer_grouping_records_for_project.logger")
15461569
def test_backfill_seer_grouping_records_skip_project_already_processed(self, mock_logger):

0 commit comments

Comments
 (0)