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.

feat(clickhouse): codify log_entries aux cluster tables (#105493)

Bryan Ciaraldidebd20ac48f5
diff --git a/posthog/clickhouse/hcl/golden/dev/auxiliary.hcl b/posthog/clickhouse/hcl/golden/dev/auxiliary.hcl
index 9bb0f21d859e..aa35007f2542 100644
--- a/posthog/clickhouse/hcl/golden/dev/auxiliary.hcl
+++ b/posthog/clickhouse/hcl/golden/dev/auxiliary.hcl
@@ -656,6 +656,84 @@ database "posthog" {
}
}
+ table "log_entries_data" {
+ order_by = ["team_id", "log_source", "log_source_id", "instance_id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(7) TO VOLUME 'cold', toDate(timestamp) + toIntervalDay(90)"
+ settings = {
+ index_granularity = "1024"
+ storage_policy = "s3_tiered"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.log_entries_data"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "log_entries_distributed" {
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "log_entries_data"
+ }
+ }
+
table "marketing_conversions_preaggregated" {
column "team_id" {
type = "Int64"
diff --git a/posthog/clickhouse/hcl/golden/dev/data.hcl b/posthog/clickhouse/hcl/golden/dev/data.hcl
index 6ce5eed2905d..a70ab951b6e2 100644
--- a/posthog/clickhouse/hcl/golden/dev/data.hcl
+++ b/posthog/clickhouse/hcl/golden/dev/data.hcl
@@ -2204,6 +2204,41 @@ database "posthog" {
}
}
+ table "log_entries_distributed" {
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "log_entries_data"
+ }
+ }
+
table "marketing_conversions_preaggregated" {
column "team_id" {
type = "Int64"
diff --git a/posthog/clickhouse/hcl/golden/local-multi/auxiliary.hcl b/posthog/clickhouse/hcl/golden/local-multi/auxiliary.hcl
index 09206fdf57c0..4d29a4ce18c3 100644
--- a/posthog/clickhouse/hcl/golden/local-multi/auxiliary.hcl
+++ b/posthog/clickhouse/hcl/golden/local-multi/auxiliary.hcl
@@ -700,6 +700,83 @@ database "posthog" {
}
}
+ table "log_entries_data" {
+ order_by = ["team_id", "log_source", "log_source_id", "instance_id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(90)"
+ settings = {
+ index_granularity = "1024"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.log_entries_data"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "log_entries_distributed" {
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "log_entries_data"
+ }
+ }
+
table "marketing_conversions_preaggregated" {
column "team_id" {
type = "Int64"
diff --git a/posthog/clickhouse/hcl/golden/local-multi/data.hcl b/posthog/clickhouse/hcl/golden/local-multi/data.hcl
index f2f1ae9ea7bc..a9f9f9abe380 100644
--- a/posthog/clickhouse/hcl/golden/local-multi/data.hcl
+++ b/posthog/clickhouse/hcl/golden/local-multi/data.hcl
@@ -2599,6 +2599,41 @@ database "posthog" {
}
}
+ table "log_entries_distributed" {
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "log_entries_data"
+ }
+ }
+
table "marketing_conversions_preaggregated" {
column "team_id" {
type = "Int64"
diff --git a/posthog/clickhouse/hcl/golden/local-multi/ingestion_small.hcl b/posthog/clickhouse/hcl/golden/local-multi/ingestion_small.hcl
index 68f3997a3d57..bd808b11d109 100644
--- a/posthog/clickhouse/hcl/golden/local-multi/ingestion_small.hcl
+++ b/posthog/clickhouse/hcl/golden/local-multi/ingestion_small.hcl
@@ -308,6 +308,41 @@ database "posthog" {
}
}
+ table "kafka_log_entries_aux" {
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ engine "kafka" {
+ collection = "warpstream_ingestion"
+ topic_list = "log_entries"
+ group_name = "clickhouse_log_entries_aux"
+ format = "JSONEachRow"
+ num_consumers = 1
+ max_block_size = 100000
+ skip_broken_messages = 100
+ poll_timeout_ms = 10000
+ thread_per_consumer = true
+ }
+ }
+
table "kafka_log_entries_v3" {
column "team_id" {
type = "UInt64"
@@ -1448,6 +1483,41 @@ database "posthog" {
}
}
+ table "writable_log_entries_aux" {
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "log_entries_data"
+ }
+ }
+
table "writable_person" {
column "id" {
type = "UUID"
@@ -2288,6 +2358,52 @@ SQL
}
}
+ materialized_view "log_entries_aux_mv" {
+ to_table = "posthog.writable_log_entries_aux"
+ query = <<SQL
+SELECT
+ team_id,
+ log_source,
+ log_source_id,
+ instance_id,
+ timestamp,
+ level,
+ message,
+ _timestamp,
+ _offset
+FROM kafka_log_entries_aux
+WHERE toDate(timestamp) <= today()
+SQL
+
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ }
+
materialized_view "log_entries_v3_mv" {
to_table = "posthog.writable_log_entries"
query = <<SQL
diff --git a/posthog/clickhouse/hcl/golden/local-single/all.hcl b/posthog/clickhouse/hcl/golden/local-single/all.hcl
index 3035e4ca459c..0488a935e834 100644
--- a/posthog/clickhouse/hcl/golden/local-single/all.hcl
+++ b/posthog/clickhouse/hcl/golden/local-single/all.hcl
@@ -3394,6 +3394,41 @@ database "posthog" {
}
}
+ table "kafka_log_entries_aux" {
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ engine "kafka" {
+ collection = "warpstream_ingestion"
+ topic_list = "log_entries"
+ group_name = "clickhouse_log_entries_aux"
+ format = "JSONEachRow"
+ num_consumers = 1
+ max_block_size = 100000
+ skip_broken_messages = 100
+ poll_timeout_ms = 10000
+ thread_per_consumer = true
+ }
+ }
+
table "kafka_log_entries_v3" {
column "team_id" {
type = "UInt64"
@@ -5103,6 +5138,83 @@ database "posthog" {
}
}
+ table "log_entries_data" {
+ order_by = ["team_id", "log_source", "log_source_id", "instance_id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(90)"
+ settings = {
+ index_granularity = "1024"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.log_entries_data"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "log_entries_distributed" {
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "log_entries_data"
+ }
+ }
+
table "logs" {
column "time_bucket" {
type = "DateTime"
@@ -17396,6 +17508,41 @@ SQL
}
}
+ table "writable_log_entries_aux" {
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "log_entries_data"
+ }
+ }
+
table "writable_logs34" {
settings = {
background_insert_batch = "1"
@@ -21500,6 +21647,52 @@ SQL
}
}
+ materialized_view "log_entries_aux_mv" {
+ to_table = "posthog.writable_log_entries_aux"
+ query = <<SQL
+SELECT
+ team_id,
+ log_source,
+ log_source_id,
+ instance_id,
+ timestamp,
+ level,
+ message,
+ _timestamp,
+ _offset
+FROM kafka_log_entries_aux
+WHERE toDate(timestamp) <= today()
+SQL
+
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ }
+
materialized_view "log_entries_v3_mv" {
to_table = "posthog.writable_log_entries"
query = <<SQL
diff --git a/posthog/clickhouse/hcl/golden/prod-eu/auxiliary.hcl b/posthog/clickhouse/hcl/golden/prod-eu/auxiliary.hcl
index ac341067018a..e07d1cc23f59 100644
--- a/posthog/clickhouse/hcl/golden/prod-eu/auxiliary.hcl
+++ b/posthog/clickhouse/hcl/golden/prod-eu/auxiliary.hcl
@@ -656,6 +656,84 @@ database "posthog" {
}
}
+ table "log_entries_data" {
+ order_by = ["team_id", "log_source", "log_source_id", "instance_id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(7) TO VOLUME 'cold', toDate(timestamp) + toIntervalDay(90)"
+ settings = {
+ index_granularity = "1024"
+ storage_policy = "s3_tiered"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.log_entries_data"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "log_entries_distributed" {
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "log_entries_data"
+ }
+ }
+
table "marketing_conversions_preaggregated" {
column "team_id" {
type = "Int64"
diff --git a/posthog/clickhouse/hcl/golden/prod-us/auxiliary.hcl b/posthog/clickhouse/hcl/golden/prod-us/auxiliary.hcl
index a20eca9ad4fa..63efe0c67439 100644
--- a/posthog/clickhouse/hcl/golden/prod-us/auxiliary.hcl
+++ b/posthog/clickhouse/hcl/golden/prod-us/auxiliary.hcl
@@ -694,6 +694,84 @@ database "posthog" {
}
}
+ table "log_entries_data" {
+ order_by = ["team_id", "log_source", "log_source_id", "instance_id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(7) TO VOLUME 'cold', toDate(timestamp) + toIntervalDay(90)"
+ settings = {
+ index_granularity = "1024"
+ storage_policy = "s3_tiered"
+ ttl_only_drop_parts = "1"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.log_entries_data"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+
+ table "log_entries_distributed" {
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "log_source" {
+ type = "LowCardinality(String)"
+ }
+ column "log_source_id" {
+ type = "String"
+ }
+ column "instance_id" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "level" {
+ type = "LowCardinality(String)"
+ }
+ column "message" {
+ type = "String"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "log_entries_data"
+ }
+ }
+
table "marketing_conversions_preaggregated" {
column "team_id" {
type = "Int64"
diff --git a/posthog/clickhouse/hcl/manifest.hcl b/posthog/clickhouse/hcl/manifest.hcl
index d9800feb2220..7b27f9354121 100644
--- a/posthog/clickhouse/hcl/manifest.hcl
+++ b/posthog/clickhouse/hcl/manifest.hcl
@@ -74,10 +74,10 @@ role "ai_events" {
# hosts the ingestion_warnings store; prod-us adds the Distributed proxy onto the data
# cluster. prod goldens are dump-baselined (not live-verifiable here).
role "aux" {
- env "local-multi" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/aux_small", "roles/auxiliary/shared", "roles/auxiliary/local"] }
- env "dev" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/aux_small", "roles/coshared/ingestion_warnings_store", "roles/auxiliary/shared", "roles/auxiliary/prod", "roles/auxiliary/dev"] }
- env "prod-us" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/aux_small", "roles/coshared/ingestion_warnings_store", "roles/auxiliary/shared", "roles/auxiliary/prod", "roles/auxiliary/prod-us"] }
- env "prod-eu" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/aux_small", "roles/coshared/ingestion_warnings_store", "roles/auxiliary/shared", "roles/auxiliary/prod", "roles/auxiliary/prod-eu"] }
+ env "local-multi" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/log_entries_aux", "roles/coshared/aux_small", "roles/auxiliary/shared", "roles/auxiliary/local"] }
+ env "dev" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/log_entries_aux", "roles/coshared/aux_small", "roles/coshared/ingestion_warnings_store", "roles/auxiliary/shared", "roles/auxiliary/prod", "roles/auxiliary/dev"] }
+ env "prod-us" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/log_entries_aux", "roles/coshared/aux_small", "roles/coshared/ingestion_warnings_store", "roles/auxiliary/shared", "roles/auxiliary/prod", "roles/auxiliary/prod-us"] }
+ env "prod-eu" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/log_entries_aux", "roles/coshared/aux_small", "roles/coshared/ingestion_warnings_store", "roles/auxiliary/shared", "roles/auxiliary/prod", "roles/auxiliary/prod-eu"] }
}
# SESSIONS satellite: the local node runs only the shared query_log_archive path
@@ -118,10 +118,10 @@ role "batch_exports" {
# columns per env that are added out-of-band and churn constantly, so their goldens
# live in PostHog/posthog-cloud-infra (clickhouse/hcl/), not the OSS gate.
role "data" {
- env "dev" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/ai_events_data", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/sessions_data", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/cloud", "roles/coshared/log_entries_write", "roles/data/dev"] }
- env "prod-us" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/ai_events_data", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/sessions_data", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/cloud", "roles/data/prod", "roles/data/prod-us"] }
- env "prod-eu" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/ai_events_data", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/sessions_data", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/cloud", "roles/coshared/log_entries_write", "roles/data/prod", "roles/data/prod-eu"] }
- env "local-multi" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/sessions_data", "roles/coshared/ai_events_data", "roles/coshared/tophog", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/batch_exports_data", "roles/coshared/ingestion_warnings_store", "roles/coshared/events_json_write", "roles/coshared/log_entries_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/local"] }
+ env "dev" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/ai_events_data", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/log_entries_aux", "roles/coshared/sessions_data", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/cloud", "roles/coshared/log_entries_write", "roles/data/dev"] }
+ env "prod-us" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/ai_events_data", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/log_entries_aux", "roles/coshared/sessions_data", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/cloud", "roles/data/prod", "roles/data/prod-us"] }
+ env "prod-eu" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/custom_metrics", "roles/coshared/ai_events_data", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/log_entries_aux", "roles/coshared/sessions_data", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/cloud", "roles/coshared/log_entries_write", "roles/data/prod", "roles/data/prod-eu"] }
+ env "local-multi" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/log_entries_aux", "roles/coshared/sessions_data", "roles/coshared/ai_events_data", "roles/coshared/tophog", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/batch_exports_data", "roles/coshared/ingestion_warnings_store", "roles/coshared/events_json_write", "roles/coshared/log_entries_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/local"] }
}
# INGESTION satellites: the Kafka consumer layer. Each node carries the kafka_* engine
@@ -134,7 +134,7 @@ role "events" {
}
role "small" {
- env "local-multi" { layers = ["roles/shared/qla.hcl", "roles/coshared/named_collections", "roles/coshared/aux_small", "roles/coshared/log_entries_write", "roles/coshared/session_replay_write", "roles/ingestion_small/local"] }
+ env "local-multi" { layers = ["roles/shared/qla.hcl", "roles/coshared/named_collections", "roles/coshared/aux_small", "roles/coshared/log_entries_write", "roles/coshared/log_entries_aux_write", "roles/coshared/session_replay_write", "roles/ingestion_small/local"] }
}
role "medium" {
@@ -146,7 +146,7 @@ role "medium" {
# and not MULTINODE_CLICKHOUSE. Composed as the deduped union of the local-multi stacks it
# hosts, so any name two of those roles declare fails this load instead of drifting.
role "all" {
- env "local-single" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/apm_ingest", "roles/coshared/logs_avro_ingest", "roles/coshared/custom_metrics", "roles/ops/shared", "roles/ops/local", "roles/logs/base", "roles/logs/traces", "roles/logs/traces_kafka_metrics", "roles/logs/metrics", "roles/logs/local", "roles/apm/shared", "roles/apm/local", "roles/coshared/ai_events_data", "roles/ai_events/shared", "roles/ai_events/local", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/aux_small", "roles/auxiliary/shared", "roles/auxiliary/local", "roles/coshared/sessions_data", "roles/coshared/tophog", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/batch_exports_data", "roles/coshared/ingestion_warnings_store", "roles/coshared/events_json_write", "roles/coshared/log_entries_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/local", "roles/ingestion_events/shared", "roles/ingestion_events/local", "roles/ingestion_events/local-single", "roles/ingestion_small/local", "roles/ingestion_medium/local"] }
+ env "local-single" { layers = ["roles/shared", "roles/coshared/named_collections", "roles/coshared/apm_ingest", "roles/coshared/logs_avro_ingest", "roles/coshared/custom_metrics", "roles/ops/shared", "roles/ops/local", "roles/logs/base", "roles/logs/traces", "roles/logs/traces_kafka_metrics", "roles/logs/metrics", "roles/logs/local", "roles/apm/shared", "roles/apm/local", "roles/coshared/ai_events_data", "roles/ai_events/shared", "roles/ai_events/local", "roles/coshared/aux_data", "roles/coshared/person_property_mutations", "roles/coshared/log_entries_aux", "roles/coshared/aux_small", "roles/auxiliary/shared", "roles/auxiliary/local", "roles/coshared/sessions_data", "roles/coshared/tophog", "roles/coshared/events_recent", "roles/coshared/events_recent_write", "roles/coshared/batch_exports_data", "roles/coshared/ingestion_warnings_store", "roles/coshared/events_json_write", "roles/coshared/log_entries_write", "roles/coshared/log_entries_aux_write", "roles/coshared/session_replay_write", "roles/data/shared", "roles/data/common", "roles/data/local", "roles/ingestion_events/shared", "roles/ingestion_events/local", "roles/ingestion_events/local-single", "roles/ingestion_small/local", "roles/ingestion_medium/local"] }
}
# role "endpoints" {
diff --git a/posthog/clickhouse/hcl/roles/auxiliary/prod/patches.hcl b/posthog/clickhouse/hcl/roles/auxiliary/prod/patches.hcl
index 26f415466dbf..88540aa64368 100644
--- a/posthog/clickhouse/hcl/roles/auxiliary/prod/patches.hcl
+++ b/posthog/clickhouse/hcl/roles/auxiliary/prod/patches.hcl
@@ -5,4 +5,10 @@ database "posthog" {
storage_policy = "s3_tiered"
}
}
+ patch_table "log_entries_data" {
+ ttl = "toDate(timestamp) + toIntervalDay(7) TO VOLUME 'cold', toDate(timestamp) + toIntervalDay(90)"
+ settings = {
+ storage_policy = "s3_tiered"
+ }
+ }
}
diff --git a/posthog/clickhouse/hcl/roles/auxiliary/shared/log_entries.hcl b/posthog/clickhouse/hcl/roles/auxiliary/shared/log_entries.hcl
new file mode 100644
index 000000000000..ffd8e7b4460c
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/auxiliary/shared/log_entries.hcl
@@ -0,0 +1,19 @@
+# The aux log_entries store. Tiering (7-day move to the S3 `cold` volume + s3_tiered
+# storage policy) is a deployed-cloud delta in roles/auxiliary/prod/patches.hcl.
+database "posthog" {
+ table "log_entries_data" {
+ extend = "_log_entries_aux_columns"
+ order_by = ["team_id", "log_source", "log_source_id", "instance_id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(90)"
+ settings = {
+ index_granularity = "1024"
+ ttl_only_drop_parts = "1"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.log_entries_data"
+ replica_name = "{replica}"
+ version_column = "_timestamp"
+ }
+ }
+}
diff --git a/posthog/clickhouse/hcl/roles/coshared/log_entries_aux/tables.hcl b/posthog/clickhouse/hcl/roles/coshared/log_entries_aux/tables.hcl
new file mode 100644
index 000000000000..47a570b60089
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/coshared/log_entries_aux/tables.hcl
@@ -0,0 +1,25 @@
+# log_entries on the aux cluster: the column core and
+# the Distributed reader, composed by the aux and data nodes. The data table lives in
+# roles/auxiliary/shared, the Kafka consumer trio in roles/coshared/log_entries_aux_write.
+database "posthog" {
+ table "_log_entries_aux_columns" {
+ abstract = true
+ column "team_id" { type = "UInt64" }
+ column "log_source" { type = "LowCardinality(String)" }
+ column "log_source_id" { type = "String" }
+ column "instance_id" { type = "String" }
+ column "timestamp" { type = "DateTime64(6, 'UTC')" }
+ column "level" { type = "LowCardinality(String)" }
+ column "message" { type = "String" }
+ column "_timestamp" { type = "DateTime" }
+ column "_offset" { type = "UInt64" }
+ }
+ table "log_entries_distributed" {
+ extend = "_log_entries_aux_columns"
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "log_entries_data"
+ }
+ }
+}
diff --git a/posthog/clickhouse/hcl/roles/coshared/log_entries_aux_write/sql/log_entries_aux_mv.sql b/posthog/clickhouse/hcl/roles/coshared/log_entries_aux_write/sql/log_entries_aux_mv.sql
new file mode 100644
index 000000000000..f345f70abb54
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/coshared/log_entries_aux_write/sql/log_entries_aux_mv.sql
@@ -0,0 +1,12 @@
+SELECT
+ team_id,
+ log_source,
+ log_source_id,
+ instance_id,
+ timestamp,
+ level,
+ message,
+ _timestamp,
+ _offset
+FROM kafka_log_entries_aux
+WHERE toDate(timestamp) <= today()
diff --git a/posthog/clickhouse/hcl/roles/coshared/log_entries_aux_write/tables.hcl b/posthog/clickhouse/hcl/roles/coshared/log_entries_aux_write/tables.hcl
new file mode 100644
index 000000000000..b526ca4a0648
--- /dev/null
+++ b/posthog/clickhouse/hcl/roles/coshared/log_entries_aux_write/tables.hcl
@@ -0,0 +1,54 @@
+# The aux log_entries Kafka consumer trio. Cloud placement is asymmetric (EU
+# ingestion-small, US ingestion-medium) and cloud ingestion nodes are not in the
+# managed set yet, so this layer is composed only on the local small node.
+database "posthog" {
+ table "writable_log_entries_aux" {
+ column "team_id" { type = "UInt64" }
+ column "log_source" { type = "LowCardinality(String)" }
+ column "log_source_id" { type = "String" }
+ column "instance_id" { type = "String" }
+ column "timestamp" { type = "DateTime64(6, 'UTC')" }
+ column "level" { type = "LowCardinality(String)" }
+ column "message" { type = "String" }
+ column "_timestamp" { type = "DateTime" }
+ column "_offset" { type = "UInt64" }
+ engine "distributed" {
+ cluster_name = "aux"
+ remote_database = "posthog"
+ remote_table = "log_entries_data"
+ }
+ }
+ table "kafka_log_entries_aux" {
+ column "team_id" { type = "UInt64" }
+ column "log_source" { type = "LowCardinality(String)" }
+ column "log_source_id" { type = "String" }
+ column "instance_id" { type = "String" }
+ column "timestamp" { type = "DateTime64(6, 'UTC')" }
+ column "level" { type = "LowCardinality(String)" }
+ column "message" { type = "String" }
+ engine "kafka" {
+ collection = "warpstream_ingestion"
+ topic_list = "log_entries"
+ group_name = "clickhouse_log_entries_aux"
+ format = "JSONEachRow"
+ skip_broken_messages = 100
+ num_consumers = 1
+ thread_per_consumer = true
+ poll_timeout_ms = 10000
+ max_block_size = 100000
+ }
+ }
+ materialized_view "log_entries_aux_mv" {
+ to_table = "posthog.writable_log_entries_aux"
+ query = file("sql/log_entries_aux_mv.sql")
+ column "team_id" { type = "UInt64" }
+ column "log_source" { type = "LowCardinality(String)" }
+ column "log_source_id" { type = "String" }
+ column "instance_id" { type = "String" }
+ column "timestamp" { type = "DateTime64(6, 'UTC')" }
+ column "level" { type = "LowCardinality(String)" }
+ column "message" { type = "String" }
+ column "_timestamp" { type = "DateTime" }
+ column "_offset" { type = "UInt64" }
+ }
+}
diff --git a/posthog/clickhouse/hcl/roles/data/prod/tables.hcl b/posthog/clickhouse/hcl/roles/data/prod/tables.hcl
index afcaf947994c..785a6ae55209 100644
--- a/posthog/clickhouse/hcl/roles/data/prod/tables.hcl
+++ b/posthog/clickhouse/hcl/roles/data/prod/tables.hcl
@@ -1,40 +1,5 @@
# Objects both prod data clusters run and dev does not.
database "posthog" {
- table "log_entries_distributed" {
- column "team_id" {
- type = "UInt64"
- }
- column "log_source" {
- type = "LowCardinality(String)"
- }
- column "log_source_id" {
- type = "String"
- }
- column "instance_id" {
- type = "String"
- }
- column "timestamp" {
- type = "DateTime64(6, 'UTC')"
- }
- column "level" {
- type = "LowCardinality(String)"
- }
- column "message" {
- type = "String"
- }
- column "_timestamp" {
- type = "DateTime"
- }
- column "_offset" {
- type = "UInt64"
- }
- engine "distributed" {
- cluster_name = "aux"
- remote_database = "posthog"
- remote_table = "log_entries_data"
- }
- }
-
table "new_raw_sessions" {
column "team_id" {
type = "Int64"
diff --git a/posthog/clickhouse/hcl/sql/dev/auxiliary.sql b/posthog/clickhouse/hcl/sql/dev/auxiliary.sql
index 7ece2e0e031e..f154ac370965 100644
--- a/posthog/clickhouse/hcl/sql/dev/auxiliary.sql
+++ b/posthog/clickhouse/hcl/sql/dev/auxiliary.sql
@@ -120,6 +120,28 @@ CREATE TABLE posthog.kafka_property_values (
property_value String,
property_count UInt64
) ENGINE = Kafka(warpstream_ingestion) SETTINGS kafka_format = 'JSONEachRow', kafka_group_name = 'clickhouse_property_values', kafka_num_consumers = 1, kafka_thread_per_consumer = 1, kafka_topic_list = 'clickhouse_property_values';
+CREATE TABLE posthog.log_entries_data (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.log_entries_data', '{replica}', _timestamp) ORDER BY (team_id, log_source, log_source_id, instance_id, timestamp) PARTITION BY toYYYYMMDD(timestamp) TTL toDate(timestamp) + toIntervalDay(7) TO VOLUME 'cold', toDate(timestamp) + toIntervalDay(90) SETTINGS index_granularity = 1024, storage_policy = 's3_tiered', ttl_only_drop_parts = 1;
+CREATE TABLE posthog.log_entries_distributed (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = Distributed('aux', 'posthog', 'log_entries_data');
CREATE TABLE posthog.message_assets_data (
team_id Int64,
function_kind LowCardinality(String),
diff --git a/posthog/clickhouse/hcl/sql/dev/data.sql b/posthog/clickhouse/hcl/sql/dev/data.sql
index e6f3679e6709..ccb5507f1360 100644
--- a/posthog/clickhouse/hcl/sql/dev/data.sql
+++ b/posthog/clickhouse/hcl/sql/dev/data.sql
@@ -444,6 +444,17 @@ CREATE TABLE posthog.llma_metrics_daily (
metric_name String,
metric_value Float64
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.llma_metrics_daily', '{replica}-{shard}') ORDER BY (team_id, date, metric_name) PARTITION BY toYYYYMM(date) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.log_entries_distributed (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = Distributed('aux', 'posthog', 'log_entries_data');
CREATE TABLE posthog.marketing_conversions_preaggregated (
team_id Int64,
job_id UUID,
diff --git a/posthog/clickhouse/hcl/sql/local-multi/auxiliary.sql b/posthog/clickhouse/hcl/sql/local-multi/auxiliary.sql
index 59240e92e9fb..74857317bc6b 100644
--- a/posthog/clickhouse/hcl/sql/local-multi/auxiliary.sql
+++ b/posthog/clickhouse/hcl/sql/local-multi/auxiliary.sql
@@ -134,6 +134,28 @@ CREATE TABLE posthog.kafka_property_values (
property_value String,
property_count UInt64
) ENGINE = Kafka(warpstream_ingestion) SETTINGS kafka_format = 'JSONEachRow', kafka_group_name = 'clickhouse_property_values', kafka_num_consumers = 1, kafka_thread_per_consumer = 1, kafka_topic_list = 'clickhouse_property_values';
+CREATE TABLE posthog.log_entries_data (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.log_entries_data', '{replica}', _timestamp) ORDER BY (team_id, log_source, log_source_id, instance_id, timestamp) PARTITION BY toYYYYMMDD(timestamp) TTL toDate(timestamp) + toIntervalDay(90) SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.log_entries_distributed (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = Distributed('aux', 'posthog', 'log_entries_data');
CREATE TABLE posthog.message_assets_data (
team_id Int64,
function_kind LowCardinality(String),
diff --git a/posthog/clickhouse/hcl/sql/local-multi/data.sql b/posthog/clickhouse/hcl/sql/local-multi/data.sql
index 7561bfd4a68d..8808edeb4280 100644
--- a/posthog/clickhouse/hcl/sql/local-multi/data.sql
+++ b/posthog/clickhouse/hcl/sql/local-multi/data.sql
@@ -453,6 +453,17 @@ CREATE TABLE posthog.llma_metrics_daily (
metric_name String,
metric_value Float64
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.llma_metrics_daily', '{replica}-{shard}') ORDER BY (team_id, date, metric_name) PARTITION BY toYYYYMM(date) SETTINGS index_granularity = 8192;
+CREATE TABLE posthog.log_entries_distributed (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = Distributed('aux', 'posthog', 'log_entries_data');
CREATE TABLE posthog.marketing_conversions_preaggregated (
team_id Int64,
job_id UUID,
diff --git a/posthog/clickhouse/hcl/sql/local-multi/ingestion_small.sql b/posthog/clickhouse/hcl/sql/local-multi/ingestion_small.sql
index fd713ed3f3a0..dda03bcc414a 100644
--- a/posthog/clickhouse/hcl/sql/local-multi/ingestion_small.sql
+++ b/posthog/clickhouse/hcl/sql/local-multi/ingestion_small.sql
@@ -91,6 +91,15 @@ CREATE TABLE posthog.kafka_ingestion_warnings (
details String CODEC(ZSTD(3)),
timestamp DateTime64(6, 'UTC')
) ENGINE = Kafka(msk_cluster) SETTINGS kafka_format = 'JSONEachRow', kafka_group_name = 'group1', kafka_topic_list = 'clickhouse_ingestion_warnings';
+CREATE TABLE posthog.kafka_log_entries_aux (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String
+) ENGINE = Kafka(warpstream_ingestion) SETTINGS kafka_format = 'JSONEachRow', kafka_group_name = 'clickhouse_log_entries_aux', kafka_max_block_size = 100000, kafka_num_consumers = 1, kafka_poll_timeout_ms = 10000, kafka_skip_broken_messages = 100, kafka_thread_per_consumer = 1, kafka_topic_list = 'log_entries';
CREATE TABLE posthog.kafka_log_entries_v3 (
team_id UInt64,
log_source LowCardinality(String),
@@ -430,6 +439,17 @@ CREATE TABLE posthog.writable_log_entries (
_timestamp DateTime,
_offset UInt64
) ENGINE = Distributed('posthog', 'posthog', 'sharded_log_entries', rand());
+CREATE TABLE posthog.writable_log_entries_aux (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = Distributed('aux', 'posthog', 'log_entries_data');
CREATE TABLE posthog.writable_person (
id UUID,
created_at DateTime64(3),
@@ -664,6 +684,18 @@ CREATE MATERIALIZED VIEW posthog.ingestion_warnings_mv TO posthog.writable_inges
_offset,
_partition
FROM posthog.kafka_ingestion_warnings;
+CREATE MATERIALIZED VIEW posthog.log_entries_aux_mv TO posthog.writable_log_entries_aux (team_id UInt64, log_source LowCardinality(String), log_source_id String, instance_id String, timestamp DateTime64(6, 'UTC'), level LowCardinality(String), message String, _timestamp DateTime, _offset UInt64) AS SELECT
+ team_id,
+ log_source,
+ log_source_id,
+ instance_id,
+ timestamp,
+ level,
+ message,
+ _timestamp,
+ _offset
+FROM kafka_log_entries_aux
+WHERE toDate(timestamp) <= today();
CREATE MATERIALIZED VIEW posthog.log_entries_v3_mv TO posthog.writable_log_entries (team_id UInt64, log_source LowCardinality(String), log_source_id String, instance_id String, timestamp DateTime64(6, 'UTC'), level LowCardinality(String), message String, _timestamp Nullable(DateTime), _offset UInt64) AS SELECT
team_id,
log_source,
diff --git a/posthog/clickhouse/hcl/sql/local-single/all.sql b/posthog/clickhouse/hcl/sql/local-single/all.sql
index 96ac92b79e0a..aef69dcd7c81 100644
--- a/posthog/clickhouse/hcl/sql/local-single/all.sql
+++ b/posthog/clickhouse/hcl/sql/local-single/all.sql
@@ -535,6 +535,15 @@ CREATE TABLE posthog.kafka_ingestion_warnings_v2 (
details String,
timestamp DateTime64(6, 'UTC')
) ENGINE = Kafka(warpstream_ingestion) SETTINGS kafka_format = 'JSONEachRow', kafka_group_name = 'clickhouse_ingestion_warnings_v2', kafka_topic_list = 'clickhouse_ingestion_warnings';
+CREATE TABLE posthog.kafka_log_entries_aux (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String
+) ENGINE = Kafka(warpstream_ingestion) SETTINGS kafka_format = 'JSONEachRow', kafka_group_name = 'clickhouse_log_entries_aux', kafka_max_block_size = 100000, kafka_num_consumers = 1, kafka_poll_timeout_ms = 10000, kafka_skip_broken_messages = 100, kafka_thread_per_consumer = 1, kafka_topic_list = 'log_entries';
CREATE TABLE posthog.kafka_log_entries_v3 (
team_id UInt64,
log_source LowCardinality(String),
@@ -1020,6 +1029,28 @@ CREATE TABLE posthog.log_attributes_distributed (
original_expiry_time_bucket DateTime DEFAULT now(),
severity_text LowCardinality(String)
) ENGINE = Distributed('posthog_single_shard', 'posthog', 'log_attributes3');
+CREATE TABLE posthog.log_entries_data (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.log_entries_data', '{replica}', _timestamp) ORDER BY (team_id, log_source, log_source_id, instance_id, timestamp) PARTITION BY toYYYYMMDD(timestamp) TTL toDate(timestamp) + toIntervalDay(90) SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1;
+CREATE TABLE posthog.log_entries_distributed (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = Distributed('aux', 'posthog', 'log_entries_data');
CREATE TABLE posthog.logs32 (
time_bucket DateTime MATERIALIZED toStartOfDay(timestamp) CODEC(DoubleDelta, ZSTD(1)),
original_expiry_timestamp DateTime64(6) CODEC(DoubleDelta, ZSTD(1)),
@@ -3936,6 +3967,17 @@ CREATE TABLE posthog.writable_log_entries (
_timestamp DateTime,
_offset UInt64
) ENGINE = Distributed('posthog', 'posthog', 'sharded_log_entries', rand());
+CREATE TABLE posthog.writable_log_entries_aux (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = Distributed('aux', 'posthog', 'log_entries_data');
CREATE TABLE posthog.writable_logs34 (
time_bucket DateTime MATERIALIZED toStartOfDay(timestamp),
original_expiry_timestamp DateTime64(6),
@@ -5065,6 +5107,18 @@ CREATE MATERIALIZED VIEW posthog.kafka_trace_spans_avro_mv TO posthog.trace_span
toInt64OrDefault(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')], toInt64(0)) AS _bytes_uncompressed,
toInt64OrDefault(_headers.value[indexOf(_headers.name, 'bytes_compressed')], toInt64(0)) AS _bytes_compressed
FROM posthog.kafka_trace_spans_avro;
+CREATE MATERIALIZED VIEW posthog.log_entries_aux_mv TO posthog.writable_log_entries_aux (team_id UInt64, log_source LowCardinality(String), log_source_id String, instance_id String, timestamp DateTime64(6, 'UTC'), level LowCardinality(String), message String, _timestamp DateTime, _offset UInt64) AS SELECT
+ team_id,
+ log_source,
+ log_source_id,
+ instance_id,
+ timestamp,
+ level,
+ message,
+ _timestamp,
+ _offset
+FROM kafka_log_entries_aux
+WHERE toDate(timestamp) <= today();
CREATE MATERIALIZED VIEW posthog.log_entries_v3_mv TO posthog.writable_log_entries (team_id UInt64, log_source LowCardinality(String), log_source_id String, instance_id String, timestamp DateTime64(6, 'UTC'), level LowCardinality(String), message String, _timestamp Nullable(DateTime), _offset UInt64) AS SELECT
team_id,
log_source,
diff --git a/posthog/clickhouse/hcl/sql/prod-eu/auxiliary.sql b/posthog/clickhouse/hcl/sql/prod-eu/auxiliary.sql
index e607852f2f2f..1b96a47c4f82 100644
--- a/posthog/clickhouse/hcl/sql/prod-eu/auxiliary.sql
+++ b/posthog/clickhouse/hcl/sql/prod-eu/auxiliary.sql
@@ -120,6 +120,28 @@ CREATE TABLE posthog.kafka_property_values (
property_value String,
property_count UInt64
) ENGINE = Kafka(warpstream_ingestion) SETTINGS kafka_format = 'JSONEachRow', kafka_group_name = 'clickhouse_property_values', kafka_num_consumers = 8, kafka_thread_per_consumer = 1, kafka_topic_list = 'clickhouse_property_values';
+CREATE TABLE posthog.log_entries_data (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.log_entries_data', '{replica}', _timestamp) ORDER BY (team_id, log_source, log_source_id, instance_id, timestamp) PARTITION BY toYYYYMMDD(timestamp) TTL toDate(timestamp) + toIntervalDay(7) TO VOLUME 'cold', toDate(timestamp) + toIntervalDay(90) SETTINGS index_granularity = 1024, storage_policy = 's3_tiered', ttl_only_drop_parts = 1;
+CREATE TABLE posthog.log_entries_distributed (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = Distributed('aux', 'posthog', 'log_entries_data');
CREATE TABLE posthog.message_assets_data (
team_id Int64,
function_kind LowCardinality(String),
diff --git a/posthog/clickhouse/hcl/sql/prod-us/auxiliary.sql b/posthog/clickhouse/hcl/sql/prod-us/auxiliary.sql
index 1de261b463d9..f654c57928ba 100644
--- a/posthog/clickhouse/hcl/sql/prod-us/auxiliary.sql
+++ b/posthog/clickhouse/hcl/sql/prod-us/auxiliary.sql
@@ -120,6 +120,28 @@ CREATE TABLE posthog.kafka_property_values (
property_value String,
property_count UInt64
) ENGINE = Kafka(warpstream_ingestion) SETTINGS kafka_format = 'JSONEachRow', kafka_group_name = 'clickhouse_property_values', kafka_num_consumers = 8, kafka_thread_per_consumer = 1, kafka_topic_list = 'clickhouse_property_values';
+CREATE TABLE posthog.log_entries_data (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.log_entries_data', '{replica}', _timestamp) ORDER BY (team_id, log_source, log_source_id, instance_id, timestamp) PARTITION BY toYYYYMMDD(timestamp) TTL toDate(timestamp) + toIntervalDay(7) TO VOLUME 'cold', toDate(timestamp) + toIntervalDay(90) SETTINGS index_granularity = 1024, storage_policy = 's3_tiered', ttl_only_drop_parts = 1;
+CREATE TABLE posthog.log_entries_distributed (
+ team_id UInt64,
+ log_source LowCardinality(String),
+ log_source_id String,
+ instance_id String,
+ timestamp DateTime64(6, 'UTC'),
+ level LowCardinality(String),
+ message String,
+ _timestamp DateTime,
+ _offset UInt64
+) ENGINE = Distributed('aux', 'posthog', 'log_entries_data');
CREATE TABLE posthog.message_assets_data (
team_id Int64,
function_kind LowCardinality(String),
diff --git a/posthog/clickhouse/kafka_engine.py b/posthog/clickhouse/kafka_engine.py
index 92fceb8e4eab..4c15c47cc7b4 100644
--- a/posthog/clickhouse/kafka_engine.py
+++ b/posthog/clickhouse/kafka_engine.py
@@ -36,6 +36,7 @@ CONSUMER_GROUP_FLAG_EVALUATIONS = "clickhouse_flag_evaluations"
# WarpStream consumer groups (separate from MSK so both can coexist)
CONSUMER_GROUP_LOG_ENTRIES_WS = "clickhouse_log_entries_ws"
+CONSUMER_GROUP_LOG_ENTRIES_AUX = "clickhouse_log_entries_aux"
CONSUMER_GROUP_APP_METRICS2_WS = "clickhouse_app_metrics2_ws"
CONSUMER_GROUP_TOPHOG_WS = "clickhouse_tophog_ws"
CONSUMER_GROUP_PRECALCULATED_EVENTS_WS = "clickhouse_precalculated_events_ws"
diff --git a/posthog/clickhouse/log_entries.py b/posthog/clickhouse/log_entries.py
index 1d45ce7c9e27..553f5bfffc19 100644
--- a/posthog/clickhouse/log_entries.py
+++ b/posthog/clickhouse/log_entries.py
@@ -231,3 +231,133 @@ def LOG_ENTRIES_V3_TABLE_MV_SQL():
from_table=f"kafka_{LOG_ENTRIES_TABLE}_v3",
database=CLICKHOUSE_DATABASE,
)
+
+
+# aux cluster migration (log_entries -> aux, S3-tiered)
+#
+# `log_entries_data` on the aux cluster is the go-forward store for log_entries: hot days on
+# local disk, days older than LOG_ENTRIES_AUX_HOT_DAYS on the `cold` (S3) volume, 90 day delete.
+# It is fed by a dedicated Kafka consumer (kafka_log_entries_aux + log_entries_aux_mv ->
+# writable_log_entries_aux) that runs alongside the main-cluster consumer during the dual-write
+# phase. `log_entries_distributed` is the reader over the aux data, present on both the aux and
+# main clusters; the read cutover swaps it with `log_entries` in a follow-up migration.
+#
+# The S3 storage policy only exists on deployed cloud clusters, so the tiering clauses are
+# resolved per run mode and omitted locally.
+
+LOG_ENTRIES_DATA_TABLE = "log_entries_data"
+LOG_ENTRIES_AUX_DISTRIBUTED_TABLE = "log_entries_distributed"
+LOG_ENTRIES_AUX_WRITABLE_TABLE = "writable_log_entries_aux"
+KAFKA_LOG_ENTRIES_AUX_TABLE = "kafka_log_entries_aux"
+LOG_ENTRIES_AUX_MV = "log_entries_aux_mv"
+LOG_ENTRIES_AUX_HOT_DAYS = 7
+
+
+def _log_entries_data_ttl() -> str:
+ from posthog.run_mode import run_mode
+
+ if run_mode().is_deployed_cloud:
+ return (
+ f"TTL toDate(timestamp) + INTERVAL {LOG_ENTRIES_AUX_HOT_DAYS} DAY TO VOLUME 'cold', "
+ f"toDate(timestamp) + INTERVAL {LOG_ENTRIES_TTL_DAYS} DAY DELETE"
+ )
+ return f"TTL toDate(timestamp) + INTERVAL {LOG_ENTRIES_TTL_DAYS} DAY DELETE"
+
+
+def _log_entries_data_settings() -> str:
+ from posthog.run_mode import run_mode
+
+ base = "index_granularity = 1024, ttl_only_drop_parts = 1"
+ if run_mode().is_deployed_cloud:
+ return base + ", storage_policy = 's3_tiered'"
+ return base
+
+
+def LOG_ENTRIES_DATA_TABLE_SQL():
+ return (
+ LOG_ENTRIES_TABLE_BASE_SQL
+ + """PARTITION BY toYYYYMMDD(timestamp) ORDER BY (team_id, log_source, log_source_id, instance_id, timestamp)
+{ttl_period}
+SETTINGS {table_settings}
+"""
+ ).format(
+ table_name=LOG_ENTRIES_DATA_TABLE,
+ on_cluster_clause=ON_CLUSTER_CLAUSE(False),
+ extra_fields=KAFKA_COLUMNS,
+ engine=LOG_ENTRIES_TABLE_ENGINE(LOG_ENTRIES_DATA_TABLE),
+ ttl_period=_log_entries_data_ttl(),
+ table_settings=_log_entries_data_settings(),
+ )
+
+
+def _log_entries_aux_distributed_engine():
+ from django.conf import settings
+
+ return Distributed(data_table=LOG_ENTRIES_DATA_TABLE, cluster=settings.CLICKHOUSE_AUX_CLUSTER)
+
+
+def LOG_ENTRIES_AUX_DISTRIBUTED_TABLE_SQL():
+ return LOG_ENTRIES_TABLE_BASE_SQL.format(
+ table_name=LOG_ENTRIES_AUX_DISTRIBUTED_TABLE,
+ on_cluster_clause=ON_CLUSTER_CLAUSE(False),
+ extra_fields=KAFKA_COLUMNS,
+ engine=_log_entries_aux_distributed_engine(),
+ )
+
+
+def LOG_ENTRIES_AUX_WRITABLE_TABLE_SQL():
+ return LOG_ENTRIES_TABLE_BASE_SQL.format(
+ table_name=LOG_ENTRIES_AUX_WRITABLE_TABLE,
+ on_cluster_clause=ON_CLUSTER_CLAUSE(False),
+ extra_fields=KAFKA_COLUMNS,
+ engine=_log_entries_aux_distributed_engine(),
+ )
+
+
+def KAFKA_LOG_ENTRIES_AUX_TABLE_SQL():
+ from posthog.clickhouse.kafka_engine import CONSUMER_GROUP_LOG_ENTRIES_AUX, kafka_num_consumers
+
+ return (
+ LOG_ENTRIES_TABLE_BASE_SQL
+ + """
+ SETTINGS kafka_skip_broken_messages = 100,
+ kafka_num_consumers = {num_consumers},
+ kafka_thread_per_consumer = 1,
+ kafka_poll_timeout_ms = 10000,
+ kafka_max_block_size = 100000
+ """
+ ).format(
+ num_consumers=kafka_num_consumers(1),
+ table_name=KAFKA_LOG_ENTRIES_AUX_TABLE,
+ on_cluster_clause=ON_CLUSTER_CLAUSE(False),
+ engine=kafka_engine(
+ topic=KAFKA_LOG_ENTRIES,
+ group=CONSUMER_GROUP_LOG_ENTRIES_AUX,
+ named_collection=CLICKHOUSE_KAFKA_WARPSTREAM_INGESTION_NAMED_COLLECTION,
+ ),
+ extra_fields="",
+ )
+
+
+def LOG_ENTRIES_AUX_MV_SQL():
+ return """
+ CREATE MATERIALIZED VIEW IF NOT EXISTS {mv_name}
+ TO {database}.{to_table}
+ AS SELECT
+ team_id,
+ log_source,
+ log_source_id,
+ instance_id,
+ timestamp,
+ level,
+ message,
+ _timestamp,
+ _offset
+ FROM {database}.{from_table}
+ WHERE toDate(timestamp) <= today()
+ """.format(
+ mv_name=LOG_ENTRIES_AUX_MV,
+ to_table=LOG_ENTRIES_AUX_WRITABLE_TABLE,
+ from_table=KAFKA_LOG_ENTRIES_AUX_TABLE,
+ database=CLICKHOUSE_DATABASE,
+ )
diff --git a/posthog/clickhouse/migrations/0332_log_entries_aux.py b/posthog/clickhouse/migrations/0332_log_entries_aux.py
new file mode 100644
index 000000000000..1b967ef8a0f2
--- /dev/null
+++ b/posthog/clickhouse/migrations/0332_log_entries_aux.py
@@ -0,0 +1,34 @@
+from posthog.clickhouse.client.connection import NodeRole
+from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions
+from posthog.clickhouse.log_entries import (
+ KAFKA_LOG_ENTRIES_AUX_TABLE_SQL,
+ LOG_ENTRIES_AUX_DISTRIBUTED_TABLE_SQL,
+ LOG_ENTRIES_AUX_MV_SQL,
+ LOG_ENTRIES_AUX_WRITABLE_TABLE_SQL,
+ LOG_ENTRIES_DATA_TABLE_SQL,
+)
+from posthog.run_mode import RunMode, run_mode
+
+# Codifies the objects for the log_entries move to the aux cluster.
+#
+# All statements are IF NOT EXISTS and are a no-op on prod EU/US, where these objects were
+# created by hand during the data migration and are already dual-writing. This migration makes
+# dev/test and any future environment consistent with prod.
+#
+# `log_entries_data` (aux) is the S3-tiered go-forward store. `log_entries_distributed` is the
+# reader over it, present on the aux and main clusters; the read cutover (swapping it with
+# `log_entries`) is a separate follow-up migration. The Kafka consumer trio runs on
+# ingestion-small in EU and ingestion-medium in US — role matching is exact, so the role is
+# resolved per run mode; targeting both roles would start a second consumer set in each region.
+# `run_mode()` is resolved here (not a raw CLOUD_DEPLOYMENT check) so a test re-import under a
+# patched deployment picks up the right branch. Local single-node is unaffected either way:
+# migration_tools collapses it to NodeRole.ALL.
+_ingestion_role = NodeRole.INGESTION_MEDIUM if run_mode() is RunMode.CLOUD_US else NodeRole.INGESTION_SMALL
+
+operations = [
+ run_sql_with_exceptions(LOG_ENTRIES_DATA_TABLE_SQL(), node_roles=[NodeRole.AUX]),
+ run_sql_with_exceptions(LOG_ENTRIES_AUX_DISTRIBUTED_TABLE_SQL(), node_roles=[NodeRole.AUX, NodeRole.DATA]),
+ run_sql_with_exceptions(LOG_ENTRIES_AUX_WRITABLE_TABLE_SQL(), node_roles=[_ingestion_role]),
+ run_sql_with_exceptions(KAFKA_LOG_ENTRIES_AUX_TABLE_SQL(), node_roles=[_ingestion_role]),
+ run_sql_with_exceptions(LOG_ENTRIES_AUX_MV_SQL(), node_roles=[_ingestion_role]),
+]
diff --git a/posthog/clickhouse/migrations/max_migration.txt b/posthog/clickhouse/migrations/max_migration.txt
index f6e76c5ef26c..57969f528cdd 100644
--- a/posthog/clickhouse/migrations/max_migration.txt
+++ b/posthog/clickhouse/migrations/max_migration.txt
@@ -1 +1 @@
-0331_metrics4_samples_timestamp_minmax
+0332_log_entries_aux
diff --git a/posthog/clickhouse/schema.py b/posthog/clickhouse/schema.py
index 4ed509652535..1ef69a14c50e 100644
--- a/posthog/clickhouse/schema.py
+++ b/posthog/clickhouse/schema.py
@@ -9,7 +9,16 @@ from posthog.clickhouse.dead_letter_queue import (
WRITABLE_DEAD_LETTER_QUEUE_TABLE_SQL,
)
from posthog.clickhouse.distributed_system_processes import DISTRIBUTED_SYSTEM_PROCESSES_TABLE_SQL
-from posthog.clickhouse.log_entries import KAFKA_LOG_ENTRIES_TABLE_SQL, LOG_ENTRIES_TABLE_MV_SQL, LOG_ENTRIES_TABLE_SQL
+from posthog.clickhouse.log_entries import (
+ KAFKA_LOG_ENTRIES_AUX_TABLE_SQL,
+ KAFKA_LOG_ENTRIES_TABLE_SQL,
+ LOG_ENTRIES_AUX_DISTRIBUTED_TABLE_SQL,
+ LOG_ENTRIES_AUX_MV_SQL,
+ LOG_ENTRIES_AUX_WRITABLE_TABLE_SQL,
+ LOG_ENTRIES_DATA_TABLE_SQL,
+ LOG_ENTRIES_TABLE_MV_SQL,
+ LOG_ENTRIES_TABLE_SQL,
+)
from posthog.clickhouse.logs import (
LOG_ATTRIBUTES2_TABLE_SQL,
LOG_ATTRIBUTES3_DISTRIBUTED_TABLE_SQL,
@@ -409,6 +418,7 @@ from products.event_definitions.backend.models.property_definition import PROPER
CREATE_MERGETREE_TABLE_QUERIES = (
PERSON_PROPERTY_MUTATION_LOG_DATA_TABLE_SQL,
LOG_ENTRIES_TABLE_SQL,
+ LOG_ENTRIES_DATA_TABLE_SQL,
CREATE_COHORTPEOPLE_TABLE_SQL,
PERSON_STATIC_COHORT_TABLE_SQL,
DEAD_LETTER_QUEUE_TABLE_SQL,
@@ -506,6 +516,8 @@ CREATE_MERGETREE_TABLE_QUERIES = (
)
CREATE_DISTRIBUTED_TABLE_QUERIES = (
PERSON_PROPERTY_MUTATION_LOG_TABLE_SQL,
+ LOG_ENTRIES_AUX_DISTRIBUTED_TABLE_SQL,
+ LOG_ENTRIES_AUX_WRITABLE_TABLE_SQL,
WRITABLE_EVENTS_TABLE_SQL,
DISTRIBUTED_EVENTS_TABLE_SQL,
WRITABLE_EVENTS_JSON_TABLE_SQL,
@@ -604,6 +616,7 @@ CREATE_DISTRIBUTED_TABLE_QUERIES = (
CREATE_KAFKA_TABLE_QUERIES = (
PERSON_PROPERTY_MUTATION_LOG_KAFKA_TABLE_SQL,
KAFKA_LOG_ENTRIES_TABLE_SQL,
+ KAFKA_LOG_ENTRIES_AUX_TABLE_SQL,
KAFKA_DEAD_LETTER_QUEUE_TABLE_SQL,
KAFKA_EVENTS_TABLE_JSON_SQL,
KAFKA_EVENTS_NATIVE_JSON_TABLE_SQL,
@@ -641,6 +654,7 @@ CREATE_KAFKA_TABLE_QUERIES = (
CREATE_MV_TABLE_QUERIES = (
PERSON_PROPERTY_MUTATION_LOG_MV_SQL,
LOG_ENTRIES_TABLE_MV_SQL,
+ LOG_ENTRIES_AUX_MV_SQL,
DEAD_LETTER_QUEUE_TABLE_MV_SQL,
EVENTS_TABLE_JSON_MV_SQL,
EVENTS_JSON_TABLE_MV_SQL,
diff --git a/posthog/clickhouse/test/__snapshots__/test_schema.ambr b/posthog/clickhouse/test/__snapshots__/test_schema.ambr
index c14aaa7608d6..a527f6b6da59 100644
--- a/posthog/clickhouse/test/__snapshots__/test_schema.ambr
+++ b/posthog/clickhouse/test/__snapshots__/test_schema.ambr
@@ -474,6 +474,41 @@
'''
# ---
+# name: test_create_kafka_table_with_different_kafka_host[kafka_log_entries_aux]
+ '''
+
+ CREATE TABLE IF NOT EXISTS kafka_log_entries_aux
+ (
+ team_id UInt64,
+ -- The name of the service or product that generated the logs.
+ -- Examples: batch_exports
+ log_source LowCardinality(String),
+ -- An id for the log source.
+ -- Set log_source to avoid collision with ids from other log sources if the id generation is not safe.
+ -- Examples: A batch export id, a cronjob id, a plugin id.
+ log_source_id String,
+ -- A secondary id e.g. for the instance of log_source that generated this log.
+ -- This may be ommitted if log_source is a singleton.
+ -- Examples: A batch export run id, a plugin_config id, a thread id, a process id, a machine id.
+ instance_id String,
+ -- Timestamp indicating when the log was generated.
+ timestamp DateTime64(6, 'UTC'),
+ -- The log level.
+ -- Examples: INFO, WARNING, DEBUG, ERROR.
+ level LowCardinality(String),
+ -- The actual log message.
+ message String
+
+ ) ENGINE = Kafka(warpstream_ingestion, kafka_topic_list = 'log_entries_test', kafka_group_name = 'clickhouse_log_entries_aux', kafka_format = 'JSONEachRow')
+
+ SETTINGS kafka_skip_broken_messages = 100,
+ kafka_num_consumers = 1,
+ kafka_thread_per_consumer = 1,
+ kafka_poll_timeout_ms = 10000,
+ kafka_max_block_size = 100000
+
+ '''
+# ---
# name: test_create_kafka_table_with_different_kafka_host[kafka_message_assets]
'''
@@ -2842,6 +2877,41 @@
'''
# ---
+# name: test_create_table_query[kafka_log_entries_aux]
+ '''
+
+ CREATE TABLE IF NOT EXISTS kafka_log_entries_aux
+ (
+ team_id UInt64,
+ -- The name of the service or product that generated the logs.
+ -- Examples: batch_exports
+ log_source LowCardinality(String),
+ -- An id for the log source.
+ -- Set log_source to avoid collision with ids from other log sources if the id generation is not safe.
+ -- Examples: A batch export id, a cronjob id, a plugin id.
+ log_source_id String,
+ -- A secondary id e.g. for the instance of log_source that generated this log.
+ -- This may be ommitted if log_source is a singleton.
+ -- Examples: A batch export run id, a plugin_config id, a thread id, a process id, a machine id.
+ instance_id String,
+ -- Timestamp indicating when the log was generated.
+ timestamp DateTime64(6, 'UTC'),
+ -- The log level.
+ -- Examples: INFO, WARNING, DEBUG, ERROR.
+ level LowCardinality(String),
+ -- The actual log message.
+ message String
+
+ ) ENGINE = Kafka(warpstream_ingestion, kafka_topic_list = 'log_entries_test', kafka_group_name = 'clickhouse_log_entries_aux', kafka_format = 'JSONEachRow')
+
+ SETTINGS kafka_skip_broken_messages = 100,
+ kafka_num_consumers = 1,
+ kafka_thread_per_consumer = 1,
+ kafka_poll_timeout_ms = 10000,
+ kafka_max_block_size = 100000
+
+ '''
+# ---
# name: test_create_table_query[kafka_message_assets]
'''
@@ -3466,6 +3536,93 @@
'''
# ---
+# name: test_create_table_query[log_entries_aux_mv]
+ '''
+
+ CREATE MATERIALIZED VIEW IF NOT EXISTS log_entries_aux_mv
+ TO posthog_test.writable_log_entries_aux
+ AS SELECT
+ team_id,
+ log_source,
+ log_source_id,
+ instance_id,
+ timestamp,
+ level,
+ message,
+ _timestamp,
+ _offset
+ FROM posthog_test.kafka_log_entries_aux
+ WHERE toDate(timestamp) <= today()
+
+ '''
+# ---
+# name: test_create_table_query[log_entries_data]
+ '''
+
+ CREATE TABLE IF NOT EXISTS log_entries_data
+ (
+ team_id UInt64,
+ -- The name of the service or product that generated the logs.
+ -- Examples: batch_exports
+ log_source LowCardinality(String),
+ -- An id for the log source.
+ -- Set log_source to avoid collision with ids from other log sources if the id generation is not safe.
+ -- Examples: A batch export id, a cronjob id, a plugin id.
+ log_source_id String,
+ -- A secondary id e.g. for the instance of log_source that generated this log.
+ -- This may be ommitted if log_source is a singleton.
+ -- Examples: A batch export run id, a plugin_config id, a thread id, a process id, a machine id.
+ instance_id String,
+ -- Timestamp indicating when the log was generated.
+ timestamp DateTime64(6, 'UTC'),
+ -- The log level.
+ -- Examples: INFO, WARNING, DEBUG, ERROR.
+ level LowCardinality(String),
+ -- The actual log message.
+ message String
+
+ , _timestamp DateTime
+ , _offset UInt64
+
+ ) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/77f1df52-4b43-11e9-910f-b8ca3a9b9f3e_noshard/posthog.log_entries_data', '{replica}-{shard}', _timestamp)
+ PARTITION BY toYYYYMMDD(timestamp) ORDER BY (team_id, log_source, log_source_id, instance_id, timestamp)
+ TTL toDate(timestamp) + INTERVAL 90 DAY DELETE
+ SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1
+
+ '''
+# ---
+# name: test_create_table_query[log_entries_distributed]
+ '''
+
+ CREATE TABLE IF NOT EXISTS log_entries_distributed
+ (
+ team_id UInt64,
+ -- The name of the service or product that generated the logs.
+ -- Examples: batch_exports
+ log_source LowCardinality(String),
+ -- An id for the log source.
+ -- Set log_source to avoid collision with ids from other log sources if the id generation is not safe.
+ -- Examples: A batch export id, a cronjob id, a plugin id.
+ log_source_id String,
+ -- A secondary id e.g. for the instance of log_source that generated this log.
+ -- This may be ommitted if log_source is a singleton.
+ -- Examples: A batch export run id, a plugin_config id, a thread id, a process id, a machine id.
+ instance_id String,
+ -- Timestamp indicating when the log was generated.
+ timestamp DateTime64(6, 'UTC'),
+ -- The log level.
+ -- Examples: INFO, WARNING, DEBUG, ERROR.
+ level LowCardinality(String),
+ -- The actual log message.
+ message String
+
+ , _timestamp DateTime
+ , _offset UInt64
+
+ ) ENGINE = Distributed('aux', 'posthog_test', 'log_entries_data')
+
+ '''
+# ---
# name: test_create_table_query[log_entries_mv]
'''
@@ -10488,6 +10645,38 @@
'''
# ---
+# name: test_create_table_query[writable_log_entries_aux]
+ '''
+
+ CREATE TABLE IF NOT EXISTS writable_log_entries_aux
+ (
+ team_id UInt64,
+ -- The name of the service or product that generated the logs.
+ -- Examples: batch_exports
+ log_source LowCardinality(String),
+ -- An id for the log source.
+ -- Set log_source to avoid collision with ids from other log sources if the id generation is not safe.
+ -- Examples: A batch export id, a cronjob id, a plugin id.
+ log_source_id String,
+ -- A secondary id e.g. for the instance of log_source that generated this log.
+ -- This may be ommitted if log_source is a singleton.
+ -- Examples: A batch export run id, a plugin_config id, a thread id, a process id, a machine id.
+ instance_id String,
+ -- Timestamp indicating when the log was generated.
+ timestamp DateTime64(6, 'UTC'),
+ -- The log level.
+ -- Examples: INFO, WARNING, DEBUG, ERROR.
+ level LowCardinality(String),
+ -- The actual log message.
+ message String
+
+ , _timestamp DateTime
+ , _offset UInt64
+
+ ) ENGINE = Distributed('aux', 'posthog_test', 'log_entries_data')
+
+ '''
+# ---
# name: test_create_table_query[writable_metrics4_attributes]
'''
@@ -11711,6 +11900,41 @@
'''
# ---
+# name: test_create_table_query_replicated_and_storage[log_entries_data]
+ '''
+
+ CREATE TABLE IF NOT EXISTS log_entries_data
+ (
+ team_id UInt64,
+ -- The name of the service or product that generated the logs.
+ -- Examples: batch_exports
+ log_source LowCardinality(String),
+ -- An id for the log source.
+ -- Set log_source to avoid collision with ids from other log sources if the id generation is not safe.
+ -- Examples: A batch export id, a cronjob id, a plugin id.
+ log_source_id String,
+ -- A secondary id e.g. for the instance of log_source that generated this log.
+ -- This may be ommitted if log_source is a singleton.
+ -- Examples: A batch export run id, a plugin_config id, a thread id, a process id, a machine id.
+ instance_id String,
+ -- Timestamp indicating when the log was generated.
+ timestamp DateTime64(6, 'UTC'),
+ -- The log level.
+ -- Examples: INFO, WARNING, DEBUG, ERROR.
+ level LowCardinality(String),
+ -- The actual log message.
+ message String
+
+ , _timestamp DateTime
+ , _offset UInt64
+
+ ) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/77f1df52-4b43-11e9-910f-b8ca3a9b9f3e_noshard/posthog.log_entries_data', '{replica}-{shard}', _timestamp)
+ PARTITION BY toYYYYMMDD(timestamp) ORDER BY (team_id, log_source, log_source_id, instance_id, timestamp)
+ TTL toDate(timestamp) + INTERVAL 90 DAY DELETE
+ SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1
+
+ '''
+# ---
# name: test_create_table_query_replicated_and_storage[logs32]
'''