Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(error-tracking): give S3 writes/deletes retry backoff and pace cleanup (#71393)

posthog[bot]481b3255f836
diff --git a/products/error_tracking/backend/temporal/symbol_set_cleanup/activities.py b/products/error_tracking/backend/temporal/symbol_set_cleanup/activities.py
index 40174de7fa8d..4f758a9be0fe 100644
--- a/products/error_tracking/backend/temporal/symbol_set_cleanup/activities.py
+++ b/products/error_tracking/backend/temporal/symbol_set_cleanup/activities.py
@@ -1,4 +1,6 @@
+import time
import datetime
+from itertools import batched
from django.db import close_old_connections, transaction
from django.db.models import Q
@@ -19,6 +21,9 @@ from products.error_tracking.backend.temporal.symbol_set_cleanup.types import (
logger = structlog.get_logger(__name__)
+_DELETE_REQUEST_BATCH_SIZE = 1000
+_DELETE_REQUEST_PACING_SECONDS = 0.1
+
def _cleanup_filter(inputs: SymbolSetCleanupInputs) -> Q:
cutoff_date = timezone.now() - datetime.timedelta(days=inputs.days_old)
@@ -49,6 +54,15 @@ def _delete_symbol_set_batch(symbol_set_ids: list[str]) -> tuple[int, set[str]]:
return left_deleted + right_deleted, left_failed | right_failed
+def _delete_symbol_set_contents_with_pacing(storage_ptrs: list[str]) -> list[str]:
+ failed_storage_ptrs: list[str] = []
+ for batch_number, storage_ptr_batch in enumerate(batched(storage_ptrs, _DELETE_REQUEST_BATCH_SIZE, strict=False)):
+ if batch_number > 0:
+ time.sleep(_DELETE_REQUEST_PACING_SECONDS)
+ failed_storage_ptrs.extend(delete_symbol_set_contents_many(list(storage_ptr_batch)))
+ return failed_storage_ptrs
+
+
@activity.defn
def cleanup_symbol_sets_activity(inputs: SymbolSetCleanupInputs) -> SymbolSetCleanupResult:
"""Delete stale symbol sets in bounded batches, preserving model delete behavior."""
@@ -116,7 +130,7 @@ def cleanup_symbol_sets_activity(inputs: SymbolSetCleanupInputs) -> SymbolSetCle
]
if deleted_storage_ptrs:
try:
- failed_storage_ptrs = delete_symbol_set_contents_many(deleted_storage_ptrs)
+ failed_storage_ptrs = _delete_symbol_set_contents_with_pacing(deleted_storage_ptrs)
except Exception as exc:
failed_storage_ptrs = deleted_storage_ptrs
logger.exception(
diff --git a/products/error_tracking/backend/temporal/symbol_set_cleanup/test/test_symbol_set_cleanup.py b/products/error_tracking/backend/temporal/symbol_set_cleanup/test/test_symbol_set_cleanup.py
index 35c18aec45e7..6e95b0d090a7 100644
--- a/products/error_tracking/backend/temporal/symbol_set_cleanup/test/test_symbol_set_cleanup.py
+++ b/products/error_tracking/backend/temporal/symbol_set_cleanup/test/test_symbol_set_cleanup.py
@@ -5,7 +5,7 @@ from datetime import timedelta
import pytest
from freezegun import freeze_time
from posthog.test.base import BaseTest
-from unittest.mock import AsyncMock, patch
+from unittest.mock import AsyncMock, call, patch
from django.utils import timezone
@@ -14,7 +14,10 @@ from temporalio.testing import WorkflowEnvironment
from temporalio.worker import UnsandboxedWorkflowRunner, Worker
from products.error_tracking.backend.models import ErrorTrackingStackFrame, ErrorTrackingSymbolSet
-from products.error_tracking.backend.temporal.symbol_set_cleanup.activities import cleanup_symbol_sets_activity
+from products.error_tracking.backend.temporal.symbol_set_cleanup.activities import (
+ _delete_symbol_set_contents_with_pacing,
+ cleanup_symbol_sets_activity,
+)
from products.error_tracking.backend.temporal.symbol_set_cleanup.types import (
SymbolSetCleanupInputs,
SymbolSetCleanupResult,
@@ -22,6 +25,19 @@ from products.error_tracking.backend.temporal.symbol_set_cleanup.types import (
from products.error_tracking.backend.temporal.symbol_set_cleanup.workflow import ErrorTrackingSymbolSetCleanupWorkflow
+class TestDeleteSymbolSetContentsWithPacing:
+ @patch("products.error_tracking.backend.temporal.symbol_set_cleanup.activities.time.sleep")
+ @patch("products.error_tracking.backend.temporal.symbol_set_cleanup.activities.delete_symbol_set_contents_many")
+ def test_paces_storage_delete_requests(self, delete_contents, sleep) -> None:
+ storage_ptrs = [f"symbols/{index}" for index in range(1001)]
+ delete_contents.return_value = []
+
+ assert _delete_symbol_set_contents_with_pacing(storage_ptrs) == []
+
+ assert delete_contents.call_args_list == [call(storage_ptrs[:1000]), call(storage_ptrs[1000:])]
+ sleep.assert_called_once_with(0.1)
+
+
class TestSymbolSetCleanupActivity(BaseTest):
def _create_symbol_set(
self,