: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): drop the empty logs_volume_buckets table (#84184)
Jon McCallum58a04111103d
diff --git a/posthog/clickhouse/hcl/golden/dev/logs.hcl b/posthog/clickhouse/hcl/golden/dev/logs.hclindex 0cca7c884715..fd6ee7d2e0b1 100644--- a/posthog/clickhouse/hcl/golden/dev/logs.hcl+++ b/posthog/clickhouse/hcl/golden/dev/logs.hcl@@ -695,78 +695,6 @@ database "posthog" {}}- table "logs_volume_buckets" {- order_by = ["team_id", "time_bucket", "generation", "service_name", "namespace", "environment", "severity_text"]- partition_by = "toDate(time_bucket)"- ttl = "time_bucket + toIntervalDay(42)"- settings = {- index_granularity = "8192"- ttl_only_drop_parts = "1"- }- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime('UTC')"- codec = "DoubleDelta, ZSTD(1)"- }- column "generation" {- type = "UInt64"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "namespace" {- type = "LowCardinality(String)"- }- column "environment" {- type = "LowCardinality(String)"- }- column "severity_text" {- type = "LowCardinality(String)"- }- column "log_count" {- type = "UInt64"- }- engine "replicated_merge_tree" {- zoo_path = "/clickhouse/tables/noshard/posthog.logs_volume_buckets"- replica_name = "{replica}-{shard}"- }- }-- table "logs_volume_buckets_distributed" {- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime('UTC')"- codec = "DoubleDelta, ZSTD(1)"- }- column "generation" {- type = "UInt64"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "namespace" {- type = "LowCardinality(String)"- }- column "environment" {- type = "LowCardinality(String)"- }- column "severity_text" {- type = "LowCardinality(String)"- }- column "log_count" {- type = "UInt64"- }- engine "distributed" {- cluster_name = "posthog_single_shard"- remote_database = "posthog"- remote_table = "logs_volume_buckets"- }- }-table "metric_attributes" {order_by = ["team_id", "attribute_type", "time_bucket", "resource_fingerprint", "attribute_key", "attribute_value"]partition_by = "toDate(time_bucket)"diff --git a/posthog/clickhouse/hcl/golden/local-multi/logs.hcl b/posthog/clickhouse/hcl/golden/local-multi/logs.hclindex 35d72a43d2a8..a9dc49099205 100644--- a/posthog/clickhouse/hcl/golden/local-multi/logs.hcl+++ b/posthog/clickhouse/hcl/golden/local-multi/logs.hcl@@ -1118,78 +1118,6 @@ SQL}}- table "logs_volume_buckets" {- order_by = ["team_id", "time_bucket", "generation", "service_name", "namespace", "environment", "severity_text"]- partition_by = "toDate(time_bucket)"- ttl = "time_bucket + toIntervalDay(42)"- settings = {- index_granularity = "8192"- ttl_only_drop_parts = "1"- }- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime('UTC')"- codec = "DoubleDelta, ZSTD(1)"- }- column "generation" {- type = "UInt64"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "namespace" {- type = "LowCardinality(String)"- }- column "environment" {- type = "LowCardinality(String)"- }- column "severity_text" {- type = "LowCardinality(String)"- }- column "log_count" {- type = "UInt64"- }- engine "replicated_merge_tree" {- zoo_path = "/clickhouse/tables/noshard/posthog.logs_volume_buckets"- replica_name = "{replica}-{shard}"- }- }-- table "logs_volume_buckets_distributed" {- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime('UTC')"- codec = "DoubleDelta, ZSTD(1)"- }- column "generation" {- type = "UInt64"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "namespace" {- type = "LowCardinality(String)"- }- column "environment" {- type = "LowCardinality(String)"- }- column "severity_text" {- type = "LowCardinality(String)"- }- column "log_count" {- type = "UInt64"- }- engine "distributed" {- cluster_name = "posthog_single_shard"- remote_database = "posthog"- remote_table = "logs_volume_buckets"- }- }-table "metric_samples" {column "team_id" {type = "Int32"diff --git a/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl b/posthog/clickhouse/hcl/golden/prod-eu/logs.hclindex f4fdd05c35ff..f88323b41650 100644--- a/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl+++ b/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl@@ -776,78 +776,6 @@ database "posthog" {}}- table "logs_volume_buckets" {- order_by = ["team_id", "time_bucket", "generation", "service_name", "namespace", "environment", "severity_text"]- partition_by = "toDate(time_bucket)"- ttl = "time_bucket + toIntervalDay(42)"- settings = {- index_granularity = "8192"- ttl_only_drop_parts = "1"- }- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime('UTC')"- codec = "DoubleDelta, ZSTD(1)"- }- column "generation" {- type = "UInt64"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "namespace" {- type = "LowCardinality(String)"- }- column "environment" {- type = "LowCardinality(String)"- }- column "severity_text" {- type = "LowCardinality(String)"- }- column "log_count" {- type = "UInt64"- }- engine "replicated_merge_tree" {- zoo_path = "/clickhouse/tables/noshard/posthog.logs_volume_buckets"- replica_name = "{replica}-{shard}"- }- }-- table "logs_volume_buckets_distributed" {- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime('UTC')"- codec = "DoubleDelta, ZSTD(1)"- }- column "generation" {- type = "UInt64"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "namespace" {- type = "LowCardinality(String)"- }- column "environment" {- type = "LowCardinality(String)"- }- column "severity_text" {- type = "LowCardinality(String)"- }- column "log_count" {- type = "UInt64"- }- engine "distributed" {- cluster_name = "posthog_single_shard"- remote_database = "posthog"- remote_table = "logs_volume_buckets"- }- }-table "metric_attributes" {order_by = ["team_id", "attribute_type", "time_bucket", "resource_fingerprint", "attribute_key", "attribute_value"]partition_by = "toDate(time_bucket)"diff --git a/posthog/clickhouse/hcl/golden/prod-us/logs.hcl b/posthog/clickhouse/hcl/golden/prod-us/logs.hclindex fd9e1251c254..62f9597e60cb 100644--- a/posthog/clickhouse/hcl/golden/prod-us/logs.hcl+++ b/posthog/clickhouse/hcl/golden/prod-us/logs.hcl@@ -775,78 +775,6 @@ database "posthog" {}}- table "logs_volume_buckets" {- order_by = ["team_id", "time_bucket", "generation", "service_name", "namespace", "environment", "severity_text"]- partition_by = "toDate(time_bucket)"- ttl = "time_bucket + toIntervalDay(42)"- settings = {- index_granularity = "8192"- ttl_only_drop_parts = "1"- }- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime('UTC')"- codec = "DoubleDelta, ZSTD(1)"- }- column "generation" {- type = "UInt64"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "namespace" {- type = "LowCardinality(String)"- }- column "environment" {- type = "LowCardinality(String)"- }- column "severity_text" {- type = "LowCardinality(String)"- }- column "log_count" {- type = "UInt64"- }- engine "replicated_merge_tree" {- zoo_path = "/clickhouse/tables/noshard/posthog.logs_volume_buckets"- replica_name = "{replica}-{shard}"- }- }-- table "logs_volume_buckets_distributed" {- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime('UTC')"- codec = "DoubleDelta, ZSTD(1)"- }- column "generation" {- type = "UInt64"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "namespace" {- type = "LowCardinality(String)"- }- column "environment" {- type = "LowCardinality(String)"- }- column "severity_text" {- type = "LowCardinality(String)"- }- column "log_count" {- type = "UInt64"- }- engine "distributed" {- cluster_name = "posthog_single_shard"- remote_database = "posthog"- remote_table = "logs_volume_buckets"- }- }-table "metric_attributes" {order_by = ["team_id", "attribute_type", "time_bucket", "resource_fingerprint", "attribute_key", "attribute_value"]partition_by = "toDate(time_bucket)"diff --git a/posthog/clickhouse/hcl/roles/logs/base/tables.hcl b/posthog/clickhouse/hcl/roles/logs/base/tables.hclindex db99f520bd4e..dccddde576cd 100644--- a/posthog/clickhouse/hcl/roles/logs/base/tables.hcl+++ b/posthog/clickhouse/hcl/roles/logs/base/tables.hcl@@ -691,76 +691,6 @@ database "posthog" {}}- table "logs_volume_buckets" {- order_by = ["team_id", "time_bucket", "generation", "service_name", "namespace", "environment", "severity_text"]- partition_by = "toDate(time_bucket)"- ttl = "time_bucket + toIntervalDay(42)"- settings = {- index_granularity = "8192"- ttl_only_drop_parts = "1"- }- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime('UTC')"- codec = "DoubleDelta, ZSTD(1)"- }- column "generation" {- type = "UInt64"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "namespace" {- type = "LowCardinality(String)"- }- column "environment" {- type = "LowCardinality(String)"- }- column "severity_text" {- type = "LowCardinality(String)"- }- column "log_count" {- type = "UInt64"- }- engine "replicated_merge_tree" {- zoo_path = "/clickhouse/tables/noshard/posthog.logs_volume_buckets"- replica_name = "{replica}-{shard}"- }- }- table "logs_volume_buckets_distributed" {- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime('UTC')"- codec = "DoubleDelta, ZSTD(1)"- }- column "generation" {- type = "UInt64"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "namespace" {- type = "LowCardinality(String)"- }- column "environment" {- type = "LowCardinality(String)"- }- column "severity_text" {- type = "LowCardinality(String)"- }- column "log_count" {- type = "UInt64"- }- engine "distributed" {- cluster_name = "posthog_single_shard"- remote_database = "posthog"- remote_table = "logs_volume_buckets"- }- }table "metric_samples" {column "team_id" {type = "Int32"diff --git a/posthog/clickhouse/hcl/sql/dev/logs.sql b/posthog/clickhouse/hcl/sql/dev/logs.sqlindex 174017c12c41..36ee8359d67a 100644--- a/posthog/clickhouse/hcl/sql/dev/logs.sql+++ b/posthog/clickhouse/hcl/sql/dev/logs.sql@@ -190,26 +190,6 @@ CREATE TABLE posthog.logs_kafka_metrics_distributed (max_created_at SimpleAggregateFunction(max, DateTime64(9)),max_lag SimpleAggregateFunction(max, UInt64)) ENGINE = Distributed('logs', 'posthog', 'logs_kafka_metrics');-CREATE TABLE posthog.logs_volume_buckets (- team_id Int32,- time_bucket DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),- generation UInt64,- service_name LowCardinality(String),- namespace LowCardinality(String),- environment LowCardinality(String),- severity_text LowCardinality(String),- log_count UInt64-) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.logs_volume_buckets', '{replica}-{shard}') ORDER BY (team_id, time_bucket, generation, service_name, namespace, environment, severity_text) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(42) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;-CREATE TABLE posthog.logs_volume_buckets_distributed (- team_id Int32,- time_bucket DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),- generation UInt64,- service_name LowCardinality(String),- namespace LowCardinality(String),- environment LowCardinality(String),- severity_text LowCardinality(String),- log_count UInt64-) ENGINE = Distributed('posthog_single_shard', 'posthog', 'logs_volume_buckets');CREATE TABLE posthog.metric_attributes (team_id Int32,time_bucket DateTime64(0),diff --git a/posthog/clickhouse/hcl/sql/local-multi/logs.sql b/posthog/clickhouse/hcl/sql/local-multi/logs.sqlindex 4f47a4963c3a..0f56c0fb9b9c 100644--- a/posthog/clickhouse/hcl/sql/local-multi/logs.sql+++ b/posthog/clickhouse/hcl/sql/local-multi/logs.sql@@ -267,26 +267,6 @@ CREATE TABLE posthog.logs_kafka_metrics_distributed (max_created_at SimpleAggregateFunction(max, DateTime64(9)),max_lag SimpleAggregateFunction(max, UInt64)) ENGINE = Distributed('posthog_single_shard', 'posthog', 'logs_kafka_metrics');-CREATE TABLE posthog.logs_volume_buckets (- team_id Int32,- time_bucket DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),- generation UInt64,- service_name LowCardinality(String),- namespace LowCardinality(String),- environment LowCardinality(String),- severity_text LowCardinality(String),- log_count UInt64-) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.logs_volume_buckets', '{replica}-{shard}') ORDER BY (team_id, time_bucket, generation, service_name, namespace, environment, severity_text) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(42) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;-CREATE TABLE posthog.logs_volume_buckets_distributed (- team_id Int32,- time_bucket DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),- generation UInt64,- service_name LowCardinality(String),- namespace LowCardinality(String),- environment LowCardinality(String),- severity_text LowCardinality(String),- log_count UInt64-) ENGINE = Distributed('posthog_single_shard', 'posthog', 'logs_volume_buckets');CREATE TABLE posthog.metric_samples1 (team_id Int32,metric_name LowCardinality(String),diff --git a/posthog/clickhouse/hcl/sql/prod-eu/logs.sql b/posthog/clickhouse/hcl/sql/prod-eu/logs.sqlindex 4b077b4a03cc..bb669b689192 100644--- a/posthog/clickhouse/hcl/sql/prod-eu/logs.sql+++ b/posthog/clickhouse/hcl/sql/prod-eu/logs.sql@@ -214,26 +214,6 @@ CREATE TABLE posthog.logs_kafka_metrics_distributed (max_created_at SimpleAggregateFunction(max, DateTime64(9)),max_lag SimpleAggregateFunction(max, UInt64)) ENGINE = Distributed('logs', 'posthog', 'logs_kafka_metrics');-CREATE TABLE posthog.logs_volume_buckets (- team_id Int32,- time_bucket DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),- generation UInt64,- service_name LowCardinality(String),- namespace LowCardinality(String),- environment LowCardinality(String),- severity_text LowCardinality(String),- log_count UInt64-) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.logs_volume_buckets', '{replica}-{shard}') ORDER BY (team_id, time_bucket, generation, service_name, namespace, environment, severity_text) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(42) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;-CREATE TABLE posthog.logs_volume_buckets_distributed (- team_id Int32,- time_bucket DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),- generation UInt64,- service_name LowCardinality(String),- namespace LowCardinality(String),- environment LowCardinality(String),- severity_text LowCardinality(String),- log_count UInt64-) ENGINE = Distributed('posthog_single_shard', 'posthog', 'logs_volume_buckets');CREATE TABLE posthog.metric_attributes (team_id Int32,time_bucket DateTime64(0),diff --git a/posthog/clickhouse/hcl/sql/prod-us/logs.sql b/posthog/clickhouse/hcl/sql/prod-us/logs.sqlindex f4f40122cd75..8e3e05a34afa 100644--- a/posthog/clickhouse/hcl/sql/prod-us/logs.sql+++ b/posthog/clickhouse/hcl/sql/prod-us/logs.sql@@ -213,26 +213,6 @@ CREATE TABLE posthog.logs_kafka_metrics_distributed (max_created_at SimpleAggregateFunction(max, DateTime64(9)),max_lag SimpleAggregateFunction(max, UInt64)) ENGINE = Distributed('logs', 'posthog', 'logs_kafka_metrics');-CREATE TABLE posthog.logs_volume_buckets (- team_id Int32,- time_bucket DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),- generation UInt64,- service_name LowCardinality(String),- namespace LowCardinality(String),- environment LowCardinality(String),- severity_text LowCardinality(String),- log_count UInt64-) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.logs_volume_buckets', '{replica}-{shard}') ORDER BY (team_id, time_bucket, generation, service_name, namespace, environment, severity_text) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(42) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;-CREATE TABLE posthog.logs_volume_buckets_distributed (- team_id Int32,- time_bucket DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),- generation UInt64,- service_name LowCardinality(String),- namespace LowCardinality(String),- environment LowCardinality(String),- severity_text LowCardinality(String),- log_count UInt64-) ENGINE = Distributed('posthog_single_shard', 'posthog', 'logs_volume_buckets');CREATE TABLE posthog.metric_attributes (team_id Int32,time_bucket DateTime64(0),diff --git a/posthog/clickhouse/logs/__init__.py b/posthog/clickhouse/logs/__init__.pyindex 94726b0142b2..4c9b483f8237 100644--- a/posthog/clickhouse/logs/__init__.py+++ b/posthog/clickhouse/logs/__init__.py@@ -25,7 +25,6 @@ from .logs34 import ()from .logs_billing_metrics import LOGS_BILLING_METRICS_DISTRIBUTED_TABLE_SQL, LOGS_BILLING_METRICS_TABLE_SQLfrom .logs_kafka_metrics import LOGS_KAFKA_METRICS_DISTRIBUTED_TABLE_SQL, LOGS_KAFKA_METRICS_TABLE_SQL-from .logs_volume_buckets import LOGS_VOLUME_BUCKETS_DISTRIBUTED_TABLE_SQL, LOGS_VOLUME_BUCKETS_TABLE_SQL__all__ = ["LOGS32_TABLE_SQL",@@ -56,6 +55,4 @@ __all__ = ["LOG_ATTRIBUTES3_DISTRIBUTED_TABLE_SQL","LOGS_BILLING_METRICS_TABLE_SQL","LOGS_BILLING_METRICS_DISTRIBUTED_TABLE_SQL",- "LOGS_VOLUME_BUCKETS_TABLE_SQL",- "LOGS_VOLUME_BUCKETS_DISTRIBUTED_TABLE_SQL",]diff --git a/posthog/clickhouse/logs/logs_volume_buckets.py b/posthog/clickhouse/logs/logs_volume_buckets.pydeleted file mode 100644index aac369814a98..000000000000--- a/posthog/clickhouse/logs/logs_volume_buckets.py+++ /dev/null@@ -1,65 +0,0 @@-from django.conf import settings--from posthog.clickhouse.table_engines import Distributed, MergeTreeEngine, ReplicationScheme--# Per-5-minute log volume rollup for anomaly detection. One row per-# (team, bucket, generation, series) where the series identity is-# (service_name, namespace, environment, severity_text) — evidence dimensions-# (service.version, instrumentation_scope, host/pod) are deliberately excluded:-# they multiply rows 5-30x and belong on the filed issue record, not the rollup.-#-# Buckets are fixed wall-clock windows on a 5-minute UTC grid, never sliding.-# `generation` is the unix-millis start of one insert attempt, allocated and-# committed in Postgres (LogsVolumeBucketCompletion); storage here is immutable-# append-only and readers must filter to committed (time_bucket, generation)-# pairs — visibility is protocol-level, which is why this is a plain MergeTree-# rather than a Replacing/Collapsing variant (those can't express keys that-# vanish in a later generation, or double-count across generations).-#-# ORDER BY is time-early (unlike logs34's dims-early tail): the dominant read is-# team + scattered bucket windows with no dim predicate, and with only ~288-# buckets/series/day a dims-early key makes every granule span the whole day.-#-# TTL is 42 days (6 weekly samples per time-of-week slot), decoupled from raw-# log retention and deliberately capped: longer dilutes the recent picture.-# Superseded and never-committed generations are not deleted — invisible to-# readers, they age out with the TTL (~3x row overhead, sub-GB). The writer-# issues no mutations; explicit cleanup DELETEs stay a deferred option.--TABLE_NAME = "logs_volume_buckets"-DISTRIBUTED_TABLE_NAME = "logs_volume_buckets_distributed"---def LOGS_VOLUME_BUCKETS_TABLE_SQL():- return f"""-CREATE TABLE IF NOT EXISTS {settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE}.{TABLE_NAME}-(- `team_id` Int32,- `time_bucket` DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),- `generation` UInt64,- `service_name` LowCardinality(String),- `namespace` LowCardinality(String),- `environment` LowCardinality(String),- `severity_text` LowCardinality(String),- `log_count` UInt64-)-ENGINE = {MergeTreeEngine(TABLE_NAME, replication_scheme=ReplicationScheme.REPLICATED)}-PARTITION BY toDate(time_bucket)-ORDER BY (team_id, time_bucket, generation, service_name, namespace, environment, severity_text)-TTL time_bucket + INTERVAL 42 DAY-SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1-"""---def LOGS_VOLUME_BUCKETS_DISTRIBUTED_TABLE_SQL():- return """-CREATE TABLE IF NOT EXISTS {database}.{distributed_table_name} AS {database}.{table_name} ENGINE = {engine}-""".format(- engine=Distributed(- data_table=TABLE_NAME,- cluster=settings.CLICKHOUSE_LOGS_CLUSTER,- ),- database=settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE,- distributed_table_name=DISTRIBUTED_TABLE_NAME,- table_name=TABLE_NAME,- )diff --git a/posthog/clickhouse/migrations/0294_logs_volume_buckets.py b/posthog/clickhouse/migrations/0294_logs_volume_buckets.pyindex 52b95bab894d..e726579705c5 100644--- a/posthog/clickhouse/migrations/0294_logs_volume_buckets.py+++ b/posthog/clickhouse/migrations/0294_logs_volume_buckets.py@@ -1,8 +1,41 @@+from django.conf import settings+from posthog.clickhouse.client.connection import NodeRolefrom posthog.clickhouse.client.migration_tools import run_sql_with_exceptions-from posthog.clickhouse.logs import LOGS_VOLUME_BUCKETS_DISTRIBUTED_TABLE_SQL, LOGS_VOLUME_BUCKETS_TABLE_SQL+from posthog.clickhouse.table_engines import Distributed, MergeTreeEngine, ReplicationScheme++# These tables were dropped in 0299, so their SQL is inlined here instead of+# living in a shared definition module.++TABLE_NAME = "logs_volume_buckets"+DISTRIBUTED_TABLE_NAME = "logs_volume_buckets_distributed"++LOGS_VOLUME_BUCKETS_TABLE_SQL = f"""+CREATE TABLE IF NOT EXISTS {settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE}.{TABLE_NAME}+(+ `team_id` Int32,+ `time_bucket` DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),+ `generation` UInt64,+ `service_name` LowCardinality(String),+ `namespace` LowCardinality(String),+ `environment` LowCardinality(String),+ `severity_text` LowCardinality(String),+ `log_count` UInt64+)+ENGINE = {MergeTreeEngine(TABLE_NAME, replication_scheme=ReplicationScheme.REPLICATED)}+PARTITION BY toDate(time_bucket)+ORDER BY (team_id, time_bucket, generation, service_name, namespace, environment, severity_text)+TTL time_bucket + INTERVAL 42 DAY+SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1+"""++LOGS_VOLUME_BUCKETS_DISTRIBUTED_TABLE_SQL = f"""+CREATE TABLE IF NOT EXISTS {settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE}.{DISTRIBUTED_TABLE_NAME}+AS {settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE}.{TABLE_NAME}+ENGINE = {Distributed(data_table=TABLE_NAME, cluster=settings.CLICKHOUSE_LOGS_CLUSTER)}+"""operations = [- run_sql_with_exceptions(LOGS_VOLUME_BUCKETS_TABLE_SQL(), node_roles=[NodeRole.LOGS]),- run_sql_with_exceptions(LOGS_VOLUME_BUCKETS_DISTRIBUTED_TABLE_SQL(), node_roles=[NodeRole.LOGS]),+ run_sql_with_exceptions(LOGS_VOLUME_BUCKETS_TABLE_SQL, node_roles=[NodeRole.LOGS]),+ run_sql_with_exceptions(LOGS_VOLUME_BUCKETS_DISTRIBUTED_TABLE_SQL, node_roles=[NodeRole.LOGS]),]diff --git a/posthog/clickhouse/migrations/0296_logs_volume_buckets_time_bucket.py b/posthog/clickhouse/migrations/0296_logs_volume_buckets_time_bucket.pyindex e9b2a44f2438..f8dad014d56a 100644--- a/posthog/clickhouse/migrations/0296_logs_volume_buckets_time_bucket.py+++ b/posthog/clickhouse/migrations/0296_logs_volume_buckets_time_bucket.py@@ -2,18 +2,44 @@ from django.conf import settingsfrom posthog.clickhouse.client.connection import NodeRolefrom posthog.clickhouse.client.migration_tools import run_sql_with_exceptions-from posthog.clickhouse.logs.logs_volume_buckets import (- DISTRIBUTED_TABLE_NAME,- LOGS_VOLUME_BUCKETS_DISTRIBUTED_TABLE_SQL,- LOGS_VOLUME_BUCKETS_TABLE_SQL,- TABLE_NAME,-)+from posthog.clickhouse.table_engines import Distributed, MergeTreeEngine, ReplicationScheme# Renames bucket_start to time_bucket to match the other logs tables. RENAME# COLUMN is impossible here — the column is part of the key expression# (ORDER BY / PARTITION BY / TTL), which ClickHouse rejects with Code 524 —# so this drops and recreates instead. Safe only because the table is empty:# it shipped in 0294 and the aggregation writer does not exist yet.+#+# These tables were dropped in 0299, so their SQL is inlined here instead of+# living in a shared definition module.++TABLE_NAME = "logs_volume_buckets"+DISTRIBUTED_TABLE_NAME = "logs_volume_buckets_distributed"++LOGS_VOLUME_BUCKETS_TABLE_SQL = f"""+CREATE TABLE IF NOT EXISTS {settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE}.{TABLE_NAME}+(+ `team_id` Int32,+ `time_bucket` DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),+ `generation` UInt64,+ `service_name` LowCardinality(String),+ `namespace` LowCardinality(String),+ `environment` LowCardinality(String),+ `severity_text` LowCardinality(String),+ `log_count` UInt64+)+ENGINE = {MergeTreeEngine(TABLE_NAME, replication_scheme=ReplicationScheme.REPLICATED)}+PARTITION BY toDate(time_bucket)+ORDER BY (team_id, time_bucket, generation, service_name, namespace, environment, severity_text)+TTL time_bucket + INTERVAL 42 DAY+SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1+"""++LOGS_VOLUME_BUCKETS_DISTRIBUTED_TABLE_SQL = f"""+CREATE TABLE IF NOT EXISTS {settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE}.{DISTRIBUTED_TABLE_NAME}+AS {settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE}.{TABLE_NAME}+ENGINE = {Distributed(data_table=TABLE_NAME, cluster=settings.CLICKHOUSE_LOGS_CLUSTER)}+"""DROP_DISTRIBUTED_SQL = f"DROP TABLE IF EXISTS {settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE}.{DISTRIBUTED_TABLE_NAME} SYNC"DROP_LOCAL_SQL = f"DROP TABLE IF EXISTS {settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE}.{TABLE_NAME} SYNC"@@ -21,6 +47,6 @@ DROP_LOCAL_SQL = f"DROP TABLE IF EXISTS {settings.CLICKHOUSE_LOGS_CLUSTER_DATABAoperations = [run_sql_with_exceptions(DROP_DISTRIBUTED_SQL, node_roles=[NodeRole.LOGS]),run_sql_with_exceptions(DROP_LOCAL_SQL, node_roles=[NodeRole.LOGS]),- run_sql_with_exceptions(LOGS_VOLUME_BUCKETS_TABLE_SQL(), node_roles=[NodeRole.LOGS]),- run_sql_with_exceptions(LOGS_VOLUME_BUCKETS_DISTRIBUTED_TABLE_SQL(), node_roles=[NodeRole.LOGS]),+ run_sql_with_exceptions(LOGS_VOLUME_BUCKETS_TABLE_SQL, node_roles=[NodeRole.LOGS]),+ run_sql_with_exceptions(LOGS_VOLUME_BUCKETS_DISTRIBUTED_TABLE_SQL, node_roles=[NodeRole.LOGS]),]diff --git a/posthog/clickhouse/migrations/0299_drop_logs_volume_buckets.py b/posthog/clickhouse/migrations/0299_drop_logs_volume_buckets.pynew file mode 100644index 000000000000..785f0ad7b350--- /dev/null+++ b/posthog/clickhouse/migrations/0299_drop_logs_volume_buckets.py@@ -0,0 +1,20 @@+from django.conf import settings++from posthog.clickhouse.client.connection import NodeRole+from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions++DB = settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE++# Safe to drop without data loss: the table is empty and nothing reads it.+# max_table_size_to_drop = 0 lifts the server's drop-size guard, which would otherwise+# refuse the drop on any node where the table turned out to hold data.+operations = [+ run_sql_with_exceptions(+ f"DROP TABLE IF EXISTS {DB}.logs_volume_buckets_distributed SETTINGS max_table_size_to_drop = 0",+ node_roles=[NodeRole.LOGS],+ ),+ run_sql_with_exceptions(+ f"DROP TABLE IF EXISTS {DB}.logs_volume_buckets SYNC SETTINGS max_table_size_to_drop = 0",+ node_roles=[NodeRole.LOGS],+ ),+]diff --git a/posthog/clickhouse/migrations/max_migration.txt b/posthog/clickhouse/migrations/max_migration.txtindex a3e59dd17ae5..4dc135326081 100644--- a/posthog/clickhouse/migrations/max_migration.txt+++ b/posthog/clickhouse/migrations/max_migration.txt@@ -1 +1 @@-0298_logs34_mv_explicit_columns+0299_drop_logs_volume_bucketsdiff --git a/posthog/clickhouse/schema.py b/posthog/clickhouse/schema.pyindex 422682b0a1f4..31218ea0eee9 100644--- a/posthog/clickhouse/schema.py+++ b/posthog/clickhouse/schema.py@@ -29,8 +29,6 @@ from posthog.clickhouse.logs import (LOGS_DISTRIBUTED_TABLE_SQL,LOGS_KAFKA_METRICS_DISTRIBUTED_TABLE_SQL,LOGS_KAFKA_METRICS_TABLE_SQL,- LOGS_VOLUME_BUCKETS_DISTRIBUTED_TABLE_SQL,- LOGS_VOLUME_BUCKETS_TABLE_SQL,)from posthog.clickhouse.metrics import (METRIC_ATTRIBUTES_MV,@@ -421,7 +419,6 @@ CREATE_MERGETREE_TABLE_QUERIES = (LOGS34_TABLE_SQL,LOG_ATTRIBUTES2_TABLE_SQL,LOG_ATTRIBUTES3_TABLE_SQL,- LOGS_VOLUME_BUCKETS_TABLE_SQL,TRACE_SPANS_TABLE_SQL,TRACE_ATTRIBUTES_TABLE_SQL,TRACE_ATTRIBUTES2_TABLE_SQL,@@ -510,7 +507,6 @@ CREATE_DISTRIBUTED_TABLE_QUERIES = (LOG_ATTRIBUTES3_DISTRIBUTED_TABLE_SQL,LOGS_KAFKA_METRICS_DISTRIBUTED_TABLE_SQL,LOGS_BILLING_METRICS_DISTRIBUTED_TABLE_SQL,- LOGS_VOLUME_BUCKETS_DISTRIBUTED_TABLE_SQL,TRACE_SPANS_DISTRIBUTED_TABLE_SQL,TRACE_ATTRIBUTES_DISTRIBUTED_TABLE_SQL,METRICS_DISTRIBUTED_TABLE_SQL,diff --git a/posthog/clickhouse/test/__snapshots__/test_schema.ambr b/posthog/clickhouse/test/__snapshots__/test_schema.ambrindex a44bb4562cdc..a8709dadca33 100644--- a/posthog/clickhouse/test/__snapshots__/test_schema.ambr+++ b/posthog/clickhouse/test/__snapshots__/test_schema.ambr@@ -3777,35 +3777,6 @@'''# ----# name: test_create_table_query[logs_volume_buckets]- '''-- CREATE TABLE IF NOT EXISTS posthog_test.logs_volume_buckets- (- `team_id` Int32,- `time_bucket` DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),- `generation` UInt64,- `service_name` LowCardinality(String),- `namespace` LowCardinality(String),- `environment` LowCardinality(String),- `severity_text` LowCardinality(String),- `log_count` UInt64- )- ENGINE = ReplicatedMergeTree('/clickhouse/tables/77f1df52-4b43-11e9-910f-b8ca3a9b9f3e_noshard/posthog.logs_volume_buckets', '{replica}-{shard}')- PARTITION BY toDate(time_bucket)- ORDER BY (team_id, time_bucket, generation, service_name, namespace, environment, severity_text)- TTL time_bucket + INTERVAL 42 DAY- SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1-- '''-# ----# name: test_create_table_query[logs_volume_buckets_distributed]- '''-- CREATE TABLE IF NOT EXISTS posthog_test.logs_volume_buckets_distributed AS posthog_test.logs_volume_buckets ENGINE = Distributed('posthog_single_shard', 'posthog_test', 'logs_volume_buckets')-- '''-# ---# name: test_create_table_query[marketing_conversions_preaggregated]'''@@ -10641,28 +10612,6 @@'''# ----# name: test_create_table_query_replicated_and_storage[logs_volume_buckets]- '''-- CREATE TABLE IF NOT EXISTS posthog_test.logs_volume_buckets- (- `team_id` Int32,- `time_bucket` DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),- `generation` UInt64,- `service_name` LowCardinality(String),- `namespace` LowCardinality(String),- `environment` LowCardinality(String),- `severity_text` LowCardinality(String),- `log_count` UInt64- )- ENGINE = ReplicatedMergeTree('/clickhouse/tables/77f1df52-4b43-11e9-910f-b8ca3a9b9f3e_noshard/posthog.logs_volume_buckets', '{replica}-{shard}')- PARTITION BY toDate(time_bucket)- ORDER BY (team_id, time_bucket, generation, service_name, namespace, environment, severity_text)- TTL time_bucket + INTERVAL 42 DAY- SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1-- '''-# ---# name: test_create_table_query_replicated_and_storage[message_assets_data]'''