: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(hogql): run logs and spans queries on their cluster in any lane (#120338)
Vasco de Krijger1e19a241fa08
diff --git a/posthog/hogql/query.py b/posthog/hogql/query.pyindex 569cfa1babba..7f23aaf1fdd8 100644--- a/posthog/hogql/query.py+++ b/posthog/hogql/query.py@@ -89,6 +89,7 @@ if TYPE_CHECKING:tracer = trace.get_tracer(__name__)TRANSIENT_S3_ERROR_RETRY_DELAY_SECONDS = 1.0+MAIN_CLUSTER_WORKLOADS = (Workload.DEFAULT, Workload.ONLINE, Workload.OFFLINE)@frozen@@ -964,8 +965,9 @@ class HogQLQueryExecutor:)workload = self.workload- if workload == Workload.DEFAULT and clickhouse_context.workload is not None:- workload = clickhouse_context.workload+ table_workload = clickhouse_context.workload+ if table_workload is not None and table_workload != Workload.DEFAULT and workload in MAIN_CLUSTER_WORKLOADS:+ workload = table_workloadif use_new_events_cluster(self.team.pk, self.query_modifiers):if get_query_tags().product == Product.ENDPOINTS or workload not in (Workload.DEFAULT,diff --git a/posthog/hogql/test/test_workload.py b/posthog/hogql/test/test_workload.pyindex b17c5ffb37ee..15b4dbca6614 100644--- a/posthog/hogql/test/test_workload.py+++ b/posthog/hogql/test/test_workload.py@@ -1,9 +1,15 @@import pytest+from posthog.test.base import BaseTest+from unittest.mock import patch++from parameterized import parameterizedfrom posthog.hogql import astfrom posthog.hogql.database.schema.events import EventsTablefrom posthog.hogql.database.schema.logs import LogAttributesTable, LogsKafkaMetricsTable, LogsTablefrom posthog.hogql.errors import QueryError+from posthog.hogql.parser import parse_select+from posthog.hogql.query import execute_hogql_queryfrom posthog.hogql.workload import WorkloadCollectorfrom posthog.clickhouse.workload import Workload@@ -96,3 +102,21 @@ class TestWorkloadCollector:assert Workload.LOGS in collector.workloadsassert collector.get_workload() == Workload.LOGS+++class TestExecuteHogQLQueryWorkload(BaseTest):+ @parameterized.expand(+ [+ ("spans_offline", "SELECT 1 FROM posthog.trace_spans", Workload.OFFLINE, Workload.LOGS),+ ("spans_online", "SELECT 1 FROM posthog.trace_spans", Workload.ONLINE, Workload.LOGS),+ ("logs_offline", "SELECT 1 FROM logs", Workload.OFFLINE, Workload.LOGS),+ ("events_offline", "SELECT 1 FROM events", Workload.OFFLINE, Workload.OFFLINE),+ ]+ )+ def test_table_cluster_wins_over_priority_workload(+ self, _name: str, query: str, requested: Workload, expected: Workload+ ) -> None:+ with patch("posthog.hogql.query.sync_execute", return_value=([], [])) as sync_execute:+ execute_hogql_query(query=parse_select(query), team=self.team, workload=requested)++ assert sync_execute.call_args.kwargs["workload"] == expected