: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(logs): point log_attributes_distributed at log_attributes3 (#70496)
Frank Hamande64efc31d3d9
diff --git a/posthog/clickhouse/hcl/golden/dev-logs.hcl b/posthog/clickhouse/hcl/golden/dev-logs.hclindex 13b84c0a79e0..8b7940b7a25d 100644--- a/posthog/clickhouse/hcl/golden/dev-logs.hcl+++ b/posthog/clickhouse/hcl/golden/dev-logs.hcl@@ -294,10 +294,13 @@ database "posthog" {type = "DateTime"default = "now()"}+ column "severity_text" {+ type = "LowCardinality(String)"+ }engine "distributed" {cluster_name = "logs"remote_database = "posthog"- remote_table = "log_attributes2"+ remote_table = "log_attributes3"}}diff --git a/posthog/clickhouse/hcl/golden/local-logs.hcl b/posthog/clickhouse/hcl/golden/local-logs.hclindex 5411edbb93b1..e29b47c89d11 100644--- a/posthog/clickhouse/hcl/golden/local-logs.hcl+++ b/posthog/clickhouse/hcl/golden/local-logs.hcl@@ -289,10 +289,13 @@ database "posthog" {type = "DateTime"default = "now()"}+ column "severity_text" {+ type = "LowCardinality(String)"+ }engine "distributed" {cluster_name = "posthog_single_shard"remote_database = "posthog"- remote_table = "log_attributes2"+ remote_table = "log_attributes3"}}diff --git a/posthog/clickhouse/hcl/golden/prod-eu-logs.hcl b/posthog/clickhouse/hcl/golden/prod-eu-logs.hclindex a5abc59e3773..59858a22d12d 100644--- a/posthog/clickhouse/hcl/golden/prod-eu-logs.hcl+++ b/posthog/clickhouse/hcl/golden/prod-eu-logs.hcl@@ -374,10 +374,13 @@ database "posthog" {type = "DateTime"default = "now()"}+ column "severity_text" {+ type = "LowCardinality(String)"+ }engine "distributed" {cluster_name = "logs"remote_database = "posthog"- remote_table = "log_attributes2"+ remote_table = "log_attributes3"}}diff --git a/posthog/clickhouse/hcl/golden/prod-us-logs.hcl b/posthog/clickhouse/hcl/golden/prod-us-logs.hclindex eb7d229f3d72..f74cee513ada 100644--- a/posthog/clickhouse/hcl/golden/prod-us-logs.hcl+++ b/posthog/clickhouse/hcl/golden/prod-us-logs.hcl@@ -371,10 +371,13 @@ database "posthog" {type = "DateTime"default = "now()"}+ column "severity_text" {+ type = "LowCardinality(String)"+ }engine "distributed" {cluster_name = "logs"remote_database = "posthog"- remote_table = "log_attributes2"+ remote_table = "log_attributes3"}}diff --git a/posthog/clickhouse/hcl/roles/logs/local/tables.hcl b/posthog/clickhouse/hcl/roles/logs/local/tables.hclindex 2ad7a23c40b9..ba409c00a93d 100644--- a/posthog/clickhouse/hcl/roles/logs/local/tables.hcl+++ b/posthog/clickhouse/hcl/roles/logs/local/tables.hcl@@ -285,10 +285,13 @@ database "posthog" {type = "DateTime"default = "now()"}+ column "severity_text" {+ type = "LowCardinality(String)"+ }engine "distributed" {cluster_name = "posthog_single_shard"remote_database = "posthog"- remote_table = "log_attributes2"+ remote_table = "log_attributes3"}}table "logs" {diff --git a/posthog/clickhouse/hcl/roles/logs/shared/tables.hcl b/posthog/clickhouse/hcl/roles/logs/shared/tables.hclindex db244351f7de..226e25cde000 100644--- a/posthog/clickhouse/hcl/roles/logs/shared/tables.hcl+++ b/posthog/clickhouse/hcl/roles/logs/shared/tables.hcl@@ -952,10 +952,13 @@ database "posthog" {type = "DateTime"default = "now()"}+ column "severity_text" {+ type = "LowCardinality(String)"+ }engine "distributed" {cluster_name = "logs"remote_database = "posthog"- remote_table = "log_attributes2"+ remote_table = "log_attributes3"}}table "logs_distributed" {diff --git a/posthog/clickhouse/hcl/sql/dev-logs.sql b/posthog/clickhouse/hcl/sql/dev-logs.sqlindex dac19cb54307..9dd4a9a7be85 100644--- a/posthog/clickhouse/hcl/sql/dev-logs.sql+++ b/posthog/clickhouse/hcl/sql/dev-logs.sql@@ -79,8 +79,9 @@ CREATE TABLE posthog.log_attributes_distributed (attribute_value String CODEC(ZSTD(5)),attribute_count SimpleAggregateFunction(sum, UInt64),attribute_type LowCardinality(String) DEFAULT 'log',- original_expiry_time_bucket DateTime DEFAULT now()-) ENGINE = Distributed('logs', 'posthog', 'log_attributes2');+ original_expiry_time_bucket DateTime DEFAULT now(),+ severity_text LowCardinality(String)+) ENGINE = Distributed('logs', 'posthog', 'log_attributes3');CREATE TABLE posthog.logs34 (time_bucket DateTime MATERIALIZED toStartOfDay(timestamp),original_expiry_timestamp DateTime64(6),diff --git a/posthog/clickhouse/hcl/sql/local-logs.sql b/posthog/clickhouse/hcl/sql/local-logs.sqlindex 99381dceed13..692282f7c9f9 100644--- a/posthog/clickhouse/hcl/sql/local-logs.sql+++ b/posthog/clickhouse/hcl/sql/local-logs.sql@@ -72,8 +72,9 @@ CREATE TABLE posthog.log_attributes_distributed (attribute_value String CODEC(ZSTD(5)),attribute_count SimpleAggregateFunction(sum, UInt64),attribute_type LowCardinality(String) DEFAULT 'log',- original_expiry_time_bucket DateTime DEFAULT now()-) ENGINE = Distributed('posthog_single_shard', 'posthog', 'log_attributes2');+ original_expiry_time_bucket DateTime DEFAULT now(),+ severity_text LowCardinality(String)+) ENGINE = Distributed('posthog_single_shard', 'posthog', 'log_attributes3');CREATE TABLE posthog.logs32 (time_bucket DateTime MATERIALIZED toStartOfDay(timestamp) CODEC(DoubleDelta, ZSTD(1)),original_expiry_timestamp DateTime64(6) CODEC(DoubleDelta, ZSTD(1)),diff --git a/posthog/clickhouse/hcl/sql/prod-eu-logs.sql b/posthog/clickhouse/hcl/sql/prod-eu-logs.sqlindex 1e5e7b293f13..eb49a46b55b0 100644--- a/posthog/clickhouse/hcl/sql/prod-eu-logs.sql+++ b/posthog/clickhouse/hcl/sql/prod-eu-logs.sql@@ -103,8 +103,9 @@ CREATE TABLE posthog.log_attributes_distributed (attribute_value String CODEC(ZSTD(5)),attribute_count SimpleAggregateFunction(sum, UInt64),attribute_type LowCardinality(String) DEFAULT 'log',- original_expiry_time_bucket DateTime DEFAULT now()-) ENGINE = Distributed('logs', 'posthog', 'log_attributes2');+ original_expiry_time_bucket DateTime DEFAULT now(),+ severity_text LowCardinality(String)+) ENGINE = Distributed('logs', 'posthog', 'log_attributes3');CREATE TABLE posthog.logs34 (time_bucket DateTime MATERIALIZED toStartOfDay(timestamp),original_expiry_timestamp DateTime64(6),diff --git a/posthog/clickhouse/hcl/sql/prod-us-logs.sql b/posthog/clickhouse/hcl/sql/prod-us-logs.sqlindex 789c3fee7d32..118717db2189 100644--- a/posthog/clickhouse/hcl/sql/prod-us-logs.sql+++ b/posthog/clickhouse/hcl/sql/prod-us-logs.sql@@ -102,8 +102,9 @@ CREATE TABLE posthog.log_attributes_distributed (attribute_value String CODEC(ZSTD(5)),attribute_count SimpleAggregateFunction(sum, UInt64),attribute_type LowCardinality(String) DEFAULT 'log',- original_expiry_time_bucket DateTime DEFAULT now()-) ENGINE = Distributed('logs', 'posthog', 'log_attributes2');+ original_expiry_time_bucket DateTime DEFAULT now(),+ severity_text LowCardinality(String)+) ENGINE = Distributed('logs', 'posthog', 'log_attributes3');CREATE TABLE posthog.logs34 (time_bucket DateTime MATERIALIZED toStartOfDay(timestamp),original_expiry_timestamp DateTime64(6),diff --git a/posthog/clickhouse/logs/__init__.py b/posthog/clickhouse/logs/__init__.pyindex 4a333899a829..84f9890d90fc 100644--- a/posthog/clickhouse/logs/__init__.py+++ b/posthog/clickhouse/logs/__init__.py@@ -1,6 +1,6 @@from .log_attributes import LOG_ATTRIBUTES_DISTRIBUTED_TABLE_SQL, LOG_ATTRIBUTES_TABLE_SQLfrom .log_attributes2 import LOG_ATTRIBUTES2_DISTRIBUTED_TABLE_SQL, LOG_ATTRIBUTES2_TABLE_SQL-from .log_attributes3 import LOG_ATTRIBUTES3_TABLE_SQL+from .log_attributes3 import LOG_ATTRIBUTES3_DISTRIBUTED_TABLE_SQL, LOG_ATTRIBUTES3_TABLE_SQLfrom .logs32 import (LOG_ATTRIBUTES_MV,LOG_RESOURCE_ATTRIBUTES_MV,@@ -46,6 +46,7 @@ __all__ = ["LOG_ATTRIBUTES2_TABLE_SQL","LOG_ATTRIBUTES2_DISTRIBUTED_TABLE_SQL","LOG_ATTRIBUTES3_TABLE_SQL",+ "LOG_ATTRIBUTES3_DISTRIBUTED_TABLE_SQL","LOGS_BILLING_METRICS_TABLE_SQL","LOGS_BILLING_METRICS_DISTRIBUTED_TABLE_SQL",]diff --git a/posthog/clickhouse/logs/log_attributes3.py b/posthog/clickhouse/logs/log_attributes3.pyindex 747a45f53160..9a259752a8a6 100644--- a/posthog/clickhouse/logs/log_attributes3.py+++ b/posthog/clickhouse/logs/log_attributes3.py@@ -1,6 +1,6 @@from django.conf import settings-from posthog.clickhouse.table_engines import AggregatingMergeTree, ReplicationScheme+from posthog.clickhouse.table_engines import AggregatingMergeTree, Distributed, ReplicationSchemeTABLE_NAME = "log_attributes3"@@ -32,3 +32,16 @@ SETTINGSdeduplicate_merge_projection_mode = 'drop',index_granularity = 8192"""+++def LOG_ATTRIBUTES3_DISTRIBUTED_TABLE_SQL():+ return """+CREATE OR REPLACE TABLE {database}.log_attributes_distributed AS {database}.{table_name} ENGINE = {engine}+""".format(+ engine=Distributed(+ data_table=TABLE_NAME,+ cluster=settings.CLICKHOUSE_LOGS_CLUSTER,+ ),+ database=settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE,+ table_name=TABLE_NAME,+ )diff --git a/posthog/clickhouse/migrations/0288_log_attributes3_distributed.py b/posthog/clickhouse/migrations/0288_log_attributes3_distributed.pynew file mode 100644index 000000000000..f20ddc0c321b--- /dev/null+++ b/posthog/clickhouse/migrations/0288_log_attributes3_distributed.py@@ -0,0 +1,10 @@+from posthog.clickhouse.client.connection import NodeRole+from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions+from posthog.clickhouse.logs import LOG_ATTRIBUTES3_DISTRIBUTED_TABLE_SQL++# Cut the shared log_attributes_distributed read path over to log_attributes3, which carries+# severity_text in its ORDER BY. log_attributes3 and its MVs are created and backfilled by migration+# 0282; this CREATE OR REPLACE repoints the distributed table once that data is in place.+operations = [+ run_sql_with_exceptions(LOG_ATTRIBUTES3_DISTRIBUTED_TABLE_SQL(), node_roles=[NodeRole.LOGS]),+]diff --git a/posthog/clickhouse/migrations/max_migration.txt b/posthog/clickhouse/migrations/max_migration.txtindex 48535372c34c..4f1f82a6ddee 100644--- a/posthog/clickhouse/migrations/max_migration.txt+++ b/posthog/clickhouse/migrations/max_migration.txt@@ -1 +1 @@-0287_events_recent_inserted_at_not_nullable+0288_log_attributes3_distributed