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(data-imports): stop reporting redis blips in row tracking (#88645)

Tom Owers0c5163d73814
diff --git a/products/warehouse_sources/backend/temporal/data_imports/row_tracking.py b/products/warehouse_sources/backend/temporal/data_imports/row_tracking.py
index 5b8d80576e8a..75323c6a9c70 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/row_tracking.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/row_tracking.py
@@ -9,6 +9,7 @@ from django.db.models import F, Q, Sum
from django.db.utils import InternalError, OperationalError
import requests
+import structlog
from dateutil import parser
from redis import exceptions as redis_exceptions
from structlog.types import FilteringBoundLogger
@@ -27,6 +28,9 @@ if TYPE_CHECKING:
from products.warehouse_sources.backend.models.external_data_source import ExternalDataSource
+logger = structlog.get_logger(__name__)
+
+
def _get_hash_key(team_id: int) -> str:
return f"posthog:data_warehouse_row_tracking:{team_id}"
@@ -43,6 +47,14 @@ async def _get_redis():
redis = get_async_client(f"redis://{settings.DATA_WAREHOUSE_REDIS_HOST}:{settings.DATA_WAREHOUSE_REDIS_PORT}/")
await redis.ping()
+ except redis_exceptions.RedisError as e:
+ # Row tracking already fails open when redis is unavailable (every caller
+ # checks `if not redis: return`), so a Redis-side blip - unreachable, refusing
+ # writes because RDB snapshotting failed, loading, etc. - isn't a bug, and
+ # shouldn't be reported to error tracking. Same rationale as the RedisError
+ # handling in will_hit_billing_limit below.
+ await logger.awarning("Redis error while getting row tracking client, failing open", error=str(e))
+ redis = None
except Exception as e:
capture_exception(e)
# get_async_client only builds a lazy client, so a failed ping means redis is
diff --git a/products/warehouse_sources/backend/temporal/data_imports/tests/test_row_tracking.py b/products/warehouse_sources/backend/temporal/data_imports/tests/test_row_tracking.py
index a68beac75b98..9253ead26a7d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/tests/test_row_tracking.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/tests/test_row_tracking.py
@@ -32,26 +32,50 @@ from products.warehouse_sources.backend.temporal.data_imports.row_tracking impor
class TestRowTrackingRedisUnavailable(BaseTest):
+ @parameterized.expand(
+ [
+ (
+ "connection_error",
+ redis_exceptions.ConnectionError(
+ "Error connecting to redis:6379. Temporary failure in name resolution."
+ ),
+ ),
+ (
+ "misconf_error",
+ redis_exceptions.ResponseError(
+ "MISCONF Redis is configured to save RDB snapshots, but it's currently unable to persist to "
+ "disk. Commands that may modify the data set are disabled, because this instance is configured "
+ "to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). "
+ "Please check the Redis logs for details about the RDB error."
+ ),
+ ),
+ ]
+ )
@pytest.mark.asyncio
- async def test_setup_row_tracking_does_not_raise_when_redis_is_unreachable(self):
+ async def test_setup_row_tracking_does_not_raise_when_redis_is_unreachable(self, _name, exception):
# get_async_client only builds a lazy client - the ping is the first real
# connection attempt. If it fails, the client must not be used again, or the
# next command (hset) raises the same connection error, this time uncaught.
+ # Row tracking already fails open when redis is unavailable, so a Redis-side
+ # error (unreachable, or refusing writes because RDB snapshotting failed) is a
+ # transient infra blip, not a bug, and must not be reported to error tracking.
unreachable_client = mock.AsyncMock()
- unreachable_client.ping.side_effect = redis_exceptions.ConnectionError(
- "Error connecting to redis:6379. Temporary failure in name resolution."
- )
+ unreachable_client.ping.side_effect = exception
with (
mock.patch(
"products.warehouse_sources.backend.temporal.data_imports.row_tracking.get_async_client",
return_value=unreachable_client,
),
+ mock.patch(
+ "products.warehouse_sources.backend.temporal.data_imports.row_tracking.capture_exception"
+ ) as mock_capture_exception,
override_settings(DATA_WAREHOUSE_REDIS_HOST="localhost", DATA_WAREHOUSE_REDIS_PORT="6379"),
):
await setup_row_tracking(self.team.pk, str(uuid.uuid4()))
unreachable_client.hset.assert_not_called()
+ mock_capture_exception.assert_not_called()
@pytest.mark.timeout(600)