: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(replay-vision): unshadow the read-meter sum alias so metering runs again (#86160)
Tue Haulunddb3df8d9a210
diff --git a/products/replay_vision/backend/temporal/activities/meter_scanner_reads.py b/products/replay_vision/backend/temporal/activities/meter_scanner_reads.pyindex d04846d86328..d132ed62d9ad 100644--- a/products/replay_vision/backend/temporal/activities/meter_scanner_reads.py+++ b/products/replay_vision/backend/temporal/activities/meter_scanner_reads.py@@ -29,7 +29,7 @@ _READ_BYTES_BY_SCANNER_HOUR_SQL = """SELECTJSONExtractString(log_comment, 'scanner_id') AS scanner_id,toStartOfHour(toTimeZone(event_time, 'UTC')) AS hour,- sum(read_bytes) AS read_bytes,+ sum(read_bytes) AS total_read_bytes,sumIf(read_bytes, JSONExtractString(log_comment, 'query_type') = %(deep_query_type)s) AS deep_read_bytes,sumIf(read_bytes, JSONExtractString(log_comment, 'query_type') IN %(fast_query_types)s) AS fast_read_bytesFROM clusterAllReplicas(%(cluster)s, system.query_log)@@ -68,12 +68,16 @@ def meter_scanner_read_bytes_activity() -> MeterScannerReadsResult:)by_scanner: dict[str, dict[str, tuple[int, int, int]]] = {}- for scanner_id, hour, read_bytes, deep_read_bytes, fast_read_bytes in rows:+ for scanner_id, hour, total_read_bytes, deep_read_bytes, fast_read_bytes in rows:# The tag is a free-form string in the query log, so a junk value must not take the run down.if not _is_uuid(scanner_id):continuehour_iso = hour.replace(tzinfo=dt.UTC).isoformat()- by_scanner.setdefault(scanner_id, {})[hour_iso] = (int(read_bytes), int(deep_read_bytes), int(fast_read_bytes))+ by_scanner.setdefault(scanner_id, {})[hour_iso] = (+ int(total_read_bytes),+ int(deep_read_bytes),+ int(fast_read_bytes),+ )prune_cutoff = now - dt.timedelta(hours=25)# Wider than the sweep's: the deep pass is priced on its average over this window, so a bucketdiff --git a/products/replay_vision/backend/tests/test_read_meter.py b/products/replay_vision/backend/tests/test_read_meter.pyindex 96bbc607b0d0..b1ff8bbd7d2f 100644--- a/products/replay_vision/backend/tests/test_read_meter.py+++ b/products/replay_vision/backend/tests/test_read_meter.py@@ -105,6 +105,13 @@ class TestThrottleMath:@pytest.mark.django_db(transaction=True)class TestMeterScannerReadsActivity:+ def test_the_metering_sql_executes_against_clickhouse(self) -> None:+ # Every other test here mocks sync_execute, which is how an alias-shadowing SQL error once+ # shipped and failed every production metering run; this executes the real query.+ result = meter_scanner_read_bytes_activity()++ assert result.scanners_updated == 0+def test_junk_scanner_tag_does_not_take_down_the_run(self) -> None:# scanner_id is a free-form string in the query log, so a non-UUID must be skipped rather# than blowing up the pk__in lookup for every other scanner in the batch.