: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(data-warehouse): stop reporting redis blips from row tracking to error tracking (#96393)
Tom Owers5d1154d4f2d9
diff --git a/products/warehouse_sources/backend/temporal/data_imports/row_tracking.py b/products/warehouse_sources/backend/temporal/data_imports/row_tracking.pyindex 9bab76b58c7e..758e0f92b1cd 100644--- a/products/warehouse_sources/backend/temporal/data_imports/row_tracking.py+++ b/products/warehouse_sources/backend/temporal/data_imports/row_tracking.py@@ -77,10 +77,11 @@ async def setup_row_tracking(team_id: int, schema_id: uuid.UUID | str) -> None:await redis.hset(_get_hash_key(team_id), str(schema_id), 0)await redis.expire(_get_hash_key(team_id), 60 * 60 * 24 * 7) # 7 day expireexcept redis_exceptions.RedisError as e:- # A successful ping doesn't guarantee later commands succeed (e.g. Redis- # refusing writes because it can't persist an RDB snapshot). Row tracking is- # best-effort, so a command failing here shouldn't fail the whole import.- capture_exception(e)+ # Same rationale as _get_redis above: a successful ping doesn't guarantee a+ # later command succeeds (e.g. Redis refusing writes because it can't persist+ # an RDB snapshot, or a replica failover). That's a transient infra blip, not+ # a bug, so it fails open without being reported to error tracking.+ await logger.awarning("Redis error while setting up row tracking, failing open", error=str(e))async def increment_rows(team_id: int, schema_id: uuid.UUID | str, rows: int) -> None:@@ -91,7 +92,7 @@ async def increment_rows(team_id: int, schema_id: uuid.UUID | str, rows: int) ->try:await redis.hincrby(_get_hash_key(team_id), str(schema_id), rows)except redis_exceptions.RedisError as e:- capture_exception(e)+ await logger.awarning("Redis error while incrementing row tracking, failing open", error=str(e))async def decrement_rows(team_id: int, schema_id: uuid.UUID | str, rows: int) -> None:@@ -113,7 +114,7 @@ async def decrement_rows(team_id: int, schema_id: uuid.UUID | str, rows: int) ->else:await redis.hincrby(_get_hash_key(team_id), str(schema_id), -rows)except redis_exceptions.RedisError as e:- capture_exception(e)+ await logger.awarning("Redis error while decrementing row tracking, failing open", error=str(e))async def finish_row_tracking(team_id: int, schema_id: uuid.UUID | str) -> None:@@ -124,7 +125,7 @@ async def finish_row_tracking(team_id: int, schema_id: uuid.UUID | str) -> None:try:await redis.hdel(_get_hash_key(team_id), str(schema_id))except redis_exceptions.RedisError as e:- capture_exception(e)+ await logger.awarning("Redis error while finishing row tracking, failing open", error=str(e))async def get_rows(team_id: int, schema_id: uuid.UUID | str) -> int:@@ -138,7 +139,7 @@ async def get_rows(team_id: int, schema_id: uuid.UUID | str) -> int:if value:return int(value)except redis_exceptions.RedisError as e:- capture_exception(e)+ await logger.awarning("Redis error while reading row tracking, failing open", error=str(e))return 0@@ -152,7 +153,7 @@ async def get_all_rows_for_team(team_id: int) -> int:pairs = await redis.hgetall(_get_hash_key(team_id))return sum(int(v) for v in pairs.values())except redis_exceptions.RedisError as e:- capture_exception(e)+ await logger.awarning("Redis error while reading team row tracking, failing open", error=str(e))return 0diff --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.pyindex bc93bb347822..2e8cb60c7507 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,6 +32,8 @@ from products.warehouse_sources.backend.temporal.data_imports.row_tracking imporwill_hit_billing_limit,)+_READ_ONLY_REPLICA_ERROR = redis_exceptions.ReadOnlyError("You can't write against a read only replica.")+class _CacheReadFailsClient:def __init__(self, inner):@@ -90,31 +92,68 @@ class TestRowTrackingRedisUnavailable(BaseTest):unreachable_client.hset.assert_not_called()mock_capture_exception.assert_not_called()+ @parameterized.expand(+ [+ (+ "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."+ ),+ ),+ ("read_only_replica_error", _READ_ONLY_REPLICA_ERROR),+ ]+ )@pytest.mark.asyncio- async def test_setup_row_tracking_does_not_raise_when_redis_rejects_writes(self):+ async def test_setup_row_tracking_does_not_raise_or_capture_when_redis_rejects_writes(self, _name, exception):# A successful ping doesn't guarantee the following command succeeds - e.g. Redis- # can refuse writes (MISCONF) if it can't persist an RDB snapshot to disk. That- # must fail open like the unreachable-at-ping case above, not crash the sync.+ # can refuse writes (MISCONF, or a replica redirect during failover). That must+ # fail open like the unreachable-at-ping case above: no crash, and (since it's a+ # transient infra blip the caller already tolerates) no error-tracking report.read_only_client = mock.AsyncMock()read_only_client.ping.return_value = True- read_only_client.hset.side_effect = 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."- )+ read_only_client.hset.side_effect = exceptionwith (mock.patch("products.warehouse_sources.backend.temporal.data_imports.row_tracking.get_async_client",return_value=read_only_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()))read_only_client.expire.assert_not_called()+ mock_capture_exception.assert_not_called()++ @pytest.mark.asyncio+ async def test_finish_row_tracking_does_not_raise_or_capture_when_redis_rejects_writes(self):+ # Regression test: finish_row_tracking's hdel used to report a read-only-replica+ # error (e.g. during a Redis failover) to error tracking instead of failing open+ # like the rest of row tracking already does.+ read_only_client = mock.AsyncMock()+ read_only_client.ping.return_value = True+ read_only_client.hdel.side_effect = _READ_ONLY_REPLICA_ERROR++ with (+ mock.patch(+ "products.warehouse_sources.backend.temporal.data_imports.row_tracking.get_async_client",+ return_value=read_only_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 finish_row_tracking(self.team.pk, str(uuid.uuid4()))++ mock_capture_exception.assert_not_called()@pytest.mark.timeout(600)