: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
feat(billing): route billing queries to dedicated ClickHouse user (#59620)
Paweł Szczur7548f698136f
diff --git a/.env.services b/.env.servicesindex 480432a92f08..ef7a83703ac5 100644--- a/.env.services+++ b/.env.services@@ -21,6 +21,8 @@ CLICKHOUSE_API_USER=apiCLICKHOUSE_API_PASSWORD=apipassCLICKHOUSE_APP_USER=appCLICKHOUSE_APP_PASSWORD=apppass+CLICKHOUSE_BILLING_USER=billing+CLICKHOUSE_BILLING_PASSWORD=billingpass# RedisREDIS_URL=redis://redis7:6379/diff --git a/bin/start-worker b/bin/start-workerindex 369179ddc2a8..a560a6407596 100755--- a/bin/start-worker+++ b/bin/start-worker@@ -8,6 +8,8 @@ export CLICKHOUSE_API_USER="api"export CLICKHOUSE_API_PASSWORD="apipass"export CLICKHOUSE_APP_USER="app"export CLICKHOUSE_APP_PASSWORD="apppass"+export CLICKHOUSE_BILLING_USER="billing"+export CLICKHOUSE_BILLING_PASSWORD="billingpass"source ./bin/celery-queues.envdiff --git a/docker/clickhouse/users-dev.xml b/docker/clickhouse/users-dev.xmlindex 33f108c19d46..dc24e9f422f9 100644--- a/docker/clickhouse/users-dev.xml+++ b/docker/clickhouse/users-dev.xml@@ -54,6 +54,10 @@<profile>default</profile></app>+ <billing>+ <profile>default</profile>+ </billing>+<!-- Of course this is only for local dev, but mirrors prod to make tests useful.readonly=2 pinned via <constraints> is the load-bearing safety (no writes, no client-side settings changes).No resource constraints necessary, as autoresearch gets a dedicated cluster.@@ -179,6 +183,18 @@<quota>default</quota></app>+ <billing>+ <password>billingpass</password>++ <networks>+ <ip>::/0</ip>+ </networks>++ <profile>billing</profile>++ <quota>default</quota>+ </billing>+<!-- Of course this is local dev, but mirrors prod to make tests useful.- no table-function grants (url / s3 / file / executable / jdbc / ...)- no DDLdiff --git a/posthog/clickhouse/client/connection.py b/posthog/clickhouse/client/connection.pyindex 02c05105a35c..5933b7273e0a 100644--- a/posthog/clickhouse/client/connection.py+++ b/posthog/clickhouse/client/connection.py@@ -71,6 +71,7 @@ class ClickHouseUser(StrEnum):MESSAGING = "messaging" # a.k.a. behavioral cohortsMAX_AI = "max_ai" # llm/aENDPOINTS = "endpoints"+ BILLING = "billing"# Backups - used by Dagster backup jobsBACKUPS = "backups"diff --git a/posthog/clickhouse/client/execute.py b/posthog/clickhouse/client/execute.pyindex 1564a6867bcd..541ab6015b43 100644--- a/posthog/clickhouse/client/execute.py+++ b/posthog/clickhouse/client/execute.py@@ -94,6 +94,7 @@ _KILL_SWITCH_EXEMPT_USERS = frozenset(ClickHouseUser.BATCH_EXPORT,ClickHouseUser.MIGRATIONS,ClickHouseUser.OPS,+ ClickHouseUser.BILLING,})@@ -367,6 +368,8 @@ def sync_execute(ch_user = ClickHouseUser.MAX_AIelif tags.product == Product.ENDPOINTS:ch_user = ClickHouseUser.ENDPOINTS+ elif tags.product == Product.BILLING:+ ch_user = ClickHouseUser.BILLING# To humans and bots reading this, you might be tempted to add a catch-all tag to avoid# hitting this error. Please don't do this. This error is to let us know about queries