From a7e07d631db878252bd36c302ec9d02e438e1c62 Mon Sep 17 00:00:00 2001 From: Jodi Jang Date: Tue, 23 Jul 2024 09:44:17 -0700 Subject: [PATCH 1/2] chore(similarity): Add seer failure reason to backfill log --- src/sentry/seer/similarity/grouping_records.py | 5 +++-- .../backfill_seer_grouping_records_for_project.py | 1 + tests/sentry/seer/similarity/test_grouping_records.py | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/sentry/seer/similarity/grouping_records.py b/src/sentry/seer/similarity/grouping_records.py index 2e7e3523a71ebf..f8f54a4d104b33 100644 --- a/src/sentry/seer/similarity/grouping_records.py +++ b/src/sentry/seer/similarity/grouping_records.py @@ -36,6 +36,7 @@ class CreateGroupingRecordsRequest(TypedDict): class BulkCreateGroupingRecordsResponse(TypedDict): success: bool groups_with_neighbor: NotRequired[dict[str, RawSeerSimilarIssueData]] + reason: NotRequired[str] seer_grouping_connection_pool = connection_from_url( @@ -69,7 +70,7 @@ def post_bulk_grouping_records( except ReadTimeoutError: extra.update({"reason": "ReadTimeoutError", "timeout": POST_BULK_GROUPING_RECORDS_TIMEOUT}) logger.info("seer.post_bulk_grouping_records.failure", extra=extra) - return {"success": False} + return {"success": False, "reason": "ReadTimeoutError"} if response.status >= 200 and response.status < 300: logger.info("seer.post_bulk_grouping_records.success", extra=extra) @@ -77,7 +78,7 @@ def post_bulk_grouping_records( else: extra.update({"reason": response.reason}) logger.info("seer.post_bulk_grouping_records.failure", extra=extra) - return {"success": False} + return {"success": False, "reason": response.reason} def delete_project_grouping_records( diff --git a/src/sentry/tasks/embeddings_grouping/backfill_seer_grouping_records_for_project.py b/src/sentry/tasks/embeddings_grouping/backfill_seer_grouping_records_for_project.py index 37129851b84124..9a62146e02a309 100644 --- a/src/sentry/tasks/embeddings_grouping/backfill_seer_grouping_records_for_project.py +++ b/src/sentry/tasks/embeddings_grouping/backfill_seer_grouping_records_for_project.py @@ -199,6 +199,7 @@ def backfill_seer_grouping_records_for_project( extra={ "current_project_id": current_project_id, "last_processed_project_index": last_processed_project_index, + "reason": seer_response.get("reason"), }, ) sentry_sdk.capture_exception(Exception("Seer failed during backfill")) diff --git a/tests/sentry/seer/similarity/test_grouping_records.py b/tests/sentry/seer/similarity/test_grouping_records.py index 11c69706b6290d..06a24ab40b8771 100644 --- a/tests/sentry/seer/similarity/test_grouping_records.py +++ b/tests/sentry/seer/similarity/test_grouping_records.py @@ -68,7 +68,7 @@ def test_post_bulk_grouping_records_success(mock_seer_request: MagicMock, mock_l @mock.patch("sentry.seer.similarity.grouping_records.logger") @mock.patch("sentry.seer.similarity.grouping_records.seer_grouping_connection_pool.urlopen") def test_post_bulk_grouping_records_timeout(mock_seer_request: MagicMock, mock_logger: MagicMock): - expected_return_value = {"success": False} + expected_return_value = {"success": False, "reason": "ReadTimeoutError"} mock_seer_request.side_effect = ReadTimeoutError( DUMMY_POOL, settings.SEER_AUTOFIX_URL, "read timed out" ) @@ -91,7 +91,7 @@ def test_post_bulk_grouping_records_timeout(mock_seer_request: MagicMock, mock_l @mock.patch("sentry.seer.similarity.grouping_records.logger") @mock.patch("sentry.seer.similarity.grouping_records.seer_grouping_connection_pool.urlopen") def test_post_bulk_grouping_records_failure(mock_seer_request: MagicMock, mock_logger: MagicMock): - expected_return_value = {"success": False} + expected_return_value = {"success": False, "reason": "INTERNAL SERVER ERROR"} mock_seer_request.return_value = HTTPResponse( b"\n\n500 Internal Server Error\n

Internal Server Error

\n

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

\n", reason="INTERNAL SERVER ERROR", From e77245b16ed34224022634423a5a9ac9fa14ec07 Mon Sep 17 00:00:00 2001 From: Jodi Jang Date: Tue, 23 Jul 2024 09:50:38 -0700 Subject: [PATCH 2/2] fix: Typing --- src/sentry/seer/similarity/grouping_records.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sentry/seer/similarity/grouping_records.py b/src/sentry/seer/similarity/grouping_records.py index f8f54a4d104b33..461b0b1e3c07f3 100644 --- a/src/sentry/seer/similarity/grouping_records.py +++ b/src/sentry/seer/similarity/grouping_records.py @@ -36,7 +36,7 @@ class CreateGroupingRecordsRequest(TypedDict): class BulkCreateGroupingRecordsResponse(TypedDict): success: bool groups_with_neighbor: NotRequired[dict[str, RawSeerSimilarIssueData]] - reason: NotRequired[str] + reason: NotRequired[str | None] seer_grouping_connection_pool = connection_from_url(