Skip to content

Commit

Permalink
Bust Symbolicator list_files cache on uploads
Browse files Browse the repository at this point in the history
By attaching a random querystring parameter to the Sentry internal source, this will cause a cache miss in Symbolicators `list_files` cache, thus fetching and discovering the uploaded debug file immediately.
  • Loading branch information
Swatinem committed Jul 18, 2023
1 parent 54a1d8f commit 435308b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/sentry/lang/native/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import sys
from copy import deepcopy
from datetime import datetime

import jsonschema
import sentry_sdk
Expand All @@ -10,7 +11,8 @@

from sentry import features, options
from sentry.auth.system import get_system_token
from sentry.utils import json, safe
from sentry.models.project import Project
from sentry.utils import json, redis, safe

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -115,6 +117,22 @@
},
}

default_cluster = redis.redis_clusters.get("default")
LAST_UPLOAD_TTL = 24 * 3600


def _last_upload_key(project_id: int) -> str:
return f"symbols:last_upload:{project_id}"


def record_last_upload(project: Project):
timestamp = int(datetime.utcnow().timestamp() * 1000)
default_cluster.setex(_last_upload_key(project.id), LAST_UPLOAD_TTL, timestamp)


def get_last_upload(project_id: int):
return default_cluster.get(_last_upload_key(project_id))


class InvalidSourcesError(Exception):
pass
Expand All @@ -137,7 +155,7 @@ def get_internal_url_prefix() -> str:
return internal_url_prefix.rstrip("/")


def get_internal_source(project):
def get_internal_source(project: Project):
"""
Returns the source configuration for a Sentry project.
"""
Expand All @@ -149,6 +167,9 @@ def get_internal_source(project):
),
)

if last_upload := get_last_upload(project.id):
sentry_source_url += f"?_last_upload={last_upload}"

return {
"type": "sentry",
"id": INTERNAL_SOURCE_NAME,
Expand All @@ -157,7 +178,7 @@ def get_internal_source(project):
}


def get_internal_artifact_lookup_source_url(project):
def get_internal_artifact_lookup_source_url(project: Project):
"""
Returns the url used as a part of source configuration for the Sentry artifact-lookup API.
"""
Expand All @@ -173,7 +194,7 @@ def get_internal_artifact_lookup_source_url(project):
)


def get_internal_artifact_lookup_source(project):
def get_internal_artifact_lookup_source(project: Project):
"""
Returns the source configuration for the Sentry artifact-lookup API.
"""
Expand All @@ -185,7 +206,7 @@ def get_internal_artifact_lookup_source(project):
}


def is_internal_source_id(source_id):
def is_internal_source_id(source_id: str):
"""Determines if a DIF object source identifier is reserved for internal sentry use.
This is trivial, but multiple functions in this file need to use the same definition.
Expand Down
2 changes: 2 additions & 0 deletions src/sentry/models/debugfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
region_silo_only_model,
sane_repr,
)
from sentry.lang.native.sources import record_last_upload
from sentry.models.files.file import File
from sentry.models.files.utils import clear_cached_files
from sentry.reprocessing import bump_reprocessing_revision, resolve_processing_issue
Expand Down Expand Up @@ -615,6 +616,7 @@ def create_files_from_dif_zip(
rv = create_debug_file_from_dif(to_create, project)

# Uploading new dsysm changes the reprocessing revision
record_last_upload(project)
bump_reprocessing_revision(project)

return rv
Expand Down
2 changes: 2 additions & 0 deletions src/sentry/tasks/assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def assemble_dif(project_id, name, checksum, chunks, debug_id=None, **kwargs):
"""
Assembles uploaded chunks into a ``ProjectDebugFile``.
"""
from sentry.lang.native.sources import record_last_upload
from sentry.models import BadDif, Project, debugfile
from sentry.reprocessing import bump_reprocessing_revision

Expand Down Expand Up @@ -239,6 +240,7 @@ def assemble_dif(project_id, name, checksum, chunks, debug_id=None, **kwargs):
# and might resolve processing issues. If the file was not
# created, someone else has created it and will bump the
# revision instead.
record_last_upload(project)
bump_reprocessing_revision(project, use_buffer=True)
except Exception:
set_assemble_status(
Expand Down

0 comments on commit 435308b

Please sign in to comment.