: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): add internal_source column to logs34 (#121979)
Jon McCallum13d51c4f55c4
diff --git a/posthog/clickhouse/hcl/golden/dev/apm.hcl b/posthog/clickhouse/hcl/golden/dev/apm.hclindex f2d2edb86641..733ff3ea59af 100644--- a/posthog/clickhouse/hcl/golden/dev/apm.hcl+++ b/posthog/clickhouse/hcl/golden/dev/apm.hcl@@ -434,6 +434,10 @@ database "posthog" {column "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ default = "''"+ }engine "distributed" {cluster_name = "logs"remote_database = "posthog"@@ -1366,7 +1370,8 @@ SELECTtoInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) / _record_count AS _bytes_uncompressed,toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) / _record_count AS _bytes_compressed,ifNull(pattern, '') AS pattern,- toUInt8(ifNull(pattern_version, 0)) AS pattern_version+ toUInt8(ifNull(pattern_version, 0)) AS pattern_version,+ _headers.value[indexOf(_headers.name, 'internal-source')] AS internal_sourceFROM posthog.kafka_logs_avroSQL@@ -1442,6 +1447,9 @@ SQLcolumn "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }}materialized_view "kafka_metrics_avro4_mv" {diff --git a/posthog/clickhouse/hcl/golden/dev/logs.hcl b/posthog/clickhouse/hcl/golden/dev/logs.hclindex 97ed016beaf6..a02902b3a8b8 100644--- a/posthog/clickhouse/hcl/golden/dev/logs.hcl+++ b/posthog/clickhouse/hcl/golden/dev/logs.hcl@@ -298,6 +298,10 @@ database "posthog" {column "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ default = "''"+ }index "idx_severity_text_set" {expr = "severity_text"type = "set(10)"@@ -526,6 +530,10 @@ SQLcolumn "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ default = "''"+ }engine "distributed" {cluster_name = "logs"remote_database = "posthog"@@ -597,7 +605,7 @@ SQLtable "logs_pattern_buckets" {primary_key = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "pattern_version"]- order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "pattern_version", "pattern"]+ order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "pattern_version", "pattern", "internal_source"]partition_by = "toDate(time_bucket)"ttl = "time_bucket + toIntervalDay(greatest(42, retention_days))"settings = {@@ -629,6 +637,9 @@ SQLcolumn "pattern" {type = "String"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -667,6 +678,9 @@ SQLcolumn "pattern" {type = "String"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -681,7 +695,8 @@ SQL}table "logs_volume_buckets" {- order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text"]+ primary_key = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text"]+ order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "internal_source"]partition_by = "toDate(time_bucket)"ttl = "time_bucket + toIntervalDay(greatest(42, retention_days))"settings = {@@ -707,6 +722,9 @@ SQLcolumn "severity_text" {type = "LowCardinality(String)"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -739,6 +757,9 @@ SQLcolumn "severity_text" {type = "LowCardinality(String)"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -3699,6 +3720,7 @@ SELECTseverity_text,pattern_version,pattern,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -3724,6 +3746,7 @@ FROMlower(severity_text) AS severity_text,pattern_version,pattern,+ internal_source,toUInt16(least(intDiv(@@ -3738,7 +3761,7 @@ FROMWHERE pattern_version != 0)GROUP BY- team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern+ team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern, internal_sourceSQLcolumn "team_id" {@@ -3765,6 +3788,9 @@ SQLcolumn "pattern" {type = "String"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -3849,6 +3875,7 @@ SELECTnamespace,environment,severity_text,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -3872,6 +3899,7 @@ FROM)) AS environment,lower(severity_text) AS severity_text,+ internal_source,toUInt16(least(intDiv(@@ -3885,7 +3913,7 @@ FROMFROM posthog.logs34)GROUP BY- team_id, time_bucket, service_name, namespace, environment, severity_text+ team_id, time_bucket, service_name, namespace, environment, severity_text, internal_sourceSQLcolumn "team_id" {@@ -3906,6 +3934,9 @@ SQLcolumn "severity_text" {type = "LowCardinality(String)"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}diff --git a/posthog/clickhouse/hcl/golden/local-multi/ingestion_events.hcl b/posthog/clickhouse/hcl/golden/local-multi/ingestion_events.hclindex e965ccb569ea..33d7a50d4b80 100644--- a/posthog/clickhouse/hcl/golden/local-multi/ingestion_events.hcl+++ b/posthog/clickhouse/hcl/golden/local-multi/ingestion_events.hcl@@ -811,6 +811,10 @@ database "posthog" {column "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ default = "''"+ }engine "distributed" {cluster_name = "logs"remote_database = "posthog"@@ -1012,7 +1016,8 @@ SELECTtoInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) / _record_count AS _bytes_uncompressed,toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) / _record_count AS _bytes_compressed,ifNull(pattern, '') AS pattern,- toUInt8(ifNull(pattern_version, 0)) AS pattern_version+ toUInt8(ifNull(pattern_version, 0)) AS pattern_version,+ _headers.value[indexOf(_headers.name, 'internal-source')] AS internal_sourceFROM posthog.kafka_logs_avroSQL@@ -1088,6 +1093,9 @@ SQLcolumn "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }}}diff --git a/posthog/clickhouse/hcl/golden/local-multi/logs.hcl b/posthog/clickhouse/hcl/golden/local-multi/logs.hclindex 829fc695f39a..c3b9cf2c7a0f 100644--- a/posthog/clickhouse/hcl/golden/local-multi/logs.hcl+++ b/posthog/clickhouse/hcl/golden/local-multi/logs.hcl@@ -796,6 +796,10 @@ SQLcolumn "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ default = "''"+ }index "idx_severity_text_set" {expr = "severity_text"type = "set(10)"@@ -1024,6 +1028,10 @@ SQLcolumn "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ default = "''"+ }engine "distributed" {cluster_name = "posthog_single_shard"remote_database = "posthog"@@ -1094,7 +1102,7 @@ SQLtable "logs_pattern_buckets" {primary_key = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "pattern_version"]- order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "pattern_version", "pattern"]+ order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "pattern_version", "pattern", "internal_source"]partition_by = "toDate(time_bucket)"ttl = "time_bucket + toIntervalDay(greatest(42, retention_days))"settings = {@@ -1126,6 +1134,9 @@ SQLcolumn "pattern" {type = "String"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -1164,6 +1175,9 @@ SQLcolumn "pattern" {type = "String"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -1178,7 +1192,8 @@ SQL}table "logs_volume_buckets" {- order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text"]+ primary_key = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text"]+ order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "internal_source"]partition_by = "toDate(time_bucket)"ttl = "time_bucket + toIntervalDay(greatest(42, retention_days))"settings = {@@ -1204,6 +1219,9 @@ SQLcolumn "severity_text" {type = "LowCardinality(String)"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -1236,6 +1254,9 @@ SQLcolumn "severity_text" {type = "LowCardinality(String)"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -4097,6 +4118,7 @@ SELECTseverity_text,pattern_version,pattern,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -4122,6 +4144,7 @@ FROMlower(severity_text) AS severity_text,pattern_version,pattern,+ internal_source,toUInt16(least(intDiv(@@ -4136,7 +4159,7 @@ FROMWHERE pattern_version != 0)GROUP BY- team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern+ team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern, internal_sourceSQLcolumn "team_id" {@@ -4163,6 +4186,9 @@ SQLcolumn "pattern" {type = "String"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -4247,6 +4273,7 @@ SELECTnamespace,environment,severity_text,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -4270,6 +4297,7 @@ FROM)) AS environment,lower(severity_text) AS severity_text,+ internal_source,toUInt16(least(intDiv(@@ -4283,7 +4311,7 @@ FROMFROM posthog.logs34)GROUP BY- team_id, time_bucket, service_name, namespace, environment, severity_text+ team_id, time_bucket, service_name, namespace, environment, severity_text, internal_sourceSQLcolumn "team_id" {@@ -4304,6 +4332,9 @@ SQLcolumn "severity_text" {type = "LowCardinality(String)"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}diff --git a/posthog/clickhouse/hcl/golden/local-single/all.hcl b/posthog/clickhouse/hcl/golden/local-single/all.hclindex 84d730663419..4763c79d8fe0 100644--- a/posthog/clickhouse/hcl/golden/local-single/all.hcl+++ b/posthog/clickhouse/hcl/golden/local-single/all.hcl@@ -5532,6 +5532,10 @@ SQLcolumn "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ default = "''"+ }index "idx_severity_text_set" {expr = "severity_text"type = "set(10)"@@ -5760,6 +5764,10 @@ SQLcolumn "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ default = "''"+ }engine "distributed" {cluster_name = "posthog_single_shard"remote_database = "posthog"@@ -5830,7 +5838,7 @@ SQLtable "logs_pattern_buckets" {primary_key = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "pattern_version"]- order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "pattern_version", "pattern"]+ order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "pattern_version", "pattern", "internal_source"]partition_by = "toDate(time_bucket)"ttl = "time_bucket + toIntervalDay(greatest(42, retention_days))"settings = {@@ -5862,6 +5870,9 @@ SQLcolumn "pattern" {type = "String"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -5900,6 +5911,9 @@ SQLcolumn "pattern" {type = "String"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -5914,7 +5928,8 @@ SQL}table "logs_volume_buckets" {- order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text"]+ primary_key = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text"]+ order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "internal_source"]partition_by = "toDate(time_bucket)"ttl = "time_bucket + toIntervalDay(greatest(42, retention_days))"settings = {@@ -5940,6 +5955,9 @@ SQLcolumn "severity_text" {type = "LowCardinality(String)"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -5972,6 +5990,9 @@ SQLcolumn "severity_text" {type = "LowCardinality(String)"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -17789,6 +17810,10 @@ SQLcolumn "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ default = "''"+ }engine "distributed" {cluster_name = "posthog_single_shard"remote_database = "posthog"@@ -21491,7 +21516,8 @@ SELECTtoInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) / _record_count AS _bytes_uncompressed,toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) / _record_count AS _bytes_compressed,ifNull(pattern, '') AS pattern,- toUInt8(ifNull(pattern_version, 0)) AS pattern_version+ toUInt8(ifNull(pattern_version, 0)) AS pattern_version,+ _headers.value[indexOf(_headers.name, 'internal-source')] AS internal_sourceFROM posthog.kafka_logs_avroSQL@@ -21567,6 +21593,9 @@ SQLcolumn "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }}materialized_view "kafka_logs_avro_billing_metrics_mv" {@@ -22244,6 +22273,7 @@ SELECTseverity_text,pattern_version,pattern,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -22269,6 +22299,7 @@ FROMlower(severity_text) AS severity_text,pattern_version,pattern,+ internal_source,toUInt16(least(intDiv(@@ -22283,7 +22314,7 @@ FROMWHERE pattern_version != 0)GROUP BY- team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern+ team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern, internal_sourceSQLcolumn "team_id" {@@ -22310,6 +22341,9 @@ SQLcolumn "pattern" {type = "String"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -22394,6 +22428,7 @@ SELECTnamespace,environment,severity_text,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -22417,6 +22452,7 @@ FROM)) AS environment,lower(severity_text) AS severity_text,+ internal_source,toUInt16(least(intDiv(@@ -22430,7 +22466,7 @@ FROMFROM posthog.logs34)GROUP BY- team_id, time_bucket, service_name, namespace, environment, severity_text+ team_id, time_bucket, service_name, namespace, environment, severity_text, internal_sourceSQLcolumn "team_id" {@@ -22451,6 +22487,9 @@ SQLcolumn "severity_text" {type = "LowCardinality(String)"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}diff --git a/posthog/clickhouse/hcl/golden/prod-eu/apm.hcl b/posthog/clickhouse/hcl/golden/prod-eu/apm.hclindex 4341625ce848..b595d93c9a8d 100644--- a/posthog/clickhouse/hcl/golden/prod-eu/apm.hcl+++ b/posthog/clickhouse/hcl/golden/prod-eu/apm.hcl@@ -351,6 +351,10 @@ database "posthog" {column "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ default = "''"+ }engine "distributed" {cluster_name = "logs"remote_database = "posthog"@@ -945,7 +949,8 @@ SELECTtoInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) / _record_count AS _bytes_uncompressed,toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) / _record_count AS _bytes_compressed,ifNull(pattern, '') AS pattern,- toUInt8(ifNull(pattern_version, 0)) AS pattern_version+ toUInt8(ifNull(pattern_version, 0)) AS pattern_version,+ _headers.value[indexOf(_headers.name, 'internal-source')] AS internal_sourceFROM posthog.kafka_logs_avroSQL@@ -1021,6 +1026,9 @@ SQLcolumn "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }}materialized_view "kafka_metrics_avro4_mv" {diff --git a/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl b/posthog/clickhouse/hcl/golden/prod-eu/logs.hclindex 17650a75127f..1bc44a9dfe47 100644--- a/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl+++ b/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl@@ -381,6 +381,10 @@ database "posthog" {column "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ default = "''"+ }index "idx_severity_text_set" {expr = "severity_text"type = "set(10)"@@ -609,6 +613,10 @@ SQLcolumn "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ default = "''"+ }engine "distributed" {cluster_name = "logs"remote_database = "posthog"@@ -680,7 +688,7 @@ SQLtable "logs_pattern_buckets" {primary_key = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "pattern_version"]- order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "pattern_version", "pattern"]+ order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "pattern_version", "pattern", "internal_source"]partition_by = "toDate(time_bucket)"ttl = "time_bucket + toIntervalDay(greatest(42, retention_days))"settings = {@@ -712,6 +720,9 @@ SQLcolumn "pattern" {type = "String"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -750,6 +761,9 @@ SQLcolumn "pattern" {type = "String"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -764,7 +778,8 @@ SQL}table "logs_volume_buckets" {- order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text"]+ primary_key = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text"]+ order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "internal_source"]partition_by = "toDate(time_bucket)"ttl = "time_bucket + toIntervalDay(greatest(42, retention_days))"settings = {@@ -790,6 +805,9 @@ SQLcolumn "severity_text" {type = "LowCardinality(String)"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -822,6 +840,9 @@ SQLcolumn "severity_text" {type = "LowCardinality(String)"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -3932,6 +3953,7 @@ SELECTseverity_text,pattern_version,pattern,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -3957,6 +3979,7 @@ FROMlower(severity_text) AS severity_text,pattern_version,pattern,+ internal_source,toUInt16(least(intDiv(@@ -3971,7 +3994,7 @@ FROMWHERE pattern_version != 0)GROUP BY- team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern+ team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern, internal_sourceSQLcolumn "team_id" {@@ -3998,6 +4021,9 @@ SQLcolumn "pattern" {type = "String"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -4082,6 +4108,7 @@ SELECTnamespace,environment,severity_text,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -4105,6 +4132,7 @@ FROM)) AS environment,lower(severity_text) AS severity_text,+ internal_source,toUInt16(least(intDiv(@@ -4118,7 +4146,7 @@ FROMFROM posthog.logs34)GROUP BY- team_id, time_bucket, service_name, namespace, environment, severity_text+ team_id, time_bucket, service_name, namespace, environment, severity_text, internal_sourceSQLcolumn "team_id" {@@ -4139,6 +4167,9 @@ SQLcolumn "severity_text" {type = "LowCardinality(String)"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}diff --git a/posthog/clickhouse/hcl/golden/prod-us/apm.hcl b/posthog/clickhouse/hcl/golden/prod-us/apm.hclindex 4341625ce848..b595d93c9a8d 100644--- a/posthog/clickhouse/hcl/golden/prod-us/apm.hcl+++ b/posthog/clickhouse/hcl/golden/prod-us/apm.hcl@@ -351,6 +351,10 @@ database "posthog" {column "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ default = "''"+ }engine "distributed" {cluster_name = "logs"remote_database = "posthog"@@ -945,7 +949,8 @@ SELECTtoInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) / _record_count AS _bytes_uncompressed,toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) / _record_count AS _bytes_compressed,ifNull(pattern, '') AS pattern,- toUInt8(ifNull(pattern_version, 0)) AS pattern_version+ toUInt8(ifNull(pattern_version, 0)) AS pattern_version,+ _headers.value[indexOf(_headers.name, 'internal-source')] AS internal_sourceFROM posthog.kafka_logs_avroSQL@@ -1021,6 +1026,9 @@ SQLcolumn "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }}materialized_view "kafka_metrics_avro4_mv" {diff --git a/posthog/clickhouse/hcl/golden/prod-us/logs.hcl b/posthog/clickhouse/hcl/golden/prod-us/logs.hclindex 4a90e5345f67..1dbbce442320 100644--- a/posthog/clickhouse/hcl/golden/prod-us/logs.hcl+++ b/posthog/clickhouse/hcl/golden/prod-us/logs.hcl@@ -381,6 +381,10 @@ database "posthog" {column "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ default = "''"+ }index "idx_severity_text_set" {expr = "severity_text"type = "set(10)"@@ -609,6 +613,10 @@ SQLcolumn "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ default = "''"+ }engine "distributed" {cluster_name = "logs"remote_database = "posthog"@@ -680,7 +688,7 @@ SQLtable "logs_pattern_buckets" {primary_key = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "pattern_version"]- order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "pattern_version", "pattern"]+ order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "pattern_version", "pattern", "internal_source"]partition_by = "toDate(time_bucket)"ttl = "time_bucket + toIntervalDay(greatest(42, retention_days))"settings = {@@ -712,6 +720,9 @@ SQLcolumn "pattern" {type = "String"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -750,6 +761,9 @@ SQLcolumn "pattern" {type = "String"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -764,7 +778,8 @@ SQL}table "logs_volume_buckets" {- order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text"]+ primary_key = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text"]+ order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "internal_source"]partition_by = "toDate(time_bucket)"ttl = "time_bucket + toIntervalDay(greatest(42, retention_days))"settings = {@@ -790,6 +805,9 @@ SQLcolumn "severity_text" {type = "LowCardinality(String)"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -822,6 +840,9 @@ SQLcolumn "severity_text" {type = "LowCardinality(String)"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -3914,6 +3935,7 @@ SELECTseverity_text,pattern_version,pattern,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -3939,6 +3961,7 @@ FROMlower(severity_text) AS severity_text,pattern_version,pattern,+ internal_source,toUInt16(least(intDiv(@@ -3953,7 +3976,7 @@ FROMWHERE pattern_version != 0)GROUP BY- team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern+ team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern, internal_sourceSQLcolumn "team_id" {@@ -3980,6 +4003,9 @@ SQLcolumn "pattern" {type = "String"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -4064,6 +4090,7 @@ SELECTnamespace,environment,severity_text,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -4087,6 +4114,7 @@ FROM)) AS environment,lower(severity_text) AS severity_text,+ internal_source,toUInt16(least(intDiv(@@ -4100,7 +4128,7 @@ FROMFROM posthog.logs34)GROUP BY- team_id, time_bucket, service_name, namespace, environment, severity_text+ team_id, time_bucket, service_name, namespace, environment, severity_text, internal_sourceSQLcolumn "team_id" {@@ -4121,6 +4149,9 @@ SQLcolumn "severity_text" {type = "LowCardinality(String)"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}diff --git a/posthog/clickhouse/hcl/roles/coshared/logs_avro_ingest/sql/kafka_logs34_avro_mv.sql b/posthog/clickhouse/hcl/roles/coshared/logs_avro_ingest/sql/kafka_logs34_avro_mv.sqlindex 5ce53c50ad30..9748885f3e46 100644--- a/posthog/clickhouse/hcl/roles/coshared/logs_avro_ingest/sql/kafka_logs34_avro_mv.sql+++ b/posthog/clickhouse/hcl/roles/coshared/logs_avro_ingest/sql/kafka_logs34_avro_mv.sql@@ -29,5 +29,6 @@ SELECTtoInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) / _record_count AS _bytes_uncompressed,toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) / _record_count AS _bytes_compressed,ifNull(pattern, '') AS pattern,- toUInt8(ifNull(pattern_version, 0)) AS pattern_version+ toUInt8(ifNull(pattern_version, 0)) AS pattern_version,+ _headers.value[indexOf(_headers.name, 'internal-source')] AS internal_sourceFROM posthog.kafka_logs_avrodiff --git a/posthog/clickhouse/hcl/roles/coshared/logs_avro_ingest/tables.hcl b/posthog/clickhouse/hcl/roles/coshared/logs_avro_ingest/tables.hclindex 8dcda1fa9318..ebebbd43240f 100644--- a/posthog/clickhouse/hcl/roles/coshared/logs_avro_ingest/tables.hcl+++ b/posthog/clickhouse/hcl/roles/coshared/logs_avro_ingest/tables.hcl@@ -144,6 +144,9 @@ database "posthog" {column "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }}table "writable_logs34" {@@ -256,6 +259,10 @@ database "posthog" {column "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ default = "''"+ }settings = {background_insert_batch = "1"}diff --git a/posthog/clickhouse/hcl/roles/logs/base/sql/logs34_to_pattern_buckets.sql b/posthog/clickhouse/hcl/roles/logs/base/sql/logs34_to_pattern_buckets.sqlindex 2a7104bb2715..8463dfb9a83e 100644--- a/posthog/clickhouse/hcl/roles/logs/base/sql/logs34_to_pattern_buckets.sql+++ b/posthog/clickhouse/hcl/roles/logs/base/sql/logs34_to_pattern_buckets.sql@@ -7,6 +7,7 @@ SELECTseverity_text,pattern_version,pattern,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -32,6 +33,7 @@ FROMlower(severity_text) AS severity_text,pattern_version,pattern,+ internal_source,toUInt16(least(intDiv(@@ -45,4 +47,4 @@ FROMWHERE pattern_version != 0)GROUP BY- team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern+ team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern, internal_sourcediff --git a/posthog/clickhouse/hcl/roles/logs/base/sql/logs34_to_volume_buckets.sql b/posthog/clickhouse/hcl/roles/logs/base/sql/logs34_to_volume_buckets.sqlindex 7a8579665cbf..5a1052302138 100644--- a/posthog/clickhouse/hcl/roles/logs/base/sql/logs34_to_volume_buckets.sql+++ b/posthog/clickhouse/hcl/roles/logs/base/sql/logs34_to_volume_buckets.sql@@ -5,6 +5,7 @@ SELECTnamespace,environment,severity_text,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -28,6 +29,7 @@ FROM)) AS environment,lower(severity_text) AS severity_text,+ internal_source,toUInt16(least(intDiv(@@ -40,4 +42,4 @@ FROMFROM posthog.logs34)GROUP BY- team_id, time_bucket, service_name, namespace, environment, severity_text+ team_id, time_bucket, service_name, namespace, environment, severity_text, internal_sourcediff --git a/posthog/clickhouse/hcl/roles/logs/base/tables.hcl b/posthog/clickhouse/hcl/roles/logs/base/tables.hclindex a92b40d263e8..7bffcfd19f0f 100644--- a/posthog/clickhouse/hcl/roles/logs/base/tables.hcl+++ b/posthog/clickhouse/hcl/roles/logs/base/tables.hcl@@ -193,6 +193,9 @@ database "posthog" {column "severity_text" {type = "LowCardinality(String)"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -229,6 +232,9 @@ database "posthog" {column "pattern" {type = "String"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -631,6 +637,10 @@ database "posthog" {column "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ default = "''"+ }engine "distributed" {cluster_name = "posthog_single_shard"remote_database = "posthog"@@ -700,7 +710,8 @@ database "posthog" {}table "logs_volume_buckets" {- order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text"]+ order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "internal_source"]+ primary_key = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text"]partition_by = "toDate(time_bucket)"ttl = "time_bucket + toIntervalDay(greatest(42, retention_days))"settings = {@@ -726,6 +737,9 @@ database "posthog" {column "severity_text" {type = "LowCardinality(String)"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -758,6 +772,9 @@ database "posthog" {column "severity_text" {type = "LowCardinality(String)"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -772,7 +789,7 @@ database "posthog" {}table "logs_pattern_buckets" {- order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "pattern_version", "pattern"]+ order_by = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "pattern_version", "pattern", "internal_source"]primary_key = ["team_id", "time_bucket", "service_name", "namespace", "environment", "severity_text", "pattern_version"]partition_by = "toDate(time_bucket)"ttl = "time_bucket + toIntervalDay(greatest(42, retention_days))"@@ -805,6 +822,9 @@ database "posthog" {column "pattern" {type = "String"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -843,6 +863,9 @@ database "posthog" {column "pattern" {type = "String"}+ column "internal_source" {+ type = "LowCardinality(String)"+ }column "retention_days" {type = "SimpleAggregateFunction(max, UInt16)"}@@ -1066,6 +1089,10 @@ database "posthog" {column "pattern_version" {type = "UInt8"}+ column "internal_source" {+ type = "LowCardinality(String)"+ default = "''"+ }index "idx_severity_text_set" {expr = "severity_text"type = "set(10)"diff --git a/posthog/clickhouse/hcl/sql/dev/apm.sql b/posthog/clickhouse/hcl/sql/dev/apm.sqlindex 6bb81959a5ca..cb2ba552e502 100644--- a/posthog/clickhouse/hcl/sql/dev/apm.sql+++ b/posthog/clickhouse/hcl/sql/dev/apm.sql@@ -130,7 +130,8 @@ CREATE TABLE posthog.writable_logs34 (_bytes_compressed UInt64,_record_count UInt64,pattern String,- pattern_version UInt8+ pattern_version UInt8,+ internal_source LowCardinality(String) DEFAULT '') ENGINE = Distributed('logs', 'posthog', 'logs34') SETTINGS background_insert_batch = 1;CREATE TABLE posthog.writable_metric_samples1 (team_id Int32,@@ -414,7 +415,7 @@ CREATE TABLE posthog.writable_trace_spans (_bytes_compressed UInt64,_record_count UInt64) ENGINE = Distributed('logs', 'posthog', 'trace_spans');-CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34 (uuid String, trace_id String, span_id String, trace_flags Int32, timestamp DateTime64(6), observed_timestamp DateTime64(6), body String, severity_text String, severity_number Int32, service_name String, instrumentation_scope String, event_name String, attributes_map_str Map(String, String), resource_attributes Map(String, String), team_id Int32, original_expiry_timestamp Nullable(DateTime64(6)), _partition UInt64, _topic LowCardinality(String), _offset UInt64, _record_count Int64, _bytes_uncompressed Nullable(Float64), _bytes_compressed Nullable(Float64), pattern String, pattern_version UInt8) AS SELECT+CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34 (uuid String, trace_id String, span_id String, trace_flags Int32, timestamp DateTime64(6), observed_timestamp DateTime64(6), body String, severity_text String, severity_number Int32, service_name String, instrumentation_scope String, event_name String, attributes_map_str Map(String, String), resource_attributes Map(String, String), team_id Int32, original_expiry_timestamp Nullable(DateTime64(6)), _partition UInt64, _topic LowCardinality(String), _offset UInt64, _record_count Int64, _bytes_uncompressed Nullable(Float64), _bytes_compressed Nullable(Float64), pattern String, pattern_version UInt8, internal_source LowCardinality(String)) AS SELECTuuid,trace_id,span_id,@@ -445,7 +446,8 @@ CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) / _record_count AS _bytes_uncompressed,toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) / _record_count AS _bytes_compressed,ifNull(pattern, '') AS pattern,- toUInt8(ifNull(pattern_version, 0)) AS pattern_version+ toUInt8(ifNull(pattern_version, 0)) AS pattern_version,+ _headers.value[indexOf(_headers.name, 'internal-source')] AS internal_sourceFROM posthog.kafka_logs_avro;CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro4_mv TO posthog.metrics4_input (uuid String, team_id Int32, metric_name String, series_fingerprint UInt64, resource_fingerprint UInt64, timestamp DateTime64(6), observed_timestamp DateTime64(6), original_expiry_timestamp DateTime64(6), service_name String, metric_type String, value Float64, count UInt64, histogram_bounds Array(Float64), histogram_counts Array(UInt64), trace_id String, span_id String, trace_flags Int32, has_labels Bool, unit String, aggregation_temporality String, is_monotonic UInt8, instrumentation_scope String, resource_attributes Map(String, String), attributes Map(String, String), _partition UInt64, _topic LowCardinality(String), _offset UInt64) AS SELECTuuid,diff --git a/posthog/clickhouse/hcl/sql/dev/logs.sql b/posthog/clickhouse/hcl/sql/dev/logs.sqlindex d790e324e9e7..37f86bd49800 100644--- a/posthog/clickhouse/hcl/sql/dev/logs.sql+++ b/posthog/clickhouse/hcl/sql/dev/logs.sql@@ -78,6 +78,7 @@ CREATE TABLE posthog.logs34 (_record_count UInt64,pattern String,pattern_version UInt8,+ internal_source LowCardinality(String) DEFAULT '',INDEX idx_severity_text_set severity_text TYPE set(10) GRANULARITY 1,INDEX idx_attributes_str_keys mapKeys(attributes_map_str) TYPE bloom_filter(0.01) GRANULARITY 1,INDEX idx_attributes_str_values mapValues(attributes_map_str) TYPE bloom_filter(0.001) GRANULARITY 1,@@ -146,7 +147,8 @@ CREATE TABLE posthog.logs_distributed (_bytes_compressed UInt64,_record_count UInt64,pattern String,- pattern_version UInt8+ pattern_version UInt8,+ internal_source LowCardinality(String) DEFAULT '') ENGINE = Distributed('logs', 'posthog', 'logs34');CREATE TABLE posthog.logs_kafka_metrics (_partition UInt32,@@ -175,9 +177,10 @@ CREATE TABLE posthog.logs_pattern_buckets (severity_text LowCardinality(String),pattern_version UInt8,pattern String,+ internal_source LowCardinality(String),retention_days SimpleAggregateFunction(max, UInt16),log_count SimpleAggregateFunction(sum, UInt64)-) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.logs_pattern_buckets', '{replica}-{shard}') PRIMARY KEY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version) ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(greatest(42, retention_days)) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0;+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.logs_pattern_buckets', '{replica}-{shard}') PRIMARY KEY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version) ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern, internal_source) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(greatest(42, retention_days)) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0;CREATE TABLE posthog.logs_pattern_buckets_distributed (team_id Int32,time_bucket DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),@@ -187,6 +190,7 @@ CREATE TABLE posthog.logs_pattern_buckets_distributed (severity_text LowCardinality(String),pattern_version UInt8,pattern String,+ internal_source LowCardinality(String),retention_days SimpleAggregateFunction(max, UInt16),log_count SimpleAggregateFunction(sum, UInt64)) ENGINE = Distributed('logs', 'posthog', 'logs_pattern_buckets');@@ -197,9 +201,10 @@ CREATE TABLE posthog.logs_volume_buckets (namespace LowCardinality(String),environment LowCardinality(String),severity_text LowCardinality(String),+ internal_source LowCardinality(String),retention_days SimpleAggregateFunction(max, UInt16),log_count SimpleAggregateFunction(sum, UInt64)-) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.logs_volume_buckets', '{replica}-{shard}') ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(greatest(42, retention_days)) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0;+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.logs_volume_buckets', '{replica}-{shard}') PRIMARY KEY (team_id, time_bucket, service_name, namespace, environment, severity_text) ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, internal_source) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(greatest(42, retention_days)) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0;CREATE TABLE posthog.logs_volume_buckets_distributed (team_id Int32,time_bucket DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),@@ -207,6 +212,7 @@ CREATE TABLE posthog.logs_volume_buckets_distributed (namespace LowCardinality(String),environment LowCardinality(String),severity_text LowCardinality(String),+ internal_source LowCardinality(String),retention_days SimpleAggregateFunction(max, UInt16),log_count SimpleAggregateFunction(sum, UInt64)) ENGINE = Distributed('logs', 'posthog', 'logs_volume_buckets');@@ -1035,7 +1041,7 @@ FROMGROUP BYteam_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, attributes);-CREATE MATERIALIZED VIEW posthog.logs34_to_pattern_buckets TO posthog.logs_pattern_buckets (team_id Int32, time_bucket DateTime('UTC'), service_name LowCardinality(String), namespace LowCardinality(String), environment LowCardinality(String), severity_text LowCardinality(String), pattern_version UInt8, pattern String, retention_days SimpleAggregateFunction(max, UInt16), log_count SimpleAggregateFunction(sum, UInt64)) AS SELECT+CREATE MATERIALIZED VIEW posthog.logs34_to_pattern_buckets TO posthog.logs_pattern_buckets (team_id Int32, time_bucket DateTime('UTC'), service_name LowCardinality(String), namespace LowCardinality(String), environment LowCardinality(String), severity_text LowCardinality(String), pattern_version UInt8, pattern String, internal_source LowCardinality(String), retention_days SimpleAggregateFunction(max, UInt16), log_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,time_bucket,service_name,@@ -1044,6 +1050,7 @@ CREATE MATERIALIZED VIEW posthog.logs34_to_pattern_buckets TO posthog.logs_patteseverity_text,pattern_version,pattern,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -1069,6 +1076,7 @@ FROMlower(severity_text) AS severity_text,pattern_version,pattern,+ internal_source,toUInt16(least(intDiv(@@ -1083,7 +1091,7 @@ FROMWHERE pattern_version != 0)GROUP BY- team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern;+ team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern, internal_source;CREATE MATERIALIZED VIEW posthog.logs34_to_resource_attributes3 TO posthog.log_attributes3 (team_id Int32, time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), resource_fingerprint UInt64, attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), severity_text LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,time_bucket,@@ -1113,13 +1121,14 @@ FROMGROUP BYteam_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, resource_attributes);-CREATE MATERIALIZED VIEW posthog.logs34_to_volume_buckets TO posthog.logs_volume_buckets (team_id Int32, time_bucket DateTime('UTC'), service_name LowCardinality(String), namespace LowCardinality(String), environment LowCardinality(String), severity_text LowCardinality(String), retention_days SimpleAggregateFunction(max, UInt16), log_count SimpleAggregateFunction(sum, UInt64)) AS SELECT+CREATE MATERIALIZED VIEW posthog.logs34_to_volume_buckets TO posthog.logs_volume_buckets (team_id Int32, time_bucket DateTime('UTC'), service_name LowCardinality(String), namespace LowCardinality(String), environment LowCardinality(String), severity_text LowCardinality(String), internal_source LowCardinality(String), retention_days SimpleAggregateFunction(max, UInt16), log_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,time_bucket,service_name,namespace,environment,severity_text,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -1143,6 +1152,7 @@ FROM)) AS environment,lower(severity_text) AS severity_text,+ internal_source,toUInt16(least(intDiv(@@ -1156,7 +1166,7 @@ FROMFROM posthog.logs34)GROUP BY- team_id, time_bucket, service_name, namespace, environment, severity_text;+ team_id, time_bucket, service_name, namespace, environment, severity_text, internal_source;CREATE MATERIALIZED VIEW posthog.ops_query_log_archive_v3_mv TO posthog.writable_query_log_archive_v3 (initial_query_start_time DateTime64(6, 'UTC'), team_id Int64, initial_query_id String, is_initial_query SimpleAggregateFunction(max, UInt8), hostname SimpleAggregateFunction(max, LowCardinality(String)), user SimpleAggregateFunction(max, LowCardinality(String)), type SimpleAggregateFunction(max, Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)), event_time_microseconds SimpleAggregateFunction(max, DateTime64(6, 'UTC')), query_duration_ms SimpleAggregateFunction(max, UInt64), read_rows SimpleAggregateFunction(sum, UInt64), read_bytes SimpleAggregateFunction(sum, UInt64), written_rows SimpleAggregateFunction(sum, UInt64), written_bytes SimpleAggregateFunction(sum, UInt64), result_rows SimpleAggregateFunction(sum, UInt64), result_bytes SimpleAggregateFunction(sum, UInt64), memory_usage SimpleAggregateFunction(max, UInt64), memory_usage_sum SimpleAggregateFunction(sum, UInt64), peak_threads_usage SimpleAggregateFunction(sum, UInt64), execution_count SimpleAggregateFunction(sum, UInt64), current_database SimpleAggregateFunction(max, LowCardinality(String)), query SimpleAggregateFunction(max, String), normalized_query_hash SimpleAggregateFunction(max, UInt64), query_kind_by_root SimpleAggregateFunction(max, Tuple(UInt8, String)), tables SimpleAggregateFunction(max, Array(String)), exception_code SimpleAggregateFunction(max, Int32), exception SimpleAggregateFunction(max, String), stack_trace SimpleAggregateFunction(max, String), ProfileEvents_SelectedRows SimpleAggregateFunction(sum, UInt64), ProfileEvents_SelectedBytes SimpleAggregateFunction(sum, UInt64), ProfileEvents_RealTimeMicroseconds SimpleAggregateFunction(sum, UInt64), ProfileEvents_OSCPUVirtualTimeMicroseconds SimpleAggregateFunction(sum, UInt64), ProfileEvents_UserTimeMicroseconds SimpleAggregateFunction(sum, UInt64), ProfileEvents_SystemTimeMicroseconds SimpleAggregateFunction(sum, UInt64), ProfileEvents_SelectedParts SimpleAggregateFunction(sum, UInt64), ProfileEvents_SelectedMarks SimpleAggregateFunction(sum, UInt64), ProfileEvents_NetworkReceiveBytes SimpleAggregateFunction(sum, UInt64), ProfileEvents_NetworkSendBytes SimpleAggregateFunction(sum, UInt64), ProfileEvents_ReadBufferFromFileDescriptorReadBytes SimpleAggregateFunction(sum, UInt64), ProfileEvents_WriteBufferFromFileDescriptorWriteBytes SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3Clients SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3DeleteObjects SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3CopyObject SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3ListObjects SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3HeadObject SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3GetObjectAttributes SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3CreateMultipartUpload SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3UploadPartCopy SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3UploadPart SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3AbortMultipartUpload SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3CompleteMultipartUpload SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3PutObject SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3GetObject SimpleAggregateFunction(sum, UInt64), ProfileEvents_ReadBufferFromS3Bytes SimpleAggregateFunction(sum, UInt64), ProfileEvents_WriteBufferFromS3Bytes SimpleAggregateFunction(sum, UInt64), lc_org_id SimpleAggregateFunction(max, String), lc_user_id SimpleAggregateFunction(max, Int64), lc_session_id SimpleAggregateFunction(max, String), lc_is_impersonated SimpleAggregateFunction(max, Bool), lc_workflow SimpleAggregateFunction(max, LowCardinality(String)), lc_kind SimpleAggregateFunction(max, LowCardinality(String)), lc_id SimpleAggregateFunction(max, String), lc_route_id SimpleAggregateFunction(max, String), lc_access_method SimpleAggregateFunction(max, LowCardinality(String)), lc_api_key_label SimpleAggregateFunction(max, String), lc_api_key_mask SimpleAggregateFunction(max, String), lc_query_type SimpleAggregateFunction(max, LowCardinality(String)), lc_product SimpleAggregateFunction(max, LowCardinality(String)), lc_chargeable SimpleAggregateFunction(max, Bool), lc_name SimpleAggregateFunction(max, String), lc_request_name SimpleAggregateFunction(max, String), lc_client_query_id SimpleAggregateFunction(max, String), lc_dashboard_id SimpleAggregateFunction(max, Int64), lc_insight_id SimpleAggregateFunction(max, Int64), lc_cohort_id SimpleAggregateFunction(max, Int64), lc_batch_export_id SimpleAggregateFunction(max, String), lc_experiment_id SimpleAggregateFunction(max, Int64), lc_experiment_feature_flag_key SimpleAggregateFunction(max, String), lc_alert_config_id SimpleAggregateFunction(max, String), lc_feature SimpleAggregateFunction(max, LowCardinality(String)), lc_table_id SimpleAggregateFunction(max, String), lc_warehouse_query SimpleAggregateFunction(max, Bool), lc_person_on_events_mode SimpleAggregateFunction(max, LowCardinality(String)), lc_service_name SimpleAggregateFunction(max, LowCardinality(String)), lc_workload SimpleAggregateFunction(max, LowCardinality(String)), lc_query__kind SimpleAggregateFunction(max, LowCardinality(String)), lc_query__query SimpleAggregateFunction(max, String), lc_query SimpleAggregateFunction(max, String), lc_modifiers SimpleAggregateFunction(max, String), lc_temporal__workflow_namespace SimpleAggregateFunction(max, LowCardinality(String)), lc_temporal__workflow_type SimpleAggregateFunction(max, LowCardinality(String)), lc_temporal__workflow_id SimpleAggregateFunction(max, String), lc_temporal__workflow_run_id SimpleAggregateFunction(max, String), lc_temporal__activity_type SimpleAggregateFunction(max, LowCardinality(String)), lc_temporal__activity_id SimpleAggregateFunction(max, String), lc_temporal__attempt SimpleAggregateFunction(max, Int64), lc_dagster__job_name SimpleAggregateFunction(max, LowCardinality(String)), lc_dagster__run_id SimpleAggregateFunction(max, String), lc_dagster__owner SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_name SimpleAggregateFunction(max, String), lc_experiment_metric_name SimpleAggregateFunction(max, String), lc_experiment_execution_path SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_metric_type SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_funnel_order_type SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_exposures_path SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_metric_events_path SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_query_surface SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_precompute_table SimpleAggregateFunction(max, String), lc_experiment_query_group_id SimpleAggregateFunction(max, String), lc_experiment_precompute_skip_reason SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_scan_date_from SimpleAggregateFunction(max, String), lc_experiment_scan_date_to SimpleAggregateFunction(max, String), lc_precompute_window_start SimpleAggregateFunction(max, String), lc_precompute_window_end SimpleAggregateFunction(max, String), lc_plan_fingerprint SimpleAggregateFunction(max, String), lc_estimated_rows SimpleAggregateFunction(max, Int64), lc_estimated_bytes SimpleAggregateFunction(max, Int64)) AS WITHJSONExtract(ql.log_comment, 'Tuple(team_id Int64, org_id String, user_id Int64, session_id String, is_impersonated Bool, workflow String, kind String, id String, route_id String, access_method String, api_key_label String, api_key_mask String, query_type String, product String, chargeable Bool, name String, request_name String, client_query_id String, dashboard_id Int64, insight_id Int64, cohort_id Int64, batch_export_id String, experiment_id Int64, experiment_feature_flag_key String, alert_config_id String, feature String, table_id String, warehouse_query Bool, person_on_events_mode String, service_name String, workload String, experiment_name String, experiment_metric_name String, experiment_execution_path String, experiment_metric_type String, experiment_funnel_order_type String, experiment_exposures_path String, experiment_metric_events_path String, experiment_query_surface String, experiment_precompute_table String, experiment_query_group_id String, experiment_precompute_skip_reason String, experiment_scan_date_from String, experiment_scan_date_to String, precompute_window_start String, precompute_window_end String, plan_fingerprint String, estimated_rows Int64, estimated_bytes Int64, temporal Tuple(workflow_namespace String, workflow_type String, workflow_id String, workflow_run_id String, activity_type String, activity_id String, attempt Int64), dagster Tuple(job_name String, run_id String, tags Tuple(owner String)), query Tuple(kind String, query String, source Tuple(kind String, query String)))') AS lcSELECTdiff --git a/posthog/clickhouse/hcl/sql/local-multi/ingestion_events.sql b/posthog/clickhouse/hcl/sql/local-multi/ingestion_events.sqlindex ed350bba6ee2..e5f065cae3a9 100644--- a/posthog/clickhouse/hcl/sql/local-multi/ingestion_events.sql+++ b/posthog/clickhouse/hcl/sql/local-multi/ingestion_events.sql@@ -254,7 +254,8 @@ CREATE TABLE posthog.writable_logs34 (_bytes_compressed UInt64,_record_count UInt64,pattern String,- pattern_version UInt8+ pattern_version UInt8,+ internal_source LowCardinality(String) DEFAULT '') ENGINE = Distributed('logs', 'posthog', 'logs34') SETTINGS background_insert_batch = 1;CREATE MATERIALIZED VIEW posthog.events_json_table_mv TO posthog.writable_events_json (uuid UUID, event String, properties String, temporary_properties String, inserted_at DateTime64(3), timestamp DateTime64(6, 'UTC'), team_id Int64, distinct_id String, elements_chain String, created_at DateTime64(6, 'UTC'), person_id UUID, person_properties String, person_created_at DateTime64(3), group0_properties String, group1_properties String, group2_properties String, group3_properties String, group4_properties String, group0_created_at DateTime64(3), group1_created_at DateTime64(3), group2_created_at DateTime64(3), group3_created_at DateTime64(3), group4_created_at DateTime64(3), person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2), historical_migration Bool, captured_at DateTime64(6, 'UTC'), _timestamp Nullable(DateTime), _offset UInt64, _partition UInt64, consumer_breadcrumbs Array(String), total_event_size UInt32) AS SELECT*,@@ -316,7 +317,7 @@ FROMSETTINGSinput_format_try_infer_dates = 0,input_format_try_infer_datetimes = 0;-CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34 (uuid String, trace_id String, span_id String, trace_flags Int32, timestamp DateTime64(6), observed_timestamp DateTime64(6), body String, severity_text String, severity_number Int32, service_name String, instrumentation_scope String, event_name String, attributes_map_str Map(String, String), resource_attributes Map(String, String), team_id Int32, original_expiry_timestamp DateTime64(6), _partition UInt64, _topic LowCardinality(String), _offset UInt64, _record_count Int64, _bytes_uncompressed Nullable(Int64), _bytes_compressed Nullable(Int64), pattern String, pattern_version UInt8) AS SELECT+CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34 (uuid String, trace_id String, span_id String, trace_flags Int32, timestamp DateTime64(6), observed_timestamp DateTime64(6), body String, severity_text String, severity_number Int32, service_name String, instrumentation_scope String, event_name String, attributes_map_str Map(String, String), resource_attributes Map(String, String), team_id Int32, original_expiry_timestamp DateTime64(6), _partition UInt64, _topic LowCardinality(String), _offset UInt64, _record_count Int64, _bytes_uncompressed Nullable(Int64), _bytes_compressed Nullable(Int64), pattern String, pattern_version UInt8, internal_source LowCardinality(String)) AS SELECTuuid,trace_id,span_id,@@ -347,5 +348,6 @@ CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) / _record_count AS _bytes_uncompressed,toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) / _record_count AS _bytes_compressed,ifNull(pattern, '') AS pattern,- toUInt8(ifNull(pattern_version, 0)) AS pattern_version+ toUInt8(ifNull(pattern_version, 0)) AS pattern_version,+ _headers.value[indexOf(_headers.name, 'internal-source')] AS internal_sourceFROM posthog.kafka_logs_avro;diff --git a/posthog/clickhouse/hcl/sql/local-multi/logs.sql b/posthog/clickhouse/hcl/sql/local-multi/logs.sqlindex cca83e33972a..524eab6935b6 100644--- a/posthog/clickhouse/hcl/sql/local-multi/logs.sql+++ b/posthog/clickhouse/hcl/sql/local-multi/logs.sql@@ -170,6 +170,7 @@ CREATE TABLE posthog.logs34 (_record_count UInt64,pattern String,pattern_version UInt8,+ internal_source LowCardinality(String) DEFAULT '',INDEX idx_severity_text_set severity_text TYPE set(10) GRANULARITY 1,INDEX idx_attributes_str_keys mapKeys(attributes_map_str) TYPE bloom_filter(0.01) GRANULARITY 1,INDEX idx_attributes_str_values mapValues(attributes_map_str) TYPE bloom_filter(0.001) GRANULARITY 1,@@ -238,7 +239,8 @@ CREATE TABLE posthog.logs_distributed (_bytes_compressed UInt64,_record_count UInt64,pattern String,- pattern_version UInt8+ pattern_version UInt8,+ internal_source LowCardinality(String) DEFAULT '') ENGINE = Distributed('posthog_single_shard', 'posthog', 'logs34');CREATE TABLE posthog.logs_kafka_metrics (_partition UInt32,@@ -267,9 +269,10 @@ CREATE TABLE posthog.logs_pattern_buckets (severity_text LowCardinality(String),pattern_version UInt8,pattern String,+ internal_source LowCardinality(String),retention_days SimpleAggregateFunction(max, UInt16),log_count SimpleAggregateFunction(sum, UInt64)-) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.logs_pattern_buckets', '{replica}-{shard}') PRIMARY KEY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version) ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(greatest(42, retention_days)) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0;+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.logs_pattern_buckets', '{replica}-{shard}') PRIMARY KEY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version) ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern, internal_source) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(greatest(42, retention_days)) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0;CREATE TABLE posthog.logs_pattern_buckets_distributed (team_id Int32,time_bucket DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),@@ -279,6 +282,7 @@ CREATE TABLE posthog.logs_pattern_buckets_distributed (severity_text LowCardinality(String),pattern_version UInt8,pattern String,+ internal_source LowCardinality(String),retention_days SimpleAggregateFunction(max, UInt16),log_count SimpleAggregateFunction(sum, UInt64)) ENGINE = Distributed('posthog_single_shard', 'posthog', 'logs_pattern_buckets');@@ -289,9 +293,10 @@ CREATE TABLE posthog.logs_volume_buckets (namespace LowCardinality(String),environment LowCardinality(String),severity_text LowCardinality(String),+ internal_source LowCardinality(String),retention_days SimpleAggregateFunction(max, UInt16),log_count SimpleAggregateFunction(sum, UInt64)-) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.logs_volume_buckets', '{replica}-{shard}') ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(greatest(42, retention_days)) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0;+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.logs_volume_buckets', '{replica}-{shard}') PRIMARY KEY (team_id, time_bucket, service_name, namespace, environment, severity_text) ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, internal_source) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(greatest(42, retention_days)) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0;CREATE TABLE posthog.logs_volume_buckets_distributed (team_id Int32,time_bucket DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),@@ -299,6 +304,7 @@ CREATE TABLE posthog.logs_volume_buckets_distributed (namespace LowCardinality(String),environment LowCardinality(String),severity_text LowCardinality(String),+ internal_source LowCardinality(String),retention_days SimpleAggregateFunction(max, UInt16),log_count SimpleAggregateFunction(sum, UInt64)) ENGINE = Distributed('posthog_single_shard', 'posthog', 'logs_volume_buckets');@@ -1107,7 +1113,7 @@ FROMGROUP BYteam_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, attributes);-CREATE MATERIALIZED VIEW posthog.logs34_to_pattern_buckets TO posthog.logs_pattern_buckets (team_id Int32, time_bucket DateTime('UTC'), service_name LowCardinality(String), namespace LowCardinality(String), environment LowCardinality(String), severity_text LowCardinality(String), pattern_version UInt8, pattern String, retention_days SimpleAggregateFunction(max, UInt16), log_count SimpleAggregateFunction(sum, UInt64)) AS SELECT+CREATE MATERIALIZED VIEW posthog.logs34_to_pattern_buckets TO posthog.logs_pattern_buckets (team_id Int32, time_bucket DateTime('UTC'), service_name LowCardinality(String), namespace LowCardinality(String), environment LowCardinality(String), severity_text LowCardinality(String), pattern_version UInt8, pattern String, internal_source LowCardinality(String), retention_days SimpleAggregateFunction(max, UInt16), log_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,time_bucket,service_name,@@ -1116,6 +1122,7 @@ CREATE MATERIALIZED VIEW posthog.logs34_to_pattern_buckets TO posthog.logs_patteseverity_text,pattern_version,pattern,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -1141,6 +1148,7 @@ FROMlower(severity_text) AS severity_text,pattern_version,pattern,+ internal_source,toUInt16(least(intDiv(@@ -1155,7 +1163,7 @@ FROMWHERE pattern_version != 0)GROUP BY- team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern;+ team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern, internal_source;CREATE MATERIALIZED VIEW posthog.logs34_to_resource_attributes3 TO posthog.log_attributes3 (team_id Int32, time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), resource_fingerprint UInt64, attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), severity_text LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,time_bucket,@@ -1185,13 +1193,14 @@ FROMGROUP BYteam_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, resource_attributes);-CREATE MATERIALIZED VIEW posthog.logs34_to_volume_buckets TO posthog.logs_volume_buckets (team_id Int32, time_bucket DateTime('UTC'), service_name LowCardinality(String), namespace LowCardinality(String), environment LowCardinality(String), severity_text LowCardinality(String), retention_days SimpleAggregateFunction(max, UInt16), log_count SimpleAggregateFunction(sum, UInt64)) AS SELECT+CREATE MATERIALIZED VIEW posthog.logs34_to_volume_buckets TO posthog.logs_volume_buckets (team_id Int32, time_bucket DateTime('UTC'), service_name LowCardinality(String), namespace LowCardinality(String), environment LowCardinality(String), severity_text LowCardinality(String), internal_source LowCardinality(String), retention_days SimpleAggregateFunction(max, UInt16), log_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,time_bucket,service_name,namespace,environment,severity_text,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -1215,6 +1224,7 @@ FROM)) AS environment,lower(severity_text) AS severity_text,+ internal_source,toUInt16(least(intDiv(@@ -1228,7 +1238,7 @@ FROMFROM posthog.logs34)GROUP BY- team_id, time_bucket, service_name, namespace, environment, severity_text;+ team_id, time_bucket, service_name, namespace, environment, severity_text, internal_source;CREATE MATERIALIZED VIEW posthog.trace_span_to_attributes TO posthog.trace_attributes (team_id Int32, original_expiry_time_bucket DateTime64(0), time_bucket DateTime64(0), service_name LowCardinality(String), resource_fingerprint UInt64, attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,original_expiry_time_bucket,diff --git a/posthog/clickhouse/hcl/sql/local-single/all.sql b/posthog/clickhouse/hcl/sql/local-single/all.sqlindex a189b580f8d7..33578a6fa027 100644--- a/posthog/clickhouse/hcl/sql/local-single/all.sql+++ b/posthog/clickhouse/hcl/sql/local-single/all.sql@@ -1079,6 +1079,7 @@ CREATE TABLE posthog.logs34 (_record_count UInt64,pattern String,pattern_version UInt8,+ internal_source LowCardinality(String) DEFAULT '',INDEX idx_severity_text_set severity_text TYPE set(10) GRANULARITY 1,INDEX idx_attributes_str_keys mapKeys(attributes_map_str) TYPE bloom_filter(0.01) GRANULARITY 1,INDEX idx_attributes_str_values mapValues(attributes_map_str) TYPE bloom_filter(0.001) GRANULARITY 1,@@ -1147,7 +1148,8 @@ CREATE TABLE posthog.logs_distributed (_bytes_compressed UInt64,_record_count UInt64,pattern String,- pattern_version UInt8+ pattern_version UInt8,+ internal_source LowCardinality(String) DEFAULT '') ENGINE = Distributed('posthog_single_shard', 'posthog', 'logs34');CREATE TABLE posthog.logs_kafka_metrics (_partition UInt32,@@ -1176,9 +1178,10 @@ CREATE TABLE posthog.logs_pattern_buckets (severity_text LowCardinality(String),pattern_version UInt8,pattern String,+ internal_source LowCardinality(String),retention_days SimpleAggregateFunction(max, UInt16),log_count SimpleAggregateFunction(sum, UInt64)-) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.logs_pattern_buckets', '{replica}-{shard}') PRIMARY KEY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version) ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(greatest(42, retention_days)) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0;+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.logs_pattern_buckets', '{replica}-{shard}') PRIMARY KEY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version) ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern, internal_source) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(greatest(42, retention_days)) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0;CREATE TABLE posthog.logs_pattern_buckets_distributed (team_id Int32,time_bucket DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),@@ -1188,6 +1191,7 @@ CREATE TABLE posthog.logs_pattern_buckets_distributed (severity_text LowCardinality(String),pattern_version UInt8,pattern String,+ internal_source LowCardinality(String),retention_days SimpleAggregateFunction(max, UInt16),log_count SimpleAggregateFunction(sum, UInt64)) ENGINE = Distributed('posthog_single_shard', 'posthog', 'logs_pattern_buckets');@@ -1198,9 +1202,10 @@ CREATE TABLE posthog.logs_volume_buckets (namespace LowCardinality(String),environment LowCardinality(String),severity_text LowCardinality(String),+ internal_source LowCardinality(String),retention_days SimpleAggregateFunction(max, UInt16),log_count SimpleAggregateFunction(sum, UInt64)-) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.logs_volume_buckets', '{replica}-{shard}') ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(greatest(42, retention_days)) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0;+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.logs_volume_buckets', '{replica}-{shard}') PRIMARY KEY (team_id, time_bucket, service_name, namespace, environment, severity_text) ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, internal_source) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(greatest(42, retention_days)) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0;CREATE TABLE posthog.logs_volume_buckets_distributed (team_id Int32,time_bucket DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),@@ -1208,6 +1213,7 @@ CREATE TABLE posthog.logs_volume_buckets_distributed (namespace LowCardinality(String),environment LowCardinality(String),severity_text LowCardinality(String),+ internal_source LowCardinality(String),retention_days SimpleAggregateFunction(max, UInt16),log_count SimpleAggregateFunction(sum, UInt64)) ENGINE = Distributed('posthog_single_shard', 'posthog', 'logs_volume_buckets');@@ -3914,7 +3920,8 @@ CREATE TABLE posthog.writable_logs34 (_bytes_compressed UInt64,_record_count UInt64,pattern String,- pattern_version UInt8+ pattern_version UInt8,+ internal_source LowCardinality(String) DEFAULT '') ENGINE = Distributed('posthog_single_shard', 'posthog', 'logs34') SETTINGS background_insert_batch = 1;CREATE TABLE posthog.writable_metrics4_attributes (team_id Int32,@@ -4812,7 +4819,7 @@ CREATE MATERIALIZED VIEW posthog.ingestion_warnings_v2_mv TO posthog.ingestion_w_offset,_partitionFROM posthog.kafka_ingestion_warnings_v2;-CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34 (uuid String, trace_id String, span_id String, trace_flags Int32, timestamp DateTime64(6), observed_timestamp DateTime64(6), body String, severity_text String, severity_number Int32, service_name String, instrumentation_scope String, event_name String, attributes_map_str Map(String, String), resource_attributes Map(String, String), team_id Int32, original_expiry_timestamp DateTime64(6), _partition UInt64, _topic LowCardinality(String), _offset UInt64, _record_count Int64, _bytes_uncompressed Nullable(Int64), _bytes_compressed Nullable(Int64), pattern String, pattern_version UInt8) AS SELECT+CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34 (uuid String, trace_id String, span_id String, trace_flags Int32, timestamp DateTime64(6), observed_timestamp DateTime64(6), body String, severity_text String, severity_number Int32, service_name String, instrumentation_scope String, event_name String, attributes_map_str Map(String, String), resource_attributes Map(String, String), team_id Int32, original_expiry_timestamp DateTime64(6), _partition UInt64, _topic LowCardinality(String), _offset UInt64, _record_count Int64, _bytes_uncompressed Nullable(Int64), _bytes_compressed Nullable(Int64), pattern String, pattern_version UInt8, internal_source LowCardinality(String)) AS SELECTuuid,trace_id,span_id,@@ -4843,7 +4850,8 @@ CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) / _record_count AS _bytes_uncompressed,toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) / _record_count AS _bytes_compressed,ifNull(pattern, '') AS pattern,- toUInt8(ifNull(pattern_version, 0)) AS pattern_version+ toUInt8(ifNull(pattern_version, 0)) AS pattern_version,+ _headers.value[indexOf(_headers.name, 'internal-source')] AS internal_sourceFROM posthog.kafka_logs_avro;CREATE MATERIALIZED VIEW posthog.kafka_logs_avro_billing_metrics_mv TO posthog.logs_billing_metrics (team_id Int32, time_bucket DateTime, service_name LowCardinality(String), bytes_uncompressed SimpleAggregateFunction(sum, Float64), bytes_compressed SimpleAggregateFunction(sum, Float64), record_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,@@ -5084,7 +5092,7 @@ FROMGROUP BYteam_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, attributes);-CREATE MATERIALIZED VIEW posthog.logs34_to_pattern_buckets TO posthog.logs_pattern_buckets (team_id Int32, time_bucket DateTime('UTC'), service_name LowCardinality(String), namespace LowCardinality(String), environment LowCardinality(String), severity_text LowCardinality(String), pattern_version UInt8, pattern String, retention_days SimpleAggregateFunction(max, UInt16), log_count SimpleAggregateFunction(sum, UInt64)) AS SELECT+CREATE MATERIALIZED VIEW posthog.logs34_to_pattern_buckets TO posthog.logs_pattern_buckets (team_id Int32, time_bucket DateTime('UTC'), service_name LowCardinality(String), namespace LowCardinality(String), environment LowCardinality(String), severity_text LowCardinality(String), pattern_version UInt8, pattern String, internal_source LowCardinality(String), retention_days SimpleAggregateFunction(max, UInt16), log_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,time_bucket,service_name,@@ -5093,6 +5101,7 @@ CREATE MATERIALIZED VIEW posthog.logs34_to_pattern_buckets TO posthog.logs_patteseverity_text,pattern_version,pattern,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -5118,6 +5127,7 @@ FROMlower(severity_text) AS severity_text,pattern_version,pattern,+ internal_source,toUInt16(least(intDiv(@@ -5132,7 +5142,7 @@ FROMWHERE pattern_version != 0)GROUP BY- team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern;+ team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern, internal_source;CREATE MATERIALIZED VIEW posthog.logs34_to_resource_attributes3 TO posthog.log_attributes3 (team_id Int32, time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), resource_fingerprint UInt64, attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), severity_text LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,time_bucket,@@ -5162,13 +5172,14 @@ FROMGROUP BYteam_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, resource_attributes);-CREATE MATERIALIZED VIEW posthog.logs34_to_volume_buckets TO posthog.logs_volume_buckets (team_id Int32, time_bucket DateTime('UTC'), service_name LowCardinality(String), namespace LowCardinality(String), environment LowCardinality(String), severity_text LowCardinality(String), retention_days SimpleAggregateFunction(max, UInt16), log_count SimpleAggregateFunction(sum, UInt64)) AS SELECT+CREATE MATERIALIZED VIEW posthog.logs34_to_volume_buckets TO posthog.logs_volume_buckets (team_id Int32, time_bucket DateTime('UTC'), service_name LowCardinality(String), namespace LowCardinality(String), environment LowCardinality(String), severity_text LowCardinality(String), internal_source LowCardinality(String), retention_days SimpleAggregateFunction(max, UInt16), log_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,time_bucket,service_name,namespace,environment,severity_text,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -5192,6 +5203,7 @@ FROM)) AS environment,lower(severity_text) AS severity_text,+ internal_source,toUInt16(least(intDiv(@@ -5205,7 +5217,7 @@ FROMFROM posthog.logs34)GROUP BY- team_id, time_bucket, service_name, namespace, environment, severity_text;+ team_id, time_bucket, service_name, namespace, environment, severity_text, internal_source;CREATE MATERIALIZED VIEW posthog.message_assets_mv TO posthog.message_assets_data (team_id Int64, function_kind LowCardinality(String), function_id String, parent_run_id String, invocation_id String, action_id String, kind LowCardinality(String), distinct_id String, person_id String, recipient String, subject String, status LowCardinality(String), sent_at DateTime64(6, 'UTC'), version UInt64, is_deleted UInt8, html String, _timestamp Nullable(DateTime), _offset UInt64, _partition UInt64) AS SELECTteam_id,function_kind,diff --git a/posthog/clickhouse/hcl/sql/prod-eu/apm.sql b/posthog/clickhouse/hcl/sql/prod-eu/apm.sqlindex d68e4b981af1..5de4a6d7ba49 100644--- a/posthog/clickhouse/hcl/sql/prod-eu/apm.sql+++ b/posthog/clickhouse/hcl/sql/prod-eu/apm.sql@@ -106,7 +106,8 @@ CREATE TABLE posthog.writable_logs34 (_bytes_compressed UInt64,_record_count UInt64,pattern String,- pattern_version UInt8+ pattern_version UInt8,+ internal_source LowCardinality(String) DEFAULT '') ENGINE = Distributed('logs', 'posthog', 'logs34') SETTINGS background_insert_batch = 1;CREATE TABLE posthog.writable_metrics4_attributes (team_id Int32,@@ -288,7 +289,7 @@ CREATE TABLE posthog.writable_query_log_archive_v3 (lc_estimated_rows SimpleAggregateFunction(max, Int64),lc_estimated_bytes SimpleAggregateFunction(max, Int64)) ENGINE = Distributed('ops', 'posthog', 'query_log_archive_v3_buffer');-CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34 (uuid String, trace_id String, span_id String, trace_flags Int32, timestamp DateTime64(6), observed_timestamp DateTime64(6), body String, severity_text String, severity_number Int32, service_name String, instrumentation_scope String, event_name String, attributes_map_str Map(String, String), resource_attributes Map(String, String), team_id Int32, original_expiry_timestamp DateTime64(6), _partition UInt64, _topic LowCardinality(String), _offset UInt64, _record_count Int64, _bytes_uncompressed Nullable(Int64), _bytes_compressed Nullable(Int64), pattern String, pattern_version UInt8) AS SELECT+CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34 (uuid String, trace_id String, span_id String, trace_flags Int32, timestamp DateTime64(6), observed_timestamp DateTime64(6), body String, severity_text String, severity_number Int32, service_name String, instrumentation_scope String, event_name String, attributes_map_str Map(String, String), resource_attributes Map(String, String), team_id Int32, original_expiry_timestamp DateTime64(6), _partition UInt64, _topic LowCardinality(String), _offset UInt64, _record_count Int64, _bytes_uncompressed Nullable(Int64), _bytes_compressed Nullable(Int64), pattern String, pattern_version UInt8, internal_source LowCardinality(String)) AS SELECTuuid,trace_id,span_id,@@ -319,7 +320,8 @@ CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) / _record_count AS _bytes_uncompressed,toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) / _record_count AS _bytes_compressed,ifNull(pattern, '') AS pattern,- toUInt8(ifNull(pattern_version, 0)) AS pattern_version+ toUInt8(ifNull(pattern_version, 0)) AS pattern_version,+ _headers.value[indexOf(_headers.name, 'internal-source')] AS internal_sourceFROM posthog.kafka_logs_avro;CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro4_mv TO posthog.metrics4_input (uuid String, team_id Int32, metric_name String, series_fingerprint UInt64, resource_fingerprint UInt64, timestamp DateTime64(6), observed_timestamp DateTime64(6), original_expiry_timestamp DateTime64(6), service_name String, metric_type String, value Float64, count UInt64, histogram_bounds Array(Float64), histogram_counts Array(UInt64), trace_id String, span_id String, trace_flags Int32, has_labels Bool, unit String, aggregation_temporality String, is_monotonic UInt8, instrumentation_scope String, resource_attributes Map(String, String), attributes Map(String, String), _partition UInt64, _topic LowCardinality(String), _offset UInt64) AS SELECTuuid,diff --git a/posthog/clickhouse/hcl/sql/prod-eu/logs.sql b/posthog/clickhouse/hcl/sql/prod-eu/logs.sqlindex e099be2d4fef..677aca03d390 100644--- a/posthog/clickhouse/hcl/sql/prod-eu/logs.sql+++ b/posthog/clickhouse/hcl/sql/prod-eu/logs.sql@@ -102,6 +102,7 @@ CREATE TABLE posthog.logs34 (_record_count UInt64,pattern String,pattern_version UInt8,+ internal_source LowCardinality(String) DEFAULT '',INDEX idx_severity_text_set severity_text TYPE set(10) GRANULARITY 1,INDEX idx_attributes_str_keys mapKeys(attributes_map_str) TYPE bloom_filter(0.01) GRANULARITY 1,INDEX idx_attributes_str_values mapValues(attributes_map_str) TYPE bloom_filter(0.001) GRANULARITY 1,@@ -170,7 +171,8 @@ CREATE TABLE posthog.logs_distributed (_bytes_compressed UInt64,_record_count UInt64,pattern String,- pattern_version UInt8+ pattern_version UInt8,+ internal_source LowCardinality(String) DEFAULT '') ENGINE = Distributed('logs', 'posthog', 'logs34');CREATE TABLE posthog.logs_kafka_metrics (_partition UInt32,@@ -199,9 +201,10 @@ CREATE TABLE posthog.logs_pattern_buckets (severity_text LowCardinality(String),pattern_version UInt8,pattern String,+ internal_source LowCardinality(String),retention_days SimpleAggregateFunction(max, UInt16),log_count SimpleAggregateFunction(sum, UInt64)-) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.logs_pattern_buckets', '{replica}-{shard}') PRIMARY KEY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version) ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(greatest(42, retention_days)) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0;+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.logs_pattern_buckets', '{replica}-{shard}') PRIMARY KEY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version) ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern, internal_source) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(greatest(42, retention_days)) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0;CREATE TABLE posthog.logs_pattern_buckets_distributed (team_id Int32,time_bucket DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),@@ -211,6 +214,7 @@ CREATE TABLE posthog.logs_pattern_buckets_distributed (severity_text LowCardinality(String),pattern_version UInt8,pattern String,+ internal_source LowCardinality(String),retention_days SimpleAggregateFunction(max, UInt16),log_count SimpleAggregateFunction(sum, UInt64)) ENGINE = Distributed('logs', 'posthog', 'logs_pattern_buckets');@@ -221,9 +225,10 @@ CREATE TABLE posthog.logs_volume_buckets (namespace LowCardinality(String),environment LowCardinality(String),severity_text LowCardinality(String),+ internal_source LowCardinality(String),retention_days SimpleAggregateFunction(max, UInt16),log_count SimpleAggregateFunction(sum, UInt64)-) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.logs_volume_buckets', '{replica}-{shard}') ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(greatest(42, retention_days)) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0;+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.logs_volume_buckets', '{replica}-{shard}') PRIMARY KEY (team_id, time_bucket, service_name, namespace, environment, severity_text) ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, internal_source) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(greatest(42, retention_days)) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0;CREATE TABLE posthog.logs_volume_buckets_distributed (team_id Int32,time_bucket DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),@@ -231,6 +236,7 @@ CREATE TABLE posthog.logs_volume_buckets_distributed (namespace LowCardinality(String),environment LowCardinality(String),severity_text LowCardinality(String),+ internal_source LowCardinality(String),retention_days SimpleAggregateFunction(max, UInt16),log_count SimpleAggregateFunction(sum, UInt64)) ENGINE = Distributed('logs', 'posthog', 'logs_volume_buckets');@@ -1112,7 +1118,7 @@ FROMGROUP BYteam_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, attributes);-CREATE MATERIALIZED VIEW posthog.logs34_to_pattern_buckets TO posthog.logs_pattern_buckets (team_id Int32, time_bucket DateTime('UTC'), service_name LowCardinality(String), namespace LowCardinality(String), environment LowCardinality(String), severity_text LowCardinality(String), pattern_version UInt8, pattern String, retention_days SimpleAggregateFunction(max, UInt16), log_count SimpleAggregateFunction(sum, UInt64)) AS SELECT+CREATE MATERIALIZED VIEW posthog.logs34_to_pattern_buckets TO posthog.logs_pattern_buckets (team_id Int32, time_bucket DateTime('UTC'), service_name LowCardinality(String), namespace LowCardinality(String), environment LowCardinality(String), severity_text LowCardinality(String), pattern_version UInt8, pattern String, internal_source LowCardinality(String), retention_days SimpleAggregateFunction(max, UInt16), log_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,time_bucket,service_name,@@ -1121,6 +1127,7 @@ CREATE MATERIALIZED VIEW posthog.logs34_to_pattern_buckets TO posthog.logs_patteseverity_text,pattern_version,pattern,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -1146,6 +1153,7 @@ FROMlower(severity_text) AS severity_text,pattern_version,pattern,+ internal_source,toUInt16(least(intDiv(@@ -1160,7 +1168,7 @@ FROMWHERE pattern_version != 0)GROUP BY- team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern;+ team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern, internal_source;CREATE MATERIALIZED VIEW posthog.logs34_to_resource_attributes3 TO posthog.log_attributes3 (team_id Int32, time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), resource_fingerprint UInt64, attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), severity_text LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,time_bucket,@@ -1190,13 +1198,14 @@ FROMGROUP BYteam_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, resource_attributes);-CREATE MATERIALIZED VIEW posthog.logs34_to_volume_buckets TO posthog.logs_volume_buckets (team_id Int32, time_bucket DateTime('UTC'), service_name LowCardinality(String), namespace LowCardinality(String), environment LowCardinality(String), severity_text LowCardinality(String), retention_days SimpleAggregateFunction(max, UInt16), log_count SimpleAggregateFunction(sum, UInt64)) AS SELECT+CREATE MATERIALIZED VIEW posthog.logs34_to_volume_buckets TO posthog.logs_volume_buckets (team_id Int32, time_bucket DateTime('UTC'), service_name LowCardinality(String), namespace LowCardinality(String), environment LowCardinality(String), severity_text LowCardinality(String), internal_source LowCardinality(String), retention_days SimpleAggregateFunction(max, UInt16), log_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,time_bucket,service_name,namespace,environment,severity_text,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -1220,6 +1229,7 @@ FROM)) AS environment,lower(severity_text) AS severity_text,+ internal_source,toUInt16(least(intDiv(@@ -1233,7 +1243,7 @@ FROMFROM posthog.logs34)GROUP BY- team_id, time_bucket, service_name, namespace, environment, severity_text;+ team_id, time_bucket, service_name, namespace, environment, severity_text, internal_source;CREATE MATERIALIZED VIEW posthog.ops_query_log_archive_v3_mv TO posthog.writable_query_log_archive_v3 (initial_query_start_time DateTime64(6, 'UTC'), team_id Int64, initial_query_id String, is_initial_query SimpleAggregateFunction(max, UInt8), hostname SimpleAggregateFunction(max, LowCardinality(String)), user SimpleAggregateFunction(max, LowCardinality(String)), type SimpleAggregateFunction(max, Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)), event_time_microseconds SimpleAggregateFunction(max, DateTime64(6, 'UTC')), query_duration_ms SimpleAggregateFunction(max, UInt64), read_rows SimpleAggregateFunction(sum, UInt64), read_bytes SimpleAggregateFunction(sum, UInt64), written_rows SimpleAggregateFunction(sum, UInt64), written_bytes SimpleAggregateFunction(sum, UInt64), result_rows SimpleAggregateFunction(sum, UInt64), result_bytes SimpleAggregateFunction(sum, UInt64), memory_usage SimpleAggregateFunction(max, UInt64), memory_usage_sum SimpleAggregateFunction(sum, UInt64), peak_threads_usage SimpleAggregateFunction(sum, UInt64), execution_count SimpleAggregateFunction(sum, UInt64), current_database SimpleAggregateFunction(max, LowCardinality(String)), query SimpleAggregateFunction(max, String), normalized_query_hash SimpleAggregateFunction(max, UInt64), query_kind_by_root SimpleAggregateFunction(max, Tuple(UInt8, String)), tables SimpleAggregateFunction(max, Array(String)), exception_code SimpleAggregateFunction(max, Int32), exception SimpleAggregateFunction(max, String), stack_trace SimpleAggregateFunction(max, String), ProfileEvents_SelectedRows SimpleAggregateFunction(sum, UInt64), ProfileEvents_SelectedBytes SimpleAggregateFunction(sum, UInt64), ProfileEvents_RealTimeMicroseconds SimpleAggregateFunction(sum, UInt64), ProfileEvents_OSCPUVirtualTimeMicroseconds SimpleAggregateFunction(sum, UInt64), ProfileEvents_UserTimeMicroseconds SimpleAggregateFunction(sum, UInt64), ProfileEvents_SystemTimeMicroseconds SimpleAggregateFunction(sum, UInt64), ProfileEvents_SelectedParts SimpleAggregateFunction(sum, UInt64), ProfileEvents_SelectedMarks SimpleAggregateFunction(sum, UInt64), ProfileEvents_NetworkReceiveBytes SimpleAggregateFunction(sum, UInt64), ProfileEvents_NetworkSendBytes SimpleAggregateFunction(sum, UInt64), ProfileEvents_ReadBufferFromFileDescriptorReadBytes SimpleAggregateFunction(sum, UInt64), ProfileEvents_WriteBufferFromFileDescriptorWriteBytes SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3Clients SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3DeleteObjects SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3CopyObject SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3ListObjects SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3HeadObject SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3GetObjectAttributes SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3CreateMultipartUpload SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3UploadPartCopy SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3UploadPart SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3AbortMultipartUpload SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3CompleteMultipartUpload SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3PutObject SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3GetObject SimpleAggregateFunction(sum, UInt64), ProfileEvents_ReadBufferFromS3Bytes SimpleAggregateFunction(sum, UInt64), ProfileEvents_WriteBufferFromS3Bytes SimpleAggregateFunction(sum, UInt64), lc_org_id SimpleAggregateFunction(max, String), lc_user_id SimpleAggregateFunction(max, Int64), lc_session_id SimpleAggregateFunction(max, String), lc_is_impersonated SimpleAggregateFunction(max, Bool), lc_workflow SimpleAggregateFunction(max, LowCardinality(String)), lc_kind SimpleAggregateFunction(max, LowCardinality(String)), lc_id SimpleAggregateFunction(max, String), lc_route_id SimpleAggregateFunction(max, String), lc_access_method SimpleAggregateFunction(max, LowCardinality(String)), lc_api_key_label SimpleAggregateFunction(max, String), lc_api_key_mask SimpleAggregateFunction(max, String), lc_query_type SimpleAggregateFunction(max, LowCardinality(String)), lc_product SimpleAggregateFunction(max, LowCardinality(String)), lc_chargeable SimpleAggregateFunction(max, Bool), lc_name SimpleAggregateFunction(max, String), lc_request_name SimpleAggregateFunction(max, String), lc_client_query_id SimpleAggregateFunction(max, String), lc_dashboard_id SimpleAggregateFunction(max, Int64), lc_insight_id SimpleAggregateFunction(max, Int64), lc_cohort_id SimpleAggregateFunction(max, Int64), lc_batch_export_id SimpleAggregateFunction(max, String), lc_experiment_id SimpleAggregateFunction(max, Int64), lc_experiment_feature_flag_key SimpleAggregateFunction(max, String), lc_alert_config_id SimpleAggregateFunction(max, String), lc_feature SimpleAggregateFunction(max, LowCardinality(String)), lc_table_id SimpleAggregateFunction(max, String), lc_warehouse_query SimpleAggregateFunction(max, Bool), lc_person_on_events_mode SimpleAggregateFunction(max, LowCardinality(String)), lc_service_name SimpleAggregateFunction(max, LowCardinality(String)), lc_workload SimpleAggregateFunction(max, LowCardinality(String)), lc_query__kind SimpleAggregateFunction(max, LowCardinality(String)), lc_query__query SimpleAggregateFunction(max, String), lc_query SimpleAggregateFunction(max, String), lc_modifiers SimpleAggregateFunction(max, String), lc_temporal__workflow_namespace SimpleAggregateFunction(max, LowCardinality(String)), lc_temporal__workflow_type SimpleAggregateFunction(max, LowCardinality(String)), lc_temporal__workflow_id SimpleAggregateFunction(max, String), lc_temporal__workflow_run_id SimpleAggregateFunction(max, String), lc_temporal__activity_type SimpleAggregateFunction(max, LowCardinality(String)), lc_temporal__activity_id SimpleAggregateFunction(max, String), lc_temporal__attempt SimpleAggregateFunction(max, Int64), lc_dagster__job_name SimpleAggregateFunction(max, LowCardinality(String)), lc_dagster__run_id SimpleAggregateFunction(max, String), lc_dagster__owner SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_name SimpleAggregateFunction(max, String), lc_experiment_metric_name SimpleAggregateFunction(max, String), lc_experiment_execution_path SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_metric_type SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_funnel_order_type SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_exposures_path SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_metric_events_path SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_query_surface SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_precompute_table SimpleAggregateFunction(max, String), lc_experiment_query_group_id SimpleAggregateFunction(max, String), lc_experiment_precompute_skip_reason SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_scan_date_from SimpleAggregateFunction(max, String), lc_experiment_scan_date_to SimpleAggregateFunction(max, String), lc_precompute_window_start SimpleAggregateFunction(max, String), lc_precompute_window_end SimpleAggregateFunction(max, String), lc_plan_fingerprint SimpleAggregateFunction(max, String), lc_estimated_rows SimpleAggregateFunction(max, Int64), lc_estimated_bytes SimpleAggregateFunction(max, Int64)) AS WITHJSONExtract(ql.log_comment, 'Tuple(team_id Int64, org_id String, user_id Int64, session_id String, is_impersonated Bool, workflow String, kind String, id String, route_id String, access_method String, api_key_label String, api_key_mask String, query_type String, product String, chargeable Bool, name String, request_name String, client_query_id String, dashboard_id Int64, insight_id Int64, cohort_id Int64, batch_export_id String, experiment_id Int64, experiment_feature_flag_key String, alert_config_id String, feature String, table_id String, warehouse_query Bool, person_on_events_mode String, service_name String, workload String, experiment_name String, experiment_metric_name String, experiment_execution_path String, experiment_metric_type String, experiment_funnel_order_type String, experiment_exposures_path String, experiment_metric_events_path String, experiment_query_surface String, experiment_precompute_table String, experiment_query_group_id String, experiment_precompute_skip_reason String, experiment_scan_date_from String, experiment_scan_date_to String, precompute_window_start String, precompute_window_end String, plan_fingerprint String, estimated_rows Int64, estimated_bytes Int64, temporal Tuple(workflow_namespace String, workflow_type String, workflow_id String, workflow_run_id String, activity_type String, activity_id String, attempt Int64), dagster Tuple(job_name String, run_id String, tags Tuple(owner String)), query Tuple(kind String, query String, source Tuple(kind String, query String)))') AS lcSELECTdiff --git a/posthog/clickhouse/hcl/sql/prod-us/apm.sql b/posthog/clickhouse/hcl/sql/prod-us/apm.sqlindex 3d0aef40c59b..d2b4e514e0a1 100644--- a/posthog/clickhouse/hcl/sql/prod-us/apm.sql+++ b/posthog/clickhouse/hcl/sql/prod-us/apm.sql@@ -106,7 +106,8 @@ CREATE TABLE posthog.writable_logs34 (_bytes_compressed UInt64,_record_count UInt64,pattern String,- pattern_version UInt8+ pattern_version UInt8,+ internal_source LowCardinality(String) DEFAULT '') ENGINE = Distributed('logs', 'posthog', 'logs34') SETTINGS background_insert_batch = 1;CREATE TABLE posthog.writable_metrics4_attributes (team_id Int32,@@ -288,7 +289,7 @@ CREATE TABLE posthog.writable_query_log_archive_v3 (lc_estimated_rows SimpleAggregateFunction(max, Int64),lc_estimated_bytes SimpleAggregateFunction(max, Int64)) ENGINE = Distributed('ops', 'posthog', 'query_log_archive_v3_buffer');-CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34 (uuid String, trace_id String, span_id String, trace_flags Int32, timestamp DateTime64(6), observed_timestamp DateTime64(6), body String, severity_text String, severity_number Int32, service_name String, instrumentation_scope String, event_name String, attributes_map_str Map(String, String), resource_attributes Map(String, String), team_id Int32, original_expiry_timestamp DateTime64(6), _partition UInt64, _topic LowCardinality(String), _offset UInt64, _record_count Int64, _bytes_uncompressed Nullable(Int64), _bytes_compressed Nullable(Int64), pattern String, pattern_version UInt8) AS SELECT+CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34 (uuid String, trace_id String, span_id String, trace_flags Int32, timestamp DateTime64(6), observed_timestamp DateTime64(6), body String, severity_text String, severity_number Int32, service_name String, instrumentation_scope String, event_name String, attributes_map_str Map(String, String), resource_attributes Map(String, String), team_id Int32, original_expiry_timestamp DateTime64(6), _partition UInt64, _topic LowCardinality(String), _offset UInt64, _record_count Int64, _bytes_uncompressed Nullable(Int64), _bytes_compressed Nullable(Int64), pattern String, pattern_version UInt8, internal_source LowCardinality(String)) AS SELECTuuid,trace_id,span_id,@@ -319,7 +320,8 @@ CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) / _record_count AS _bytes_uncompressed,toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) / _record_count AS _bytes_compressed,ifNull(pattern, '') AS pattern,- toUInt8(ifNull(pattern_version, 0)) AS pattern_version+ toUInt8(ifNull(pattern_version, 0)) AS pattern_version,+ _headers.value[indexOf(_headers.name, 'internal-source')] AS internal_sourceFROM posthog.kafka_logs_avro;CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro4_mv TO posthog.metrics4_input (uuid String, team_id Int32, metric_name String, series_fingerprint UInt64, resource_fingerprint UInt64, timestamp DateTime64(6), observed_timestamp DateTime64(6), original_expiry_timestamp DateTime64(6), service_name String, metric_type String, value Float64, count UInt64, histogram_bounds Array(Float64), histogram_counts Array(UInt64), trace_id String, span_id String, trace_flags Int32, has_labels Bool, unit String, aggregation_temporality String, is_monotonic UInt8, instrumentation_scope String, resource_attributes Map(String, String), attributes Map(String, String), _partition UInt64, _topic LowCardinality(String), _offset UInt64) AS SELECTuuid,diff --git a/posthog/clickhouse/hcl/sql/prod-us/logs.sql b/posthog/clickhouse/hcl/sql/prod-us/logs.sqlindex 189bd2aa2465..3262e3406a93 100644--- a/posthog/clickhouse/hcl/sql/prod-us/logs.sql+++ b/posthog/clickhouse/hcl/sql/prod-us/logs.sql@@ -102,6 +102,7 @@ CREATE TABLE posthog.logs34 (_record_count UInt64,pattern String,pattern_version UInt8,+ internal_source LowCardinality(String) DEFAULT '',INDEX idx_severity_text_set severity_text TYPE set(10) GRANULARITY 1,INDEX idx_attributes_str_keys mapKeys(attributes_map_str) TYPE bloom_filter(0.01) GRANULARITY 1,INDEX idx_attributes_str_values mapValues(attributes_map_str) TYPE bloom_filter(0.001) GRANULARITY 1,@@ -170,7 +171,8 @@ CREATE TABLE posthog.logs_distributed (_bytes_compressed UInt64,_record_count UInt64,pattern String,- pattern_version UInt8+ pattern_version UInt8,+ internal_source LowCardinality(String) DEFAULT '') ENGINE = Distributed('logs', 'posthog', 'logs34');CREATE TABLE posthog.logs_kafka_metrics (_partition UInt32,@@ -199,9 +201,10 @@ CREATE TABLE posthog.logs_pattern_buckets (severity_text LowCardinality(String),pattern_version UInt8,pattern String,+ internal_source LowCardinality(String),retention_days SimpleAggregateFunction(max, UInt16),log_count SimpleAggregateFunction(sum, UInt64)-) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.logs_pattern_buckets', '{replica}-{shard}') PRIMARY KEY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version) ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(greatest(42, retention_days)) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0;+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.logs_pattern_buckets', '{replica}-{shard}') PRIMARY KEY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version) ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern, internal_source) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(greatest(42, retention_days)) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0;CREATE TABLE posthog.logs_pattern_buckets_distributed (team_id Int32,time_bucket DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),@@ -211,6 +214,7 @@ CREATE TABLE posthog.logs_pattern_buckets_distributed (severity_text LowCardinality(String),pattern_version UInt8,pattern String,+ internal_source LowCardinality(String),retention_days SimpleAggregateFunction(max, UInt16),log_count SimpleAggregateFunction(sum, UInt64)) ENGINE = Distributed('logs', 'posthog', 'logs_pattern_buckets');@@ -221,9 +225,10 @@ CREATE TABLE posthog.logs_volume_buckets (namespace LowCardinality(String),environment LowCardinality(String),severity_text LowCardinality(String),+ internal_source LowCardinality(String),retention_days SimpleAggregateFunction(max, UInt16),log_count SimpleAggregateFunction(sum, UInt64)-) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.logs_volume_buckets', '{replica}-{shard}') ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(greatest(42, retention_days)) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0;+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.logs_volume_buckets', '{replica}-{shard}') PRIMARY KEY (team_id, time_bucket, service_name, namespace, environment, severity_text) ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, internal_source) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(greatest(42, retention_days)) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0;CREATE TABLE posthog.logs_volume_buckets_distributed (team_id Int32,time_bucket DateTime('UTC') CODEC(DoubleDelta, ZSTD(1)),@@ -231,6 +236,7 @@ CREATE TABLE posthog.logs_volume_buckets_distributed (namespace LowCardinality(String),environment LowCardinality(String),severity_text LowCardinality(String),+ internal_source LowCardinality(String),retention_days SimpleAggregateFunction(max, UInt16),log_count SimpleAggregateFunction(sum, UInt64)) ENGINE = Distributed('logs', 'posthog', 'logs_volume_buckets');@@ -1106,7 +1112,7 @@ FROMGROUP BYteam_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, attributes);-CREATE MATERIALIZED VIEW posthog.logs34_to_pattern_buckets TO posthog.logs_pattern_buckets (team_id Int32, time_bucket DateTime('UTC'), service_name LowCardinality(String), namespace LowCardinality(String), environment LowCardinality(String), severity_text LowCardinality(String), pattern_version UInt8, pattern String, retention_days SimpleAggregateFunction(max, UInt16), log_count SimpleAggregateFunction(sum, UInt64)) AS SELECT+CREATE MATERIALIZED VIEW posthog.logs34_to_pattern_buckets TO posthog.logs_pattern_buckets (team_id Int32, time_bucket DateTime('UTC'), service_name LowCardinality(String), namespace LowCardinality(String), environment LowCardinality(String), severity_text LowCardinality(String), pattern_version UInt8, pattern String, internal_source LowCardinality(String), retention_days SimpleAggregateFunction(max, UInt16), log_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,time_bucket,service_name,@@ -1115,6 +1121,7 @@ CREATE MATERIALIZED VIEW posthog.logs34_to_pattern_buckets TO posthog.logs_patteseverity_text,pattern_version,pattern,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -1140,6 +1147,7 @@ FROMlower(severity_text) AS severity_text,pattern_version,pattern,+ internal_source,toUInt16(least(intDiv(@@ -1154,7 +1162,7 @@ FROMWHERE pattern_version != 0)GROUP BY- team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern;+ team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern, internal_source;CREATE MATERIALIZED VIEW posthog.logs34_to_resource_attributes3 TO posthog.log_attributes3 (team_id Int32, time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), resource_fingerprint UInt64, attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), severity_text LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,time_bucket,@@ -1184,13 +1192,14 @@ FROMGROUP BYteam_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, resource_attributes);-CREATE MATERIALIZED VIEW posthog.logs34_to_volume_buckets TO posthog.logs_volume_buckets (team_id Int32, time_bucket DateTime('UTC'), service_name LowCardinality(String), namespace LowCardinality(String), environment LowCardinality(String), severity_text LowCardinality(String), retention_days SimpleAggregateFunction(max, UInt16), log_count SimpleAggregateFunction(sum, UInt64)) AS SELECT+CREATE MATERIALIZED VIEW posthog.logs34_to_volume_buckets TO posthog.logs_volume_buckets (team_id Int32, time_bucket DateTime('UTC'), service_name LowCardinality(String), namespace LowCardinality(String), environment LowCardinality(String), severity_text LowCardinality(String), internal_source LowCardinality(String), retention_days SimpleAggregateFunction(max, UInt16), log_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,time_bucket,service_name,namespace,environment,severity_text,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -1214,6 +1223,7 @@ FROM)) AS environment,lower(severity_text) AS severity_text,+ internal_source,toUInt16(least(intDiv(@@ -1227,7 +1237,7 @@ FROMFROM posthog.logs34)GROUP BY- team_id, time_bucket, service_name, namespace, environment, severity_text;+ team_id, time_bucket, service_name, namespace, environment, severity_text, internal_source;CREATE MATERIALIZED VIEW posthog.ops_query_log_archive_v3_mv TO posthog.writable_query_log_archive_v3 (initial_query_start_time DateTime64(6, 'UTC'), team_id Int64, initial_query_id String, is_initial_query SimpleAggregateFunction(max, UInt8), hostname SimpleAggregateFunction(max, LowCardinality(String)), user SimpleAggregateFunction(max, LowCardinality(String)), type SimpleAggregateFunction(max, Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)), event_time_microseconds SimpleAggregateFunction(max, DateTime64(6, 'UTC')), query_duration_ms SimpleAggregateFunction(max, UInt64), read_rows SimpleAggregateFunction(sum, UInt64), read_bytes SimpleAggregateFunction(sum, UInt64), written_rows SimpleAggregateFunction(sum, UInt64), written_bytes SimpleAggregateFunction(sum, UInt64), result_rows SimpleAggregateFunction(sum, UInt64), result_bytes SimpleAggregateFunction(sum, UInt64), memory_usage SimpleAggregateFunction(max, UInt64), memory_usage_sum SimpleAggregateFunction(sum, UInt64), peak_threads_usage SimpleAggregateFunction(sum, UInt64), execution_count SimpleAggregateFunction(sum, UInt64), current_database SimpleAggregateFunction(max, LowCardinality(String)), query SimpleAggregateFunction(max, String), normalized_query_hash SimpleAggregateFunction(max, UInt64), query_kind_by_root SimpleAggregateFunction(max, Tuple(UInt8, String)), tables SimpleAggregateFunction(max, Array(String)), exception_code SimpleAggregateFunction(max, Int32), exception SimpleAggregateFunction(max, String), stack_trace SimpleAggregateFunction(max, String), ProfileEvents_SelectedRows SimpleAggregateFunction(sum, UInt64), ProfileEvents_SelectedBytes SimpleAggregateFunction(sum, UInt64), ProfileEvents_RealTimeMicroseconds SimpleAggregateFunction(sum, UInt64), ProfileEvents_OSCPUVirtualTimeMicroseconds SimpleAggregateFunction(sum, UInt64), ProfileEvents_UserTimeMicroseconds SimpleAggregateFunction(sum, UInt64), ProfileEvents_SystemTimeMicroseconds SimpleAggregateFunction(sum, UInt64), ProfileEvents_SelectedParts SimpleAggregateFunction(sum, UInt64), ProfileEvents_SelectedMarks SimpleAggregateFunction(sum, UInt64), ProfileEvents_NetworkReceiveBytes SimpleAggregateFunction(sum, UInt64), ProfileEvents_NetworkSendBytes SimpleAggregateFunction(sum, UInt64), ProfileEvents_ReadBufferFromFileDescriptorReadBytes SimpleAggregateFunction(sum, UInt64), ProfileEvents_WriteBufferFromFileDescriptorWriteBytes SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3Clients SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3DeleteObjects SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3CopyObject SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3ListObjects SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3HeadObject SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3GetObjectAttributes SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3CreateMultipartUpload SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3UploadPartCopy SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3UploadPart SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3AbortMultipartUpload SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3CompleteMultipartUpload SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3PutObject SimpleAggregateFunction(sum, UInt64), ProfileEvents_S3GetObject SimpleAggregateFunction(sum, UInt64), ProfileEvents_ReadBufferFromS3Bytes SimpleAggregateFunction(sum, UInt64), ProfileEvents_WriteBufferFromS3Bytes SimpleAggregateFunction(sum, UInt64), lc_org_id SimpleAggregateFunction(max, String), lc_user_id SimpleAggregateFunction(max, Int64), lc_session_id SimpleAggregateFunction(max, String), lc_is_impersonated SimpleAggregateFunction(max, Bool), lc_workflow SimpleAggregateFunction(max, LowCardinality(String)), lc_kind SimpleAggregateFunction(max, LowCardinality(String)), lc_id SimpleAggregateFunction(max, String), lc_route_id SimpleAggregateFunction(max, String), lc_access_method SimpleAggregateFunction(max, LowCardinality(String)), lc_api_key_label SimpleAggregateFunction(max, String), lc_api_key_mask SimpleAggregateFunction(max, String), lc_query_type SimpleAggregateFunction(max, LowCardinality(String)), lc_product SimpleAggregateFunction(max, LowCardinality(String)), lc_chargeable SimpleAggregateFunction(max, Bool), lc_name SimpleAggregateFunction(max, String), lc_request_name SimpleAggregateFunction(max, String), lc_client_query_id SimpleAggregateFunction(max, String), lc_dashboard_id SimpleAggregateFunction(max, Int64), lc_insight_id SimpleAggregateFunction(max, Int64), lc_cohort_id SimpleAggregateFunction(max, Int64), lc_batch_export_id SimpleAggregateFunction(max, String), lc_experiment_id SimpleAggregateFunction(max, Int64), lc_experiment_feature_flag_key SimpleAggregateFunction(max, String), lc_alert_config_id SimpleAggregateFunction(max, String), lc_feature SimpleAggregateFunction(max, LowCardinality(String)), lc_table_id SimpleAggregateFunction(max, String), lc_warehouse_query SimpleAggregateFunction(max, Bool), lc_person_on_events_mode SimpleAggregateFunction(max, LowCardinality(String)), lc_service_name SimpleAggregateFunction(max, LowCardinality(String)), lc_workload SimpleAggregateFunction(max, LowCardinality(String)), lc_query__kind SimpleAggregateFunction(max, LowCardinality(String)), lc_query__query SimpleAggregateFunction(max, String), lc_query SimpleAggregateFunction(max, String), lc_modifiers SimpleAggregateFunction(max, String), lc_temporal__workflow_namespace SimpleAggregateFunction(max, LowCardinality(String)), lc_temporal__workflow_type SimpleAggregateFunction(max, LowCardinality(String)), lc_temporal__workflow_id SimpleAggregateFunction(max, String), lc_temporal__workflow_run_id SimpleAggregateFunction(max, String), lc_temporal__activity_type SimpleAggregateFunction(max, LowCardinality(String)), lc_temporal__activity_id SimpleAggregateFunction(max, String), lc_temporal__attempt SimpleAggregateFunction(max, Int64), lc_dagster__job_name SimpleAggregateFunction(max, LowCardinality(String)), lc_dagster__run_id SimpleAggregateFunction(max, String), lc_dagster__owner SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_name SimpleAggregateFunction(max, String), lc_experiment_metric_name SimpleAggregateFunction(max, String), lc_experiment_execution_path SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_metric_type SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_funnel_order_type SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_exposures_path SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_metric_events_path SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_query_surface SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_precompute_table SimpleAggregateFunction(max, String), lc_experiment_query_group_id SimpleAggregateFunction(max, String), lc_experiment_precompute_skip_reason SimpleAggregateFunction(max, LowCardinality(String)), lc_experiment_scan_date_from SimpleAggregateFunction(max, String), lc_experiment_scan_date_to SimpleAggregateFunction(max, String), lc_precompute_window_start SimpleAggregateFunction(max, String), lc_precompute_window_end SimpleAggregateFunction(max, String), lc_plan_fingerprint SimpleAggregateFunction(max, String), lc_estimated_rows SimpleAggregateFunction(max, Int64), lc_estimated_bytes SimpleAggregateFunction(max, Int64)) AS WITHJSONExtract(ql.log_comment, 'Tuple(team_id Int64, org_id String, user_id Int64, session_id String, is_impersonated Bool, workflow String, kind String, id String, route_id String, access_method String, api_key_label String, api_key_mask String, query_type String, product String, chargeable Bool, name String, request_name String, client_query_id String, dashboard_id Int64, insight_id Int64, cohort_id Int64, batch_export_id String, experiment_id Int64, experiment_feature_flag_key String, alert_config_id String, feature String, table_id String, warehouse_query Bool, person_on_events_mode String, service_name String, workload String, experiment_name String, experiment_metric_name String, experiment_execution_path String, experiment_metric_type String, experiment_funnel_order_type String, experiment_exposures_path String, experiment_metric_events_path String, experiment_query_surface String, experiment_precompute_table String, experiment_query_group_id String, experiment_precompute_skip_reason String, experiment_scan_date_from String, experiment_scan_date_to String, precompute_window_start String, precompute_window_end String, plan_fingerprint String, estimated_rows Int64, estimated_bytes Int64, temporal Tuple(workflow_namespace String, workflow_type String, workflow_id String, workflow_run_id String, activity_type String, activity_id String, attempt Int64), dagster Tuple(job_name String, run_id String, tags Tuple(owner String)), query Tuple(kind String, query String, source Tuple(kind String, query String)))') AS lcSELECTdiff --git a/posthog/clickhouse/logs/logs34.py b/posthog/clickhouse/logs/logs34.pyindex 9ed815e7f0e2..b3bb2843959d 100644--- a/posthog/clickhouse/logs/logs34.py+++ b/posthog/clickhouse/logs/logs34.py@@ -49,6 +49,7 @@ CREATE TABLE IF NOT EXISTS {settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE}.{TABLE_NA`_record_count` UInt64,`pattern` String,`pattern_version` UInt8,+ `internal_source` LowCardinality(String) DEFAULT '',INDEX idx_severity_text_set severity_text TYPE set(10) GRANULARITY 1,INDEX idx_attributes_str_keys mapKeys(attributes_map_str) TYPE bloom_filter(0.01) GRANULARITY 1,INDEX idx_attributes_str_values mapValues(attributes_map_str) TYPE bloom_filter(0.001) GRANULARITY 1,@@ -147,7 +148,8 @@ CREATE TABLE IF NOT EXISTS {db}.writable_logs34`_bytes_compressed` UInt64,`_record_count` UInt64,`pattern` String,- `pattern_version` UInt8+ `pattern_version` UInt8,+ `internal_source` LowCardinality(String) DEFAULT '')ENGINE = {Distributed(data_table=TABLE_NAME, cluster=settings.CLICKHOUSE_LOGS_WRITE_CLUSTER)}SETTINGS background_insert_batch = 1@@ -294,8 +296,17 @@ SETTINGS"""-def KAFKA_LOGS34_AVRO_MV_SELECT():+# Migrations before 0361 pass `internal_source=False`, because the column does not exist yet on a+# database that upgrades through them. 0361 adds it to every table and then rebuilds each view.+_INTERNAL_SOURCE_TYPE = " `internal_source` LowCardinality(String)"+++def KAFKA_LOGS34_AVRO_MV_SELECT(*, internal_source: bool = True):db = settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE+ # The logs consumer removes any incoming `internal-source` header and sets it only on a batch whose signature it verified.+ internal_source_column = (+ ",\n _headers.value[indexOf(_headers.name, 'internal-source')] AS internal_source" if internal_source else ""+ )return f"""SELECTuuid,trace_id,@@ -320,14 +331,14 @@ def KAFKA_LOGS34_AVRO_MV_SELECT():toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) / _record_count AS _bytes_uncompressed,toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) / _record_count AS _bytes_compressed,ifNull(pattern, '') AS pattern,- toUInt8(ifNull(pattern_version, 0)) AS pattern_version+ toUInt8(ifNull(pattern_version, 0)) AS pattern_version{internal_source_column}FROM {db}.{KAFKA_TABLE_NAME}"""-def KAFKA_LOGS34_AVRO_MV(to_table: str = TABLE_NAME):+def KAFKA_LOGS34_AVRO_MV(to_table: str = TABLE_NAME, *, internal_source: bool = True):db = settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE# `to_table` defaults to `logs34` so the historical migration 0280 (which creates this MV on the- # logs nodes, where `logs34` is local) keeps working when replayed. Migrations 0305 and 0359 pass+ # logs nodes, where `logs34` is local) keeps working when replayed. Migrations 0305, 0359 and 0361 pass# `writable_logs34` — the Distributed(logs, posthog, logs34) table on the ingestion nodes —# because `logs34` itself is not local there.return f"""@@ -356,9 +367,9 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS {db}.kafka_logs34_avro_mv TO {db}.{to_tab`_bytes_uncompressed` Nullable(Int64),`_bytes_compressed` Nullable(Int64),`pattern` String,- `pattern_version` UInt8+ `pattern_version` UInt8{"," + chr(10) + _INTERNAL_SOURCE_TYPE if internal_source else ""})-AS {KAFKA_LOGS34_AVRO_MV_SELECT()}+AS {KAFKA_LOGS34_AVRO_MV_SELECT(internal_source=internal_source)}"""@@ -397,28 +408,31 @@ _LOGS34_SERIES_KEY_COLUMNS = """ team_id,_LOGS34_RETENTION_DAYS_COLUMN = """ toUInt16(least(intDiv(greatest(dateDiff('microsecond', time_bucket, original_expiry_timestamp), 0) + 86399999999, 86400000000), 3650)) AS retention_days"""-def LOGS34_TO_VOLUME_BUCKETS_MV_SELECT():+def LOGS34_TO_VOLUME_BUCKETS_MV_SELECT(*, internal_source: bool = True):db = settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE+ outer = "\n internal_source," if internal_source else ""+ inner = "\n internal_source," if internal_source else ""+ group = ", internal_source" if internal_source else ""return f"""SELECTteam_id,time_bucket,service_name,namespace,environment,- severity_text,+ severity_text,{outer}maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM(SELECT-{_LOGS34_SERIES_KEY_COLUMNS},+{_LOGS34_SERIES_KEY_COLUMNS},{inner}{_LOGS34_RETENTION_DAYS_COLUMN}FROM {db}.{TABLE_NAME})-GROUP BY team_id, time_bucket, service_name, namespace, environment, severity_text"""+GROUP BY team_id, time_bucket, service_name, namespace, environment, severity_text{group}"""-def LOGS34_TO_VOLUME_BUCKETS_MV():+def LOGS34_TO_VOLUME_BUCKETS_MV(*, internal_source: bool = True):db = settings.CLICKHOUSE_LOGS_CLUSTER_DATABASEreturn f"""CREATE MATERIALIZED VIEW IF NOT EXISTS {db}.logs34_to_volume_buckets TO {db}.logs_volume_buckets@@ -428,16 +442,19 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS {db}.logs34_to_volume_buckets TO {db}.log`service_name` LowCardinality(String),`namespace` LowCardinality(String),`environment` LowCardinality(String),- `severity_text` LowCardinality(String),+ `severity_text` LowCardinality(String),{chr(10) + _INTERNAL_SOURCE_TYPE + "," if internal_source else ""}`retention_days` SimpleAggregateFunction(max, UInt16),`log_count` SimpleAggregateFunction(sum, UInt64))-AS {LOGS34_TO_VOLUME_BUCKETS_MV_SELECT()}+AS {LOGS34_TO_VOLUME_BUCKETS_MV_SELECT(internal_source=internal_source)}"""-def LOGS34_TO_PATTERN_BUCKETS_MV_SELECT() -> str:+def LOGS34_TO_PATTERN_BUCKETS_MV_SELECT(*, internal_source: bool = True) -> str:db = settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE+ outer = "\n internal_source," if internal_source else ""+ inner = "\n internal_source," if internal_source else ""+ group = ", internal_source" if internal_source else ""# `pattern_version = 0` marks a row the ingestion consumer never stamped. Those# rows would all collapse into one empty-pattern bucket per series, so they are# dropped. The filter is on the version, not on `pattern != ''`, because a@@ -450,7 +467,7 @@ def LOGS34_TO_PATTERN_BUCKETS_MV_SELECT() -> str:environment,severity_text,pattern_version,- pattern,+ pattern,{outer}maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -458,15 +475,15 @@ FROMSELECT{_LOGS34_SERIES_KEY_COLUMNS},pattern_version,- pattern,+ pattern,{inner}{_LOGS34_RETENTION_DAYS_COLUMN}FROM {db}.{TABLE_NAME}WHERE pattern_version != 0)-GROUP BY team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern"""+GROUP BY team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern{group}"""-def LOGS34_TO_PATTERN_BUCKETS_MV() -> str:+def LOGS34_TO_PATTERN_BUCKETS_MV(*, internal_source: bool = True) -> str:db = settings.CLICKHOUSE_LOGS_CLUSTER_DATABASEreturn f"""CREATE MATERIALIZED VIEW IF NOT EXISTS {db}.logs34_to_pattern_buckets TO {db}.logs_pattern_buckets@@ -478,11 +495,11 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS {db}.logs34_to_pattern_buckets TO {db}.lo`environment` LowCardinality(String),`severity_text` LowCardinality(String),`pattern_version` UInt8,- `pattern` String,+ `pattern` String,{chr(10) + _INTERNAL_SOURCE_TYPE + "," if internal_source else ""}`retention_days` SimpleAggregateFunction(max, UInt16),`log_count` SimpleAggregateFunction(sum, UInt64))-AS {LOGS34_TO_PATTERN_BUCKETS_MV_SELECT()}+AS {LOGS34_TO_PATTERN_BUCKETS_MV_SELECT(internal_source=internal_source)}"""diff --git a/posthog/clickhouse/logs/logs_pattern_buckets.py b/posthog/clickhouse/logs/logs_pattern_buckets.pyindex 45aec484d826..182eced9910c 100644--- a/posthog/clickhouse/logs/logs_pattern_buckets.py+++ b/posthog/clickhouse/logs/logs_pattern_buckets.py@@ -55,12 +55,13 @@ CREATE TABLE IF NOT EXISTS {settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE}.{TABLE_NA`severity_text` LowCardinality(String),`pattern_version` UInt8,`pattern` String,+ `internal_source` LowCardinality(String),`retention_days` SimpleAggregateFunction(max, UInt16),`log_count` SimpleAggregateFunction(sum, UInt64))ENGINE = {AggregatingMergeTree(TABLE_NAME, replication_scheme=ReplicationScheme.REPLICATED)}PARTITION BY toDate(time_bucket)-ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern)+ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern, internal_source)PRIMARY KEY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version){ttl_clause}SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0diff --git a/posthog/clickhouse/logs/logs_volume_buckets.py b/posthog/clickhouse/logs/logs_volume_buckets.pyindex cee82c66f8b3..e0a220dec78e 100644--- a/posthog/clickhouse/logs/logs_volume_buckets.py+++ b/posthog/clickhouse/logs/logs_volume_buckets.py@@ -19,6 +19,9 @@ from posthog.clickhouse.table_engines import AggregatingMergeTree, Distributed,# series per day are few enough that a dims-early key would make every granule# span the whole day.#+# PRIMARY KEY stays the original sort key. `MODIFY ORDER BY` keeps an existing table's primary key, so+# a fresh table must declare the same key to match a migrated one.+## The TTL floor is 42 days, which buys 6 weekly samples per time-of-week slot.# A team whose raw logs outlive that keeps the rollup alongside them, so the# TTL takes whichever of the two is longer. `retention_days` is the bucket's@@ -44,12 +47,14 @@ CREATE TABLE IF NOT EXISTS {settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE}.{TABLE_NA`namespace` LowCardinality(String),`environment` LowCardinality(String),`severity_text` LowCardinality(String),+ `internal_source` LowCardinality(String),`retention_days` SimpleAggregateFunction(max, UInt16),`log_count` SimpleAggregateFunction(sum, UInt64))ENGINE = {AggregatingMergeTree(TABLE_NAME, replication_scheme=ReplicationScheme.REPLICATED)}PARTITION BY toDate(time_bucket)-ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text)+ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, internal_source)+PRIMARY KEY (team_id, time_bucket, service_name, namespace, environment, severity_text){ttl_clause}SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0"""diff --git a/posthog/clickhouse/migrations/0280_logs34.py b/posthog/clickhouse/migrations/0280_logs34.pyindex 40de0f25edad..8ebe522b47c6 100644--- a/posthog/clickhouse/migrations/0280_logs34.py+++ b/posthog/clickhouse/migrations/0280_logs34.py@@ -136,7 +136,7 @@ operations = [run_sql_with_exceptions(LOGS34_TO_LOG_ATTRIBUTES_MV(), node_roles=[NodeRole.LOGS]),run_sql_with_exceptions(LOGS34_TO_RESOURCE_ATTRIBUTES_MV(), node_roles=[NodeRole.LOGS]),run_sql_with_exceptions(KAFKA_LOGS_AVRO_TABLE_SQL(), node_roles=[NodeRole.LOGS]),- run_sql_with_exceptions(KAFKA_LOGS34_AVRO_MV(), node_roles=[NodeRole.LOGS]),+ run_sql_with_exceptions(KAFKA_LOGS34_AVRO_MV(internal_source=False), node_roles=[NodeRole.LOGS]),run_sql_with_exceptions(KAFKA_LOGS_AVRO_KAFKA_METRICS_MV(), node_roles=[NodeRole.LOGS]),run_sql_with_exceptions(KAFKA_LOGS_AVRO_BILLING_METRICS_MV(), node_roles=[NodeRole.LOGS]),]diff --git a/posthog/clickhouse/migrations/0298_logs34_mv_explicit_columns.py b/posthog/clickhouse/migrations/0298_logs34_mv_explicit_columns.pyindex f93986798178..f7fb25e8bdc2 100644--- a/posthog/clickhouse/migrations/0298_logs34_mv_explicit_columns.py+++ b/posthog/clickhouse/migrations/0298_logs34_mv_explicit_columns.py@@ -8,7 +8,7 @@ DB = settings.CLICKHOUSE_LOGS_CLUSTER_DATABASEoperations = [run_sql_with_exceptions(- f"ALTER TABLE {DB}.kafka_logs34_avro_mv MODIFY QUERY\n{KAFKA_LOGS34_AVRO_MV_SELECT()}",+ f"ALTER TABLE {DB}.kafka_logs34_avro_mv MODIFY QUERY\n{KAFKA_LOGS34_AVRO_MV_SELECT(internal_source=False)}",node_roles=[NodeRole.LOGS],sharded=False,is_alter_on_replicated_table=False,diff --git a/posthog/clickhouse/migrations/0302_logs34_to_volume_buckets_mv.py b/posthog/clickhouse/migrations/0302_logs34_to_volume_buckets_mv.pyindex 4d7eaf601d3e..10d4f17b213c 100644--- a/posthog/clickhouse/migrations/0302_logs34_to_volume_buckets_mv.py+++ b/posthog/clickhouse/migrations/0302_logs34_to_volume_buckets_mv.py@@ -3,5 +3,5 @@ from posthog.clickhouse.client.migration_tools import run_sql_with_exceptionsfrom posthog.clickhouse.logs import LOGS34_TO_VOLUME_BUCKETS_MVoperations = [- run_sql_with_exceptions(LOGS34_TO_VOLUME_BUCKETS_MV(), node_roles=[NodeRole.LOGS]),+ run_sql_with_exceptions(LOGS34_TO_VOLUME_BUCKETS_MV(internal_source=False), node_roles=[NodeRole.LOGS]),]diff --git a/posthog/clickhouse/migrations/0305_logs_retention_days.py b/posthog/clickhouse/migrations/0305_logs_retention_days.pyindex dd0232161cd7..72b9cf311b23 100644--- a/posthog/clickhouse/migrations/0305_logs_retention_days.py+++ b/posthog/clickhouse/migrations/0305_logs_retention_days.py@@ -28,5 +28,7 @@ operations = [# on dev/local so the MV below has its destination.run_sql_with_exceptions(WRITABLE_LOGS34_TABLE_SQL(), node_roles=[NodeRole.INGESTION_EVENTS]),run_sql_with_exceptions(KAFKA_LOGS_AVRO_TABLE_SQL(), node_roles=[NodeRole.INGESTION_EVENTS]),- run_sql_with_exceptions(KAFKA_LOGS34_AVRO_MV(to_table="writable_logs34"), node_roles=[NodeRole.INGESTION_EVENTS]),+ run_sql_with_exceptions(+ KAFKA_LOGS34_AVRO_MV(to_table="writable_logs34", internal_source=False), node_roles=[NodeRole.INGESTION_EVENTS]+ ),]diff --git a/posthog/clickhouse/migrations/0307_logs_pattern_kafka.py b/posthog/clickhouse/migrations/0307_logs_pattern_kafka.pyindex 834d258984db..cdb3cdd6adc0 100644--- a/posthog/clickhouse/migrations/0307_logs_pattern_kafka.py+++ b/posthog/clickhouse/migrations/0307_logs_pattern_kafka.py@@ -45,5 +45,7 @@ operations = [is_alter_on_replicated_table=False,),run_sql_with_exceptions(KAFKA_LOGS_AVRO_TABLE_SQL(), node_roles=[NodeRole.INGESTION_EVENTS]),- run_sql_with_exceptions(KAFKA_LOGS34_AVRO_MV(to_table="writable_logs34"), node_roles=[NodeRole.INGESTION_EVENTS]),+ run_sql_with_exceptions(+ KAFKA_LOGS34_AVRO_MV(to_table="writable_logs34", internal_source=False), node_roles=[NodeRole.INGESTION_EVENTS]+ ),]diff --git a/posthog/clickhouse/migrations/0329_logs_volume_buckets_retention_ttl.py b/posthog/clickhouse/migrations/0329_logs_volume_buckets_retention_ttl.pyindex f6f30014f8c1..1bcb3292903e 100644--- a/posthog/clickhouse/migrations/0329_logs_volume_buckets_retention_ttl.py+++ b/posthog/clickhouse/migrations/0329_logs_volume_buckets_retention_ttl.py@@ -35,7 +35,7 @@ ALTER TABLE {DB}.logs_volume_bucketsis_alter_on_replicated_table=False,),run_sql_with_exceptions(- f"ALTER TABLE {DB}.logs34_to_volume_buckets MODIFY QUERY\n{LOGS34_TO_VOLUME_BUCKETS_MV_SELECT()}",+ f"ALTER TABLE {DB}.logs34_to_volume_buckets MODIFY QUERY\n{LOGS34_TO_VOLUME_BUCKETS_MV_SELECT(internal_source=False)}",node_roles=[NodeRole.LOGS],sharded=False,is_alter_on_replicated_table=False,diff --git a/posthog/clickhouse/migrations/0348_expiry_from_timestamp.py b/posthog/clickhouse/migrations/0348_expiry_from_timestamp.pyindex 951678a0c1f2..108fd2e1766d 100644--- a/posthog/clickhouse/migrations/0348_expiry_from_timestamp.py+++ b/posthog/clickhouse/migrations/0348_expiry_from_timestamp.py@@ -28,7 +28,9 @@ _traces_mv = KAFKA_TRACE_SPANS_AVRO_MV(to_table="writable_trace_spans") if _is_doperations = [run_sql_with_exceptions(f"DROP TABLE IF EXISTS {DB}.kafka_logs34_avro_mv", node_roles=[_logs_role]),- run_sql_with_exceptions(KAFKA_LOGS34_AVRO_MV(to_table="writable_logs34"), node_roles=[_logs_role]),+ run_sql_with_exceptions(+ KAFKA_LOGS34_AVRO_MV(to_table="writable_logs34", internal_source=False), node_roles=[_logs_role]+ ),run_sql_with_exceptions(f"DROP TABLE IF EXISTS {DB}.kafka_trace_spans_avro_mv", node_roles=[_traces_role]),run_sql_with_exceptions(_traces_mv, node_roles=[_traces_role]),]diff --git a/posthog/clickhouse/migrations/0355_logs34_to_pattern_buckets_mv.py b/posthog/clickhouse/migrations/0355_logs34_to_pattern_buckets_mv.pyindex 2b681390c40e..e12be09e2301 100644--- a/posthog/clickhouse/migrations/0355_logs34_to_pattern_buckets_mv.py+++ b/posthog/clickhouse/migrations/0355_logs34_to_pattern_buckets_mv.py@@ -3,5 +3,5 @@ from posthog.clickhouse.client.migration_tools import run_sql_with_exceptionsfrom posthog.clickhouse.logs import LOGS34_TO_PATTERN_BUCKETS_MVoperations = [- run_sql_with_exceptions(LOGS34_TO_PATTERN_BUCKETS_MV(), node_roles=[NodeRole.LOGS]),+ run_sql_with_exceptions(LOGS34_TO_PATTERN_BUCKETS_MV(internal_source=False), node_roles=[NodeRole.LOGS]),]diff --git a/posthog/clickhouse/migrations/0359_logs_ingest_to_apm.py b/posthog/clickhouse/migrations/0359_logs_ingest_to_apm.pyindex 0c075b5a0ef9..ac5067e4d2aa 100644--- a/posthog/clickhouse/migrations/0359_logs_ingest_to_apm.py+++ b/posthog/clickhouse/migrations/0359_logs_ingest_to_apm.py@@ -30,7 +30,9 @@ operations = (run_sql_with_exceptions(WRITABLE_LOGS34_TABLE_SQL(), node_roles=[NodeRole.APM], require_hosts=True),run_sql_with_exceptions(KAFKA_LOGS_AVRO_TABLE_SQL(), node_roles=[NodeRole.APM], require_hosts=True),run_sql_with_exceptions(- KAFKA_LOGS34_AVRO_MV(to_table="writable_logs34"), node_roles=[NodeRole.APM], require_hosts=True+ KAFKA_LOGS34_AVRO_MV(to_table="writable_logs34", internal_source=False),+ node_roles=[NodeRole.APM],+ require_hosts=True,),run_sql_with_exceptions(f"DROP TABLE IF EXISTS {DB}.kafka_logs_avro", node_roles=[NodeRole.INGESTION_EVENTS]),run_sql_with_exceptions(diff --git a/posthog/clickhouse/migrations/0361_logs34_internal_source.py b/posthog/clickhouse/migrations/0361_logs34_internal_source.pynew file mode 100644index 000000000000..7d3cebbfcbba--- /dev/null+++ b/posthog/clickhouse/migrations/0361_logs34_internal_source.py@@ -0,0 +1,98 @@+from django.conf import settings++from posthog.clickhouse.client.connection import NodeRole+from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions+from posthog.clickhouse.logs import (+ KAFKA_LOGS34_AVRO_MV,+ LOGS34_TO_PATTERN_BUCKETS_MV_SELECT,+ LOGS34_TO_VOLUME_BUCKETS_MV_SELECT,+)+from posthog.run_mode import run_mode++DB = settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE++# `internal_source` marks a log row that PostHog wrote about a team's own use of PostHog. The+# ingestion consumer sets the `internal-source` Kafka header only after it verifies the batch+# signature, and the Kafka MV copies the header into the column. A message without the header gets+# '', because indexOf returns 0 and array index 0 returns the element type's default value.+#+# Every storage and Distributed table gets the column before an MV selects it, so no insert can fail+# with a missing target column.+#+# The rollups carry the column as a grouping dimension. ClickHouse allows a new column at the end of+# the sort key in the same ALTER that adds it, so the change is metadata only and existing parts read+# the column as ''. That append is forbidden for a column with a DEFAULT expression, so the rollup+# columns rely on the String type default instead. The rollup MVs change by MODIFY QUERY, which+# swaps the query in place, so no insert into logs34 lands while a rollup MV is missing.+#+# The Kafka MV is dropped and recreated where 0359 runs the ingest: the apm nodes in the cloud envs,+# the ingestion-events node in the multinode stack, in both cases writing through `writable_logs34`.+# While the MV is absent the Kafka table does not consume, so the consumer group resumes from its+# committed offset.+_logs_ingest_role = NodeRole.APM if run_mode().is_deployed_cloud else NodeRole.INGESTION_EVENTS++operations = [+ run_sql_with_exceptions(+ f"ALTER TABLE {DB}.logs34 ADD COLUMN IF NOT EXISTS internal_source LowCardinality(String) DEFAULT ''",+ node_roles=[NodeRole.LOGS],+ sharded=False,+ is_alter_on_replicated_table=True,+ ),+ run_sql_with_exceptions(+ f"ALTER TABLE {DB}.logs_distributed ADD COLUMN IF NOT EXISTS internal_source LowCardinality(String) DEFAULT ''",+ node_roles=[NodeRole.LOGS],+ sharded=False,+ is_alter_on_replicated_table=False,+ ),+ run_sql_with_exceptions(+ f"ALTER TABLE {DB}.logs_volume_buckets "+ "ADD COLUMN IF NOT EXISTS internal_source LowCardinality(String) AFTER severity_text, "+ "MODIFY ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, internal_source)",+ node_roles=[NodeRole.LOGS],+ sharded=False,+ is_alter_on_replicated_table=True,+ ),+ run_sql_with_exceptions(+ f"ALTER TABLE {DB}.logs_volume_buckets_distributed "+ "ADD COLUMN IF NOT EXISTS internal_source LowCardinality(String) AFTER severity_text",+ node_roles=[NodeRole.LOGS],+ sharded=False,+ is_alter_on_replicated_table=False,+ ),+ run_sql_with_exceptions(+ f"ALTER TABLE {DB}.logs_pattern_buckets "+ "ADD COLUMN IF NOT EXISTS internal_source LowCardinality(String) AFTER pattern, "+ "MODIFY ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, "+ "pattern_version, pattern, internal_source)",+ node_roles=[NodeRole.LOGS],+ sharded=False,+ is_alter_on_replicated_table=True,+ ),+ run_sql_with_exceptions(+ f"ALTER TABLE {DB}.logs_pattern_buckets_distributed "+ "ADD COLUMN IF NOT EXISTS internal_source LowCardinality(String) AFTER pattern",+ node_roles=[NodeRole.LOGS],+ sharded=False,+ is_alter_on_replicated_table=False,+ ),+ run_sql_with_exceptions(+ f"ALTER TABLE {DB}.logs34_to_volume_buckets MODIFY QUERY {LOGS34_TO_VOLUME_BUCKETS_MV_SELECT()}",+ node_roles=[NodeRole.LOGS],+ sharded=False,+ is_alter_on_replicated_table=False,+ ),+ run_sql_with_exceptions(+ f"ALTER TABLE {DB}.logs34_to_pattern_buckets MODIFY QUERY {LOGS34_TO_PATTERN_BUCKETS_MV_SELECT()}",+ node_roles=[NodeRole.LOGS],+ sharded=False,+ is_alter_on_replicated_table=False,+ ),+ run_sql_with_exceptions(+ f"ALTER TABLE {DB}.writable_logs34 ADD COLUMN IF NOT EXISTS internal_source LowCardinality(String) DEFAULT ''",+ node_roles=[_logs_ingest_role],+ sharded=False,+ is_alter_on_replicated_table=False,+ ),+ run_sql_with_exceptions(f"DROP TABLE IF EXISTS {DB}.kafka_logs34_avro_mv", node_roles=[_logs_ingest_role]),+ run_sql_with_exceptions(KAFKA_LOGS34_AVRO_MV(to_table="writable_logs34"), node_roles=[_logs_ingest_role]),+]diff --git a/posthog/clickhouse/migrations/max_migration.txt b/posthog/clickhouse/migrations/max_migration.txtindex b20bb7b9828a..e3122604a450 100644--- a/posthog/clickhouse/migrations/max_migration.txt+++ b/posthog/clickhouse/migrations/max_migration.txt@@ -1 +1 @@-0360_metrics4_samples_service_freshness_projection+0361_logs34_internal_sourcediff --git a/posthog/clickhouse/test/__snapshots__/test_schema.ambr b/posthog/clickhouse/test/__snapshots__/test_schema.ambrindex 1d41fdc24c45..635b9c6ebabd 100644--- a/posthog/clickhouse/test/__snapshots__/test_schema.ambr+++ b/posthog/clickhouse/test/__snapshots__/test_schema.ambr@@ -3921,6 +3921,7 @@`_record_count` UInt64,`pattern` String,`pattern_version` UInt8,+ `internal_source` LowCardinality(String) DEFAULT '',INDEX idx_severity_text_set severity_text TYPE set(10) GRANULARITY 1,INDEX idx_attributes_str_keys mapKeys(attributes_map_str) TYPE bloom_filter(0.01) GRANULARITY 1,INDEX idx_attributes_str_values mapValues(attributes_map_str) TYPE bloom_filter(0.001) GRANULARITY 1,@@ -4031,6 +4032,7 @@`severity_text` LowCardinality(String),`pattern_version` UInt8,`pattern` String,+ `internal_source` LowCardinality(String),`retention_days` SimpleAggregateFunction(max, UInt16),`log_count` SimpleAggregateFunction(sum, UInt64))@@ -4043,6 +4045,7 @@severity_text,pattern_version,pattern,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -4068,11 +4071,12 @@lower(severity_text) AS severity_text,pattern_version,pattern,+ internal_source,toUInt16(least(intDiv(greatest(dateDiff('microsecond', time_bucket, original_expiry_timestamp), 0) + 86399999999, 86400000000), 3650)) AS retention_daysFROM posthog_test.logs34WHERE pattern_version != 0)- GROUP BY team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern+ GROUP BY team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern, internal_source'''# ---@@ -4141,6 +4145,7 @@`namespace` LowCardinality(String),`environment` LowCardinality(String),`severity_text` LowCardinality(String),+ `internal_source` LowCardinality(String),`retention_days` SimpleAggregateFunction(max, UInt16),`log_count` SimpleAggregateFunction(sum, UInt64))@@ -4151,6 +4156,7 @@namespace,environment,severity_text,+ internal_source,maxSimpleState(retention_days) AS retention_days,sumSimpleState(1) AS log_countFROM@@ -4174,10 +4180,11 @@)) AS environment,lower(severity_text) AS severity_text,+ internal_source,toUInt16(least(intDiv(greatest(dateDiff('microsecond', time_bucket, original_expiry_timestamp), 0) + 86399999999, 86400000000), 3650)) AS retention_daysFROM posthog_test.logs34)- GROUP BY team_id, time_bucket, service_name, namespace, environment, severity_text+ GROUP BY team_id, time_bucket, service_name, namespace, environment, severity_text, internal_source'''# ---@@ -4261,12 +4268,13 @@`severity_text` LowCardinality(String),`pattern_version` UInt8,`pattern` String,+ `internal_source` LowCardinality(String),`retention_days` SimpleAggregateFunction(max, UInt16),`log_count` SimpleAggregateFunction(sum, UInt64))ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/77f1df52-4b43-11e9-910f-b8ca3a9b9f3e_noshard/posthog.logs_pattern_buckets', '{replica}-{shard}')PARTITION BY toDate(time_bucket)- ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern)+ ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern, internal_source)PRIMARY KEY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version)SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0@@ -4291,12 +4299,14 @@`namespace` LowCardinality(String),`environment` LowCardinality(String),`severity_text` LowCardinality(String),+ `internal_source` LowCardinality(String),`retention_days` SimpleAggregateFunction(max, UInt16),`log_count` SimpleAggregateFunction(sum, UInt64))ENGINE = ReplicatedAggregatingMergeTree('/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, service_name, namespace, environment, severity_text)+ ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, internal_source)+ PRIMARY KEY (team_id, time_bucket, service_name, namespace, environment, severity_text)SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0@@ -12245,6 +12255,7 @@`_record_count` UInt64,`pattern` String,`pattern_version` UInt8,+ `internal_source` LowCardinality(String) DEFAULT '',INDEX idx_severity_text_set severity_text TYPE set(10) GRANULARITY 1,INDEX idx_attributes_str_keys mapKeys(attributes_map_str) TYPE bloom_filter(0.01) GRANULARITY 1,INDEX idx_attributes_str_values mapValues(attributes_map_str) TYPE bloom_filter(0.001) GRANULARITY 1,@@ -12339,12 +12350,13 @@`severity_text` LowCardinality(String),`pattern_version` UInt8,`pattern` String,+ `internal_source` LowCardinality(String),`retention_days` SimpleAggregateFunction(max, UInt16),`log_count` SimpleAggregateFunction(sum, UInt64))ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/77f1df52-4b43-11e9-910f-b8ca3a9b9f3e_noshard/posthog.logs_pattern_buckets', '{replica}-{shard}')PARTITION BY toDate(time_bucket)- ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern)+ ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version, pattern, internal_source)PRIMARY KEY (team_id, time_bucket, service_name, namespace, environment, severity_text, pattern_version)SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0@@ -12362,12 +12374,14 @@`namespace` LowCardinality(String),`environment` LowCardinality(String),`severity_text` LowCardinality(String),+ `internal_source` LowCardinality(String),`retention_days` SimpleAggregateFunction(max, UInt16),`log_count` SimpleAggregateFunction(sum, UInt64))ENGINE = ReplicatedAggregatingMergeTree('/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, service_name, namespace, environment, severity_text)+ ORDER BY (team_id, time_bucket, service_name, namespace, environment, severity_text, internal_source)+ PRIMARY KEY (team_id, time_bucket, service_name, namespace, environment, severity_text)SETTINGS index_granularity = 8192, ttl_only_drop_parts = 0diff --git a/posthog/clickhouse/test/test_schema.py b/posthog/clickhouse/test/test_schema.pyindex 3c3e4619067a..00040a3fe191 100644--- a/posthog/clickhouse/test/test_schema.py+++ b/posthog/clickhouse/test/test_schema.py@@ -135,7 +135,8 @@ def test_logs_volume_bucket_retention_covers_raw_expiry(observed_timestamp + toIntervalDay(arrayJoin(%(retentions)s)) AS original_expiry_timestamp,'checkout' AS service_name,'INFO' AS severity_text,- CAST(map(), 'Map(String, String)') AS resource_attributes+ CAST(map(), 'Map(String, String)') AS resource_attributes,+ '' AS internal_source)SELECT retention_days, log_count FROM ("""+ select@@ -169,14 +170,23 @@ def test_logs_pattern_buckets_keep_stamped_empty_patterns_and_drop_unstamped_row'INFO' AS severity_text,CAST(map(), 'Map(String, String)') AS resource_attributes,toUInt8(row.1) AS pattern_version,- row.2 AS pattern- FROM (SELECT arrayJoin([(0, '', 14), (5, '', 14), (5, 'GET <N>', 14), (5, 'GET <N>', 30)]) AS row)+ row.2 AS pattern,+ row.4 AS internal_source+ FROM (+ SELECT arrayJoin([+ (0, '', 14, ''),+ (5, '', 14, ''),+ (5, 'GET <N>', 14, ''),+ (5, 'GET <N>', 30, ''),+ (5, 'GET <N>', 14, 'hog_flow')+ ]) AS row+ ))- SELECT pattern_version, pattern, retention_days, log_count FROM ("""+ SELECT pattern_version, pattern, internal_source, retention_days, log_count FROM ("""+ select- + ") ORDER BY pattern"+ + ") ORDER BY pattern, internal_source")- assert rows == [(5, "", 15, 1), (5, "GET <N>", 31, 2)]+ assert rows == [(5, "", "", 15, 1), (5, "GET <N>", "", 31, 2), (5, "GET <N>", "hog_flow", 15, 1)]def _column_definition_lines(block: str) -> Iterator[str]: