Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/sentry/debug_files/artifact_bundles.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import annotations

import logging
from datetime import datetime, timedelta

import psycopg2.errors
import sentry_sdk
from django.conf import settings
from django.db import router
from django.db import OperationalError, router
from django.db.models import Count, Exists, OuterRef
from django.utils import timezone
from sentry_redis_tools.clients import RedisCluster
Expand All @@ -25,6 +27,8 @@
from sentry.utils import metrics, redis
from sentry.utils.db import atomic_transaction

logger = logging.getLogger(__name__)

# The number of Artifact Bundles that we return in case of incomplete indexes.
MAX_BUNDLES_QUERY = 5

Expand Down Expand Up @@ -311,8 +315,23 @@ def update_bundles(bundles: set[tuple[int, datetime]], resolved: str):

# Then, we are matching by `url`:
if url:
bundles = get_artifact_bundles_containing_url(project, release, dist, url)
update_bundles(bundles, "index")
try:
bundles = get_artifact_bundles_containing_url(project, release, dist, url)
except OperationalError as e:
# The `url__icontains` lookup can be very expensive for some orgs, and gets
# canceled when it runs into a (possibly per-org lowered) statement timeout.
# In that case we degrade to whatever bundles we already found.
if not isinstance(e.__cause__, psycopg2.errors.QueryCanceled):
raise
logger.warning(
"artifact_bundles.url_lookup_canceled",
extra={
"organization_id": project.organization_id,
"project_id": project.id,
},
)
else:
update_bundles(bundles, "index")

return _maybe_renew_and_return_bundles(artifact_bundles)

Expand Down
Loading