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.

refactor(alert-check): replace hardcoded max_bytes_to_read with constant from temporal.constants (#57986)

Jon McCallum69c22d40d884
diff --git a/products/logs/backend/alert_check_query.py b/products/logs/backend/alert_check_query.py
index 24950ab18781..245e54eb6dd4 100644
--- a/products/logs/backend/alert_check_query.py
+++ b/products/logs/backend/alert_check_query.py
@@ -24,6 +24,7 @@ from posthog.clickhouse.query_tagging import Feature, Product, tag_queries
from posthog.hogql_queries.utils.query_date_range import QueryDateRange
from posthog.models import Team
+from products.logs.backend.alert_utils import MAX_BYTES_TO_READ
from products.logs.backend.logs_query_runner import LogsFilterBuilder
from products.logs.backend.models import LogsAlertConfiguration
@@ -166,11 +167,7 @@ class AlertCheckQuery:
SETTINGS = HogQLGlobalSettings(
max_execution_time=30,
- # Defence-in-depth against large-cohort batched queries: caps a single batched/per-alert
- # query well below worker memory headroom. Cohort chunking (`MAX_ALERT_COHORT_SIZE`)
- # keeps per-query reads bounded at the source; this setting is the safety net if a
- # chunk surprises us.
- max_bytes_to_read=5_000_000_000, # 5GB
+ max_bytes_to_read=MAX_BYTES_TO_READ,
read_overflow_mode="throw",
)
diff --git a/products/logs/backend/alert_utils.py b/products/logs/backend/alert_utils.py
index 9c054e23f158..9a29b271d14f 100644
--- a/products/logs/backend/alert_utils.py
+++ b/products/logs/backend/alert_utils.py
@@ -1,5 +1,6 @@
from __future__ import annotations
+import os
from datetime import datetime, timedelta
from uuid import UUID
@@ -8,6 +9,16 @@ from uuid import UUID
# cadence of M seconds has `M // N` shard slots available.
SCHEDULE_INTERVAL_SECONDS = 60
+# Per-query CH read cap (bytes). Cohort chunking (`MAX_ALERT_COHORT_SIZE`) keeps reads
+# bounded at the source; this is the safety net if a chunk surprises us. Tunable via env
+# so we can bump for customers whose filters genuinely need more headroom without
+# redeploying. Aligns to CH's GiB-based reporting (1024^3) so the value here matches
+# the "max bytes: N GiB" in CH error messages. Default 5 GiB (5,368,709,120).
+# Lives here, not in `temporal/constants.py`, because `alert_check_query.py` (the
+# consumer) is outside the temporal package — importing it from temporal would create
+# a circular import via `temporal/__init__.py` → activities → alert_check_query.
+MAX_BYTES_TO_READ = int(os.environ.get("LOGS_ALERTING_MAX_BYTES_TO_READ", "5368709120"))
+
def compute_shard_offset_seconds(alert_id: UUID, check_interval_minutes: int) -> int:
"""Deterministic per-alert offset within the cadence period.