: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
chore(clickhouse): reconcile cloud logs goldens against prod dumps (#67521)
Paweł Szczurf01f959b21e5
diff --git a/posthog/clickhouse/hcl/golden/dev-logs.hcl b/posthog/clickhouse/hcl/golden/dev-logs.hclindex b3c12b9865d6..13b84c0a79e0 100644--- a/posthog/clickhouse/hcl/golden/dev-logs.hcl+++ b/posthog/clickhouse/hcl/golden/dev-logs.hcl@@ -113,6 +113,9 @@ database "posthog" {column "attributes" {type = "Map(String, String)"}+ column "series_fingerprint" {+ type = "Nullable(Int64)"+ }engine "kafka" {broker_list = "warpstream_metrics"topic_list = "kafka_topic_list = 'clickhouse_metrics'"@@ -191,6 +194,74 @@ database "posthog" {}}+ table "log_attributes3" {+ order_by = ["team_id", "attribute_type", "time_bucket", "resource_fingerprint", "attribute_key", "attribute_value", "severity_text"]+ partition_by = "toDate(original_expiry_time_bucket)"+ ttl = "original_expiry_time_bucket"+ settings = {+ deduplicate_merge_projection_mode = "drop"+ index_granularity = "8192"+ }+ column "team_id" {+ type = "Int32"+ }+ column "time_bucket" {+ type = "DateTime64(0)"+ }+ column "service_name" {+ type = "LowCardinality(String)"+ }+ column "resource_fingerprint" {+ type = "UInt64"+ default = "0"+ }+ column "attribute_key" {+ type = "LowCardinality(String)"+ }+ column "attribute_value" {+ type = "String"+ codec = "ZSTD(5)"+ }+ column "attribute_count" {+ type = "SimpleAggregateFunction(sum, UInt64)"+ }+ column "attribute_type" {+ type = "LowCardinality(String)"+ default = "'log'"+ }+ column "original_expiry_time_bucket" {+ type = "DateTime"+ default = "now()"+ }+ column "severity_text" {+ type = "LowCardinality(String)"+ }+ index "idx_attribute_key" {+ expr = "attribute_key"+ type = "bloom_filter(0.01)"+ granularity = 1+ }+ index "idx_attribute_value" {+ expr = "attribute_value"+ type = "bloom_filter(0.01)"+ granularity = 1+ }+ index "idx_attribute_key_n3" {+ expr = "attribute_key"+ type = "ngrambf_v1(3, 32768, 3, 0)"+ granularity = 1+ }+ index "idx_attribute_value_n3" {+ expr = "attribute_value"+ type = "ngrambf_v1(3, 32768, 3, 0)"+ granularity = 1+ }+ engine "replicated_aggregating_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.log_attributes3"+ replica_name = "{replica}-{shard}"+ }+ }+table "log_attributes_distributed" {column "team_id" {type = "Int32"@@ -679,6 +750,215 @@ database "posthog" {}}+ table "metric_samples" {+ column "team_id" {+ type = "Int32"+ }+ column "metric_name" {+ type = "LowCardinality(String)"+ }+ column "series_fingerprint" {+ type = "UInt64"+ codec = "DoubleDelta"+ }+ column "timestamp" {+ type = "DateTime64(6)"+ codec = "DoubleDelta"+ }+ column "value" {+ type = "Float64"+ codec = "Gorilla(8)"+ }+ column "count" {+ type = "UInt64"+ default = "1"+ }+ column "histogram_bounds" {+ type = "Array(Float64)"+ }+ column "histogram_counts" {+ type = "Array(UInt64)"+ }+ column "trace_id" {+ type = "String"+ }+ column "span_id" {+ type = "String"+ }+ column "trace_flags" {+ type = "Int32"+ }+ engine "distributed" {+ cluster_name = "logs"+ remote_database = "posthog"+ remote_table = "metric_samples1"+ }+ }++ table "metric_samples1" {+ order_by = ["team_id", "metric_name", "series_fingerprint", "timestamp"]+ partition_by = "toDate(timestamp)"+ ttl = "toDateTime(timestamp) + toIntervalDay(30)"+ settings = {+ index_granularity = "8192"+ ttl_only_drop_parts = "1"+ }+ column "team_id" {+ type = "Int32"+ }+ column "metric_name" {+ type = "LowCardinality(String)"+ }+ column "series_fingerprint" {+ type = "UInt64"+ codec = "DoubleDelta"+ }+ column "timestamp" {+ type = "DateTime64(6)"+ codec = "DoubleDelta"+ }+ column "value" {+ type = "Float64"+ codec = "Gorilla(8)"+ }+ column "count" {+ type = "UInt64"+ default = "1"+ }+ column "histogram_bounds" {+ type = "Array(Float64)"+ }+ column "histogram_counts" {+ type = "Array(UInt64)"+ }+ column "trace_id" {+ type = "String"+ }+ column "span_id" {+ type = "String"+ }+ column "trace_flags" {+ type = "Int32"+ }+ index "idx_trace_id_bf" {+ expr = "trace_id"+ type = "bloom_filter(0.01)"+ granularity = 1+ }+ engine "replicated_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.metric_samples1"+ replica_name = "{replica}-{shard}"+ }+ }++ table "metric_series" {+ column "team_id" {+ type = "Int32"+ }+ column "metric_name" {+ type = "LowCardinality(String)"+ }+ column "series_fingerprint" {+ type = "UInt64"+ codec = "DoubleDelta"+ }+ column "metric_type" {+ type = "LowCardinality(String)"+ }+ column "unit" {+ type = "LowCardinality(String)"+ }+ column "aggregation_temporality" {+ type = "LowCardinality(String)"+ }+ column "is_monotonic" {+ type = "Bool"+ default = "false"+ }+ column "service_name" {+ type = "LowCardinality(String)"+ }+ column "resource_attributes" {+ type = "Map(LowCardinality(String), String)"+ }+ column "attributes" {+ type = "Map(LowCardinality(String), String)"+ }+ column "last_seen" {+ type = "DateTime64(6)"+ codec = "DoubleDelta"+ }+ engine "distributed" {+ cluster_name = "logs"+ remote_database = "posthog"+ remote_table = "metric_series1"+ }+ }++ table "metric_series1" {+ order_by = ["team_id", "metric_name", "series_fingerprint"]+ ttl = "toDateTime(last_seen) + toIntervalDay(90)"+ settings = {+ index_granularity = "8192"+ }+ column "team_id" {+ type = "Int32"+ }+ column "metric_name" {+ type = "LowCardinality(String)"+ }+ column "series_fingerprint" {+ type = "UInt64"+ codec = "DoubleDelta"+ }+ column "metric_type" {+ type = "LowCardinality(String)"+ }+ column "unit" {+ type = "LowCardinality(String)"+ }+ column "aggregation_temporality" {+ type = "LowCardinality(String)"+ }+ column "is_monotonic" {+ type = "Bool"+ default = "false"+ }+ column "service_name" {+ type = "LowCardinality(String)"+ }+ column "resource_attributes" {+ type = "Map(LowCardinality(String), String)"+ }+ column "attributes" {+ type = "Map(LowCardinality(String), String)"+ }+ column "last_seen" {+ type = "DateTime64(6)"+ codec = "DoubleDelta"+ }+ index "idx_service_set" {+ expr = "service_name"+ type = "set(1000)"+ granularity = 1+ }+ index "idx_attr_keys" {+ expr = "mapKeys(attributes)"+ type = "bloom_filter(0.01)"+ granularity = 1+ }+ index "idx_attr_values" {+ expr = "mapValues(attributes)"+ type = "bloom_filter(0.01)"+ granularity = 1+ }+ engine "replicated_replacing_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.metric_series1"+ replica_name = "{replica}-{shard}"+ version_column = "last_seen"+ }+ }+table "metrics" {column "time_bucket" {type = "DateTime"@@ -1756,6 +2036,73 @@ SQL}}+ materialized_view "logs34_to_log_attributes3" {+ to_table = "posthog.log_attributes3"+ query = <<SQL+SELECT+ team_id,+ time_bucket,+ original_expiry_time_bucket,+ service_name,+ resource_fingerprint,+ attribute_key,+ attribute_value,+ attribute_type,+ severity_text,+ attribute_count+FROM+ (+ SELECT+ team_id AS team_id,+ toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,+ toStartOfInterval(original_expiry_timestamp, toIntervalMinute(10)) AS original_expiry_time_bucket,+ service_name AS service_name,+ resource_fingerprint,+ severity_text AS severity_text,+ mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS attributes,+ arrayJoin(attributes) AS attribute,+ 'log' AS attribute_type,+ attribute.1 AS attribute_key,+ attribute.2 AS attribute_value,+ sumSimpleState(1) AS attribute_count+ FROM posthog.logs34+ GROUP BY+ team_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, attributes+ )+SQL++ column "team_id" {+ type = "Int32"+ }+ column "time_bucket" {+ type = "DateTime64(0)"+ }+ column "original_expiry_time_bucket" {+ type = "DateTime64(0)"+ }+ column "service_name" {+ type = "LowCardinality(String)"+ }+ column "resource_fingerprint" {+ type = "UInt64"+ }+ column "attribute_key" {+ type = "LowCardinality(String)"+ }+ column "attribute_value" {+ type = "String"+ }+ column "attribute_type" {+ type = "LowCardinality(String)"+ }+ column "severity_text" {+ type = "LowCardinality(String)"+ }+ column "attribute_count" {+ type = "SimpleAggregateFunction(sum, UInt64)"+ }+ }+materialized_view "logs34_to_resource_attributes" {to_table = "posthog.log_attributes2"query = <<SQL@@ -1817,6 +2164,72 @@ SQL}}+ materialized_view "logs34_to_resource_attributes3" {+ to_table = "posthog.log_attributes3"+ query = <<SQL+SELECT+ team_id,+ time_bucket,+ original_expiry_time_bucket,+ service_name,+ resource_fingerprint,+ attribute_key,+ attribute_value,+ attribute_type,+ severity_text,+ attribute_count+FROM+ (+ SELECT+ team_id AS team_id,+ toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,+ toStartOfInterval(original_expiry_timestamp, toIntervalMinute(10)) AS original_expiry_time_bucket,+ service_name AS service_name,+ resource_fingerprint,+ severity_text AS severity_text,+ arrayJoin(resource_attributes) AS attribute,+ 'resource' AS attribute_type,+ attribute.1 AS attribute_key,+ attribute.2 AS attribute_value,+ sumSimpleState(1) AS attribute_count+ FROM posthog.logs34+ GROUP BY+ team_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, resource_attributes+ )+SQL++ column "team_id" {+ type = "Int32"+ }+ column "time_bucket" {+ type = "DateTime64(0)"+ }+ column "original_expiry_time_bucket" {+ type = "DateTime64(0)"+ }+ column "service_name" {+ type = "LowCardinality(String)"+ }+ column "resource_fingerprint" {+ type = "UInt64"+ }+ column "attribute_key" {+ type = "LowCardinality(String)"+ }+ column "attribute_value" {+ type = "String"+ }+ column "attribute_type" {+ type = "LowCardinality(String)"+ }+ column "severity_text" {+ type = "LowCardinality(String)"+ }+ column "attribute_count" {+ type = "SimpleAggregateFunction(sum, UInt64)"+ }+ }+materialized_view "metrics1_to_metric_attributes" {to_table = "posthog.metric_attributes"query = <<SQLdiff --git a/posthog/clickhouse/hcl/golden/local-logs.hcl b/posthog/clickhouse/hcl/golden/local-logs.hclindex 570c1bb9ae9c..8ecd54aa5065 100644--- a/posthog/clickhouse/hcl/golden/local-logs.hcl+++ b/posthog/clickhouse/hcl/golden/local-logs.hcl@@ -1027,6 +1027,16 @@ database "posthog" {type = "Float64"codec = "Gorilla(8)"}+ column "count" {+ type = "UInt64"+ default = "1"+ }+ column "histogram_bounds" {+ type = "Array(Float64)"+ }+ column "histogram_counts" {+ type = "Array(UInt64)"+ }column "trace_id" {type = "String"}@@ -1069,6 +1079,16 @@ database "posthog" {type = "Float64"codec = "Gorilla(8)"}+ column "count" {+ type = "UInt64"+ default = "1"+ }+ column "histogram_bounds" {+ type = "Array(Float64)"+ }+ column "histogram_counts" {+ type = "Array(UInt64)"+ }column "trace_id" {type = "String"}@@ -1106,6 +1126,13 @@ database "posthog" {column "unit" {type = "LowCardinality(String)"}+ column "aggregation_temporality" {+ type = "LowCardinality(String)"+ }+ column "is_monotonic" {+ type = "Bool"+ default = "false"+ }column "service_name" {type = "LowCardinality(String)"}@@ -1128,6 +1155,7 @@ database "posthog" {table "metric_series1" {order_by = ["team_id", "metric_name", "series_fingerprint"]+ ttl = "toDateTime(last_seen) + toIntervalDay(90)"settings = {index_granularity = "8192"}@@ -1147,6 +1175,13 @@ database "posthog" {column "unit" {type = "LowCardinality(String)"}+ column "aggregation_temporality" {+ type = "LowCardinality(String)"+ }+ column "is_monotonic" {+ type = "Bool"+ default = "false"+ }column "service_name" {type = "LowCardinality(String)"}diff --git a/posthog/clickhouse/hcl/golden/prod-eu-logs.hcl b/posthog/clickhouse/hcl/golden/prod-eu-logs.hclindex d1fad006a2ec..a5abc59e3773 100644--- a/posthog/clickhouse/hcl/golden/prod-eu-logs.hcl+++ b/posthog/clickhouse/hcl/golden/prod-eu-logs.hcl@@ -116,6 +116,9 @@ database "posthog" {column "attributes" {type = "Map(String, String)"}+ column "series_fingerprint" {+ type = "Nullable(Int64)"+ }engine "kafka" {broker_list = "warpstream_metrics"topic_list = "kafka_topic_list = 'clickhouse_metrics'"@@ -271,6 +274,74 @@ database "posthog" {}}+ table "log_attributes3" {+ order_by = ["team_id", "attribute_type", "time_bucket", "resource_fingerprint", "attribute_key", "attribute_value", "severity_text"]+ partition_by = "toDate(original_expiry_time_bucket)"+ ttl = "original_expiry_time_bucket"+ settings = {+ deduplicate_merge_projection_mode = "drop"+ index_granularity = "8192"+ }+ column "team_id" {+ type = "Int32"+ }+ column "time_bucket" {+ type = "DateTime64(0)"+ }+ column "service_name" {+ type = "LowCardinality(String)"+ }+ column "resource_fingerprint" {+ type = "UInt64"+ default = "0"+ }+ column "attribute_key" {+ type = "LowCardinality(String)"+ }+ column "attribute_value" {+ type = "String"+ codec = "ZSTD(5)"+ }+ column "attribute_count" {+ type = "SimpleAggregateFunction(sum, UInt64)"+ }+ column "attribute_type" {+ type = "LowCardinality(String)"+ default = "'log'"+ }+ column "original_expiry_time_bucket" {+ type = "DateTime"+ default = "now()"+ }+ column "severity_text" {+ type = "LowCardinality(String)"+ }+ index "idx_attribute_key" {+ expr = "attribute_key"+ type = "bloom_filter(0.01)"+ granularity = 1+ }+ index "idx_attribute_value" {+ expr = "attribute_value"+ type = "bloom_filter(0.01)"+ granularity = 1+ }+ index "idx_attribute_key_n3" {+ expr = "attribute_key"+ type = "ngrambf_v1(3, 32768, 3, 0)"+ granularity = 1+ }+ index "idx_attribute_value_n3" {+ expr = "attribute_value"+ type = "ngrambf_v1(3, 32768, 3, 0)"+ granularity = 1+ }+ engine "replicated_aggregating_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.log_attributes3"+ replica_name = "{replica}-{shard}"+ }+ }+table "log_attributes_distributed" {column "team_id" {type = "Int32"@@ -289,7 +360,8 @@ database "posthog" {type = "LowCardinality(String)"}column "attribute_value" {- type = "String"+ type = "String"+ codec = "ZSTD(5)"}column "attribute_count" {type = "SimpleAggregateFunction(sum, UInt64)"@@ -552,7 +624,8 @@ database "posthog" {type = "Int32"}column "timestamp" {- type = "DateTime64(6)"+ type = "DateTime64(6)"+ codec = "DoubleDelta"}column "observed_timestamp" {type = "DateTime64(6)"@@ -758,6 +831,215 @@ database "posthog" {}}+ table "metric_samples" {+ column "team_id" {+ type = "Int32"+ }+ column "metric_name" {+ type = "LowCardinality(String)"+ }+ column "series_fingerprint" {+ type = "UInt64"+ codec = "DoubleDelta"+ }+ column "timestamp" {+ type = "DateTime64(6)"+ codec = "DoubleDelta"+ }+ column "value" {+ type = "Float64"+ codec = "Gorilla(8)"+ }+ column "count" {+ type = "UInt64"+ default = "1"+ }+ column "histogram_bounds" {+ type = "Array(Float64)"+ }+ column "histogram_counts" {+ type = "Array(UInt64)"+ }+ column "trace_id" {+ type = "String"+ }+ column "span_id" {+ type = "String"+ }+ column "trace_flags" {+ type = "Int32"+ }+ engine "distributed" {+ cluster_name = "logs"+ remote_database = "posthog"+ remote_table = "metric_samples1"+ }+ }++ table "metric_samples1" {+ order_by = ["team_id", "metric_name", "series_fingerprint", "timestamp"]+ partition_by = "toDate(timestamp)"+ ttl = "toDateTime(timestamp) + toIntervalDay(30)"+ settings = {+ index_granularity = "8192"+ ttl_only_drop_parts = "1"+ }+ column "team_id" {+ type = "Int32"+ }+ column "metric_name" {+ type = "LowCardinality(String)"+ }+ column "series_fingerprint" {+ type = "UInt64"+ codec = "DoubleDelta"+ }+ column "timestamp" {+ type = "DateTime64(6)"+ codec = "DoubleDelta"+ }+ column "value" {+ type = "Float64"+ codec = "Gorilla(8)"+ }+ column "count" {+ type = "UInt64"+ default = "1"+ }+ column "histogram_bounds" {+ type = "Array(Float64)"+ }+ column "histogram_counts" {+ type = "Array(UInt64)"+ }+ column "trace_id" {+ type = "String"+ }+ column "span_id" {+ type = "String"+ }+ column "trace_flags" {+ type = "Int32"+ }+ index "idx_trace_id_bf" {+ expr = "trace_id"+ type = "bloom_filter(0.01)"+ granularity = 1+ }+ engine "replicated_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.metric_samples1"+ replica_name = "{replica}-{shard}"+ }+ }++ table "metric_series" {+ column "team_id" {+ type = "Int32"+ }+ column "metric_name" {+ type = "LowCardinality(String)"+ }+ column "series_fingerprint" {+ type = "UInt64"+ codec = "DoubleDelta"+ }+ column "metric_type" {+ type = "LowCardinality(String)"+ }+ column "unit" {+ type = "LowCardinality(String)"+ }+ column "aggregation_temporality" {+ type = "LowCardinality(String)"+ }+ column "is_monotonic" {+ type = "Bool"+ default = "false"+ }+ column "service_name" {+ type = "LowCardinality(String)"+ }+ column "resource_attributes" {+ type = "Map(LowCardinality(String), String)"+ }+ column "attributes" {+ type = "Map(LowCardinality(String), String)"+ }+ column "last_seen" {+ type = "DateTime64(6)"+ codec = "DoubleDelta"+ }+ engine "distributed" {+ cluster_name = "logs"+ remote_database = "posthog"+ remote_table = "metric_series1"+ }+ }++ table "metric_series1" {+ order_by = ["team_id", "metric_name", "series_fingerprint"]+ ttl = "toDateTime(last_seen) + toIntervalDay(90)"+ settings = {+ index_granularity = "8192"+ }+ column "team_id" {+ type = "Int32"+ }+ column "metric_name" {+ type = "LowCardinality(String)"+ }+ column "series_fingerprint" {+ type = "UInt64"+ codec = "DoubleDelta"+ }+ column "metric_type" {+ type = "LowCardinality(String)"+ }+ column "unit" {+ type = "LowCardinality(String)"+ }+ column "aggregation_temporality" {+ type = "LowCardinality(String)"+ }+ column "is_monotonic" {+ type = "Bool"+ default = "false"+ }+ column "service_name" {+ type = "LowCardinality(String)"+ }+ column "resource_attributes" {+ type = "Map(LowCardinality(String), String)"+ }+ column "attributes" {+ type = "Map(LowCardinality(String), String)"+ }+ column "last_seen" {+ type = "DateTime64(6)"+ codec = "DoubleDelta"+ }+ index "idx_service_set" {+ expr = "service_name"+ type = "set(1000)"+ granularity = 1+ }+ index "idx_attr_keys" {+ expr = "mapKeys(attributes)"+ type = "bloom_filter(0.01)"+ granularity = 1+ }+ index "idx_attr_values" {+ expr = "mapValues(attributes)"+ type = "bloom_filter(0.01)"+ granularity = 1+ }+ engine "replicated_replacing_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.metric_series1"+ replica_name = "{replica}-{shard}"+ version_column = "last_seen"+ }+ }+table "metrics" {column "time_bucket" {type = "DateTime"@@ -2187,6 +2469,120 @@ SQL}}+ materialized_view "kafka_metrics_avro_to_metric_samples" {+ to_table = "posthog.metric_samples1"+ query = <<SQL+SELECT+ toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,+ ifNull(metric_name, '') AS metric_name,+ reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,+ timestamp,+ ifNull(value, 0) AS value,+ toUInt64(ifNull(count, 1)) AS count,+ histogram_bounds,+ arrayMap(x -> toUInt64(x), histogram_counts) AS histogram_counts,+ trace_id,+ span_id,+ ifNull(trace_flags, 0) AS trace_flags+FROM posthog.kafka_metrics_avro+WHERE kafka_metrics_avro.series_fingerprint IS NOT NULL+SETTINGS+ min_insert_block_size_rows = 0,+ min_insert_block_size_bytes = 0+SQL++ column "team_id" {+ type = "Int32"+ }+ column "metric_name" {+ type = "String"+ }+ column "series_fingerprint" {+ type = "UInt64"+ }+ column "timestamp" {+ type = "DateTime64(6)"+ }+ column "value" {+ type = "Float64"+ }+ column "count" {+ type = "UInt64"+ }+ column "histogram_bounds" {+ type = "Array(Float64)"+ }+ column "histogram_counts" {+ type = "Array(UInt64)"+ }+ column "trace_id" {+ type = "String"+ }+ column "span_id" {+ type = "String"+ }+ column "trace_flags" {+ type = "Int32"+ }+ }++ materialized_view "kafka_metrics_avro_to_metric_series" {+ to_table = "posthog.metric_series1"+ query = <<SQL+SELECT+ toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,+ ifNull(metric_name, '') AS metric_name,+ reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,+ ifNull(metric_type, '') AS metric_type,+ ifNull(unit, '') AS unit,+ ifNull(aggregation_temporality, '') AS aggregation_temporality,+ ifNull(is_monotonic, 0) AS is_monotonic,+ ifNull(service_name, '') AS service_name,+ mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)) AS resource_attributes,+ mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), attributes)) AS attributes,+ timestamp AS last_seen+FROM posthog.kafka_metrics_avro+WHERE kafka_metrics_avro.series_fingerprint IS NOT NULL+SETTINGS+ min_insert_block_size_rows = 0,+ min_insert_block_size_bytes = 0+SQL++ column "team_id" {+ type = "Int32"+ }+ column "metric_name" {+ type = "String"+ }+ column "series_fingerprint" {+ type = "UInt64"+ }+ column "metric_type" {+ type = "String"+ }+ column "unit" {+ type = "String"+ }+ column "aggregation_temporality" {+ type = "String"+ }+ column "is_monotonic" {+ type = "UInt8"+ }+ column "service_name" {+ type = "String"+ }+ column "resource_attributes" {+ type = "Map(String, String)"+ }+ column "attributes" {+ type = "Map(String, String)"+ }+ column "last_seen" {+ type = "DateTime64(6)"+ }+ }+materialized_view "kafka_trace_spans_avro_mv" {to_table = "posthog.trace_spans"query = <<SQL@@ -2340,6 +2736,73 @@ SQL}}+ materialized_view "logs34_to_log_attributes3" {+ to_table = "posthog.log_attributes3"+ query = <<SQL+SELECT+ team_id,+ time_bucket,+ original_expiry_time_bucket,+ service_name,+ resource_fingerprint,+ attribute_key,+ attribute_value,+ attribute_type,+ severity_text,+ attribute_count+FROM+ (+ SELECT+ team_id AS team_id,+ toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,+ toStartOfInterval(original_expiry_timestamp, toIntervalMinute(10)) AS original_expiry_time_bucket,+ service_name AS service_name,+ resource_fingerprint,+ severity_text AS severity_text,+ mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS attributes,+ arrayJoin(attributes) AS attribute,+ 'log' AS attribute_type,+ attribute.1 AS attribute_key,+ attribute.2 AS attribute_value,+ sumSimpleState(1) AS attribute_count+ FROM posthog.logs34+ GROUP BY+ team_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, attributes+ )+SQL++ column "team_id" {+ type = "Int32"+ }+ column "time_bucket" {+ type = "DateTime64(0)"+ }+ column "original_expiry_time_bucket" {+ type = "DateTime64(0)"+ }+ column "service_name" {+ type = "LowCardinality(String)"+ }+ column "resource_fingerprint" {+ type = "UInt64"+ }+ column "attribute_key" {+ type = "LowCardinality(String)"+ }+ column "attribute_value" {+ type = "String"+ }+ column "attribute_type" {+ type = "LowCardinality(String)"+ }+ column "severity_text" {+ type = "LowCardinality(String)"+ }+ column "attribute_count" {+ type = "SimpleAggregateFunction(sum, UInt64)"+ }+ }+materialized_view "logs34_to_resource_attributes" {to_table = "posthog.log_attributes2"query = <<SQL@@ -2401,6 +2864,72 @@ SQL}}+ materialized_view "logs34_to_resource_attributes3" {+ to_table = "posthog.log_attributes3"+ query = <<SQL+SELECT+ team_id,+ time_bucket,+ original_expiry_time_bucket,+ service_name,+ resource_fingerprint,+ attribute_key,+ attribute_value,+ attribute_type,+ severity_text,+ attribute_count+FROM+ (+ SELECT+ team_id AS team_id,+ toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,+ toStartOfInterval(original_expiry_timestamp, toIntervalMinute(10)) AS original_expiry_time_bucket,+ service_name AS service_name,+ resource_fingerprint,+ severity_text AS severity_text,+ arrayJoin(resource_attributes) AS attribute,+ 'resource' AS attribute_type,+ attribute.1 AS attribute_key,+ attribute.2 AS attribute_value,+ sumSimpleState(1) AS attribute_count+ FROM posthog.logs34+ GROUP BY+ team_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, resource_attributes+ )+SQL++ column "team_id" {+ type = "Int32"+ }+ column "time_bucket" {+ type = "DateTime64(0)"+ }+ column "original_expiry_time_bucket" {+ type = "DateTime64(0)"+ }+ column "service_name" {+ type = "LowCardinality(String)"+ }+ column "resource_fingerprint" {+ type = "UInt64"+ }+ column "attribute_key" {+ type = "LowCardinality(String)"+ }+ column "attribute_value" {+ type = "String"+ }+ column "attribute_type" {+ type = "LowCardinality(String)"+ }+ column "severity_text" {+ type = "LowCardinality(String)"+ }+ column "attribute_count" {+ type = "SimpleAggregateFunction(sum, UInt64)"+ }+ }+materialized_view "metrics1_to_metric_attributes" {to_table = "posthog.metric_attributes"query = <<SQLdiff --git a/posthog/clickhouse/hcl/golden/prod-us-logs.hcl b/posthog/clickhouse/hcl/golden/prod-us-logs.hclindex f3a9566fc448..eb7d229f3d72 100644--- a/posthog/clickhouse/hcl/golden/prod-us-logs.hcl+++ b/posthog/clickhouse/hcl/golden/prod-us-logs.hcl@@ -113,6 +113,9 @@ database "posthog" {column "attributes" {type = "Map(String, String)"}+ column "series_fingerprint" {+ type = "Nullable(Int64)"+ }engine "kafka" {broker_list = "warpstream_metrics"topic_list = "kafka_topic_list = 'clickhouse_metrics'"@@ -268,6 +271,74 @@ database "posthog" {}}+ table "log_attributes3" {+ order_by = ["team_id", "attribute_type", "time_bucket", "resource_fingerprint", "attribute_key", "attribute_value", "severity_text"]+ partition_by = "toDate(original_expiry_time_bucket)"+ ttl = "original_expiry_time_bucket"+ settings = {+ deduplicate_merge_projection_mode = "drop"+ index_granularity = "8192"+ }+ column "team_id" {+ type = "Int32"+ }+ column "time_bucket" {+ type = "DateTime64(0)"+ }+ column "service_name" {+ type = "LowCardinality(String)"+ }+ column "resource_fingerprint" {+ type = "UInt64"+ default = "0"+ }+ column "attribute_key" {+ type = "LowCardinality(String)"+ }+ column "attribute_value" {+ type = "String"+ codec = "ZSTD(5)"+ }+ column "attribute_count" {+ type = "SimpleAggregateFunction(sum, UInt64)"+ }+ column "attribute_type" {+ type = "LowCardinality(String)"+ default = "'log'"+ }+ column "original_expiry_time_bucket" {+ type = "DateTime"+ default = "now()"+ }+ column "severity_text" {+ type = "LowCardinality(String)"+ }+ index "idx_attribute_key" {+ expr = "attribute_key"+ type = "bloom_filter(0.01)"+ granularity = 1+ }+ index "idx_attribute_value" {+ expr = "attribute_value"+ type = "bloom_filter(0.01)"+ granularity = 1+ }+ index "idx_attribute_key_n3" {+ expr = "attribute_key"+ type = "ngrambf_v1(3, 32768, 3, 0)"+ granularity = 1+ }+ index "idx_attribute_value_n3" {+ expr = "attribute_value"+ type = "ngrambf_v1(3, 32768, 3, 0)"+ granularity = 1+ }+ engine "replicated_aggregating_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.log_attributes3"+ replica_name = "{replica}-{shard}"+ }+ }+table "log_attributes_distributed" {column "team_id" {type = "Int32"@@ -759,6 +830,215 @@ database "posthog" {}}+ table "metric_samples" {+ column "team_id" {+ type = "Int32"+ }+ column "metric_name" {+ type = "LowCardinality(String)"+ }+ column "series_fingerprint" {+ type = "UInt64"+ codec = "DoubleDelta"+ }+ column "timestamp" {+ type = "DateTime64(6)"+ codec = "DoubleDelta"+ }+ column "value" {+ type = "Float64"+ codec = "Gorilla(8)"+ }+ column "count" {+ type = "UInt64"+ default = "1"+ }+ column "histogram_bounds" {+ type = "Array(Float64)"+ }+ column "histogram_counts" {+ type = "Array(UInt64)"+ }+ column "trace_id" {+ type = "String"+ }+ column "span_id" {+ type = "String"+ }+ column "trace_flags" {+ type = "Int32"+ }+ engine "distributed" {+ cluster_name = "logs"+ remote_database = "posthog"+ remote_table = "metric_samples1"+ }+ }++ table "metric_samples1" {+ order_by = ["team_id", "metric_name", "series_fingerprint", "timestamp"]+ partition_by = "toDate(timestamp)"+ ttl = "toDateTime(timestamp) + toIntervalDay(30)"+ settings = {+ index_granularity = "8192"+ ttl_only_drop_parts = "1"+ }+ column "team_id" {+ type = "Int32"+ }+ column "metric_name" {+ type = "LowCardinality(String)"+ }+ column "series_fingerprint" {+ type = "UInt64"+ codec = "DoubleDelta"+ }+ column "timestamp" {+ type = "DateTime64(6)"+ codec = "DoubleDelta"+ }+ column "value" {+ type = "Float64"+ codec = "Gorilla(8)"+ }+ column "count" {+ type = "UInt64"+ default = "1"+ }+ column "histogram_bounds" {+ type = "Array(Float64)"+ }+ column "histogram_counts" {+ type = "Array(UInt64)"+ }+ column "trace_id" {+ type = "String"+ }+ column "span_id" {+ type = "String"+ }+ column "trace_flags" {+ type = "Int32"+ }+ index "idx_trace_id_bf" {+ expr = "trace_id"+ type = "bloom_filter(0.01)"+ granularity = 1+ }+ engine "replicated_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.metric_samples1"+ replica_name = "{replica}-{shard}"+ }+ }++ table "metric_series" {+ column "team_id" {+ type = "Int32"+ }+ column "metric_name" {+ type = "LowCardinality(String)"+ }+ column "series_fingerprint" {+ type = "UInt64"+ codec = "DoubleDelta"+ }+ column "metric_type" {+ type = "LowCardinality(String)"+ }+ column "unit" {+ type = "LowCardinality(String)"+ }+ column "aggregation_temporality" {+ type = "LowCardinality(String)"+ }+ column "is_monotonic" {+ type = "Bool"+ default = "false"+ }+ column "service_name" {+ type = "LowCardinality(String)"+ }+ column "resource_attributes" {+ type = "Map(LowCardinality(String), String)"+ }+ column "attributes" {+ type = "Map(LowCardinality(String), String)"+ }+ column "last_seen" {+ type = "DateTime64(6)"+ codec = "DoubleDelta"+ }+ engine "distributed" {+ cluster_name = "logs"+ remote_database = "posthog"+ remote_table = "metric_series1"+ }+ }++ table "metric_series1" {+ order_by = ["team_id", "metric_name", "series_fingerprint"]+ ttl = "toDateTime(last_seen) + toIntervalDay(90)"+ settings = {+ index_granularity = "8192"+ }+ column "team_id" {+ type = "Int32"+ }+ column "metric_name" {+ type = "LowCardinality(String)"+ }+ column "series_fingerprint" {+ type = "UInt64"+ codec = "DoubleDelta"+ }+ column "metric_type" {+ type = "LowCardinality(String)"+ }+ column "unit" {+ type = "LowCardinality(String)"+ }+ column "aggregation_temporality" {+ type = "LowCardinality(String)"+ }+ column "is_monotonic" {+ type = "Bool"+ default = "false"+ }+ column "service_name" {+ type = "LowCardinality(String)"+ }+ column "resource_attributes" {+ type = "Map(LowCardinality(String), String)"+ }+ column "attributes" {+ type = "Map(LowCardinality(String), String)"+ }+ column "last_seen" {+ type = "DateTime64(6)"+ codec = "DoubleDelta"+ }+ index "idx_service_set" {+ expr = "service_name"+ type = "set(1000)"+ granularity = 1+ }+ index "idx_attr_keys" {+ expr = "mapKeys(attributes)"+ type = "bloom_filter(0.01)"+ granularity = 1+ }+ index "idx_attr_values" {+ expr = "mapValues(attributes)"+ type = "bloom_filter(0.01)"+ granularity = 1+ }+ engine "replicated_replacing_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.metric_series1"+ replica_name = "{replica}-{shard}"+ version_column = "last_seen"+ }+ }+table "metrics" {column "time_bucket" {type = "DateTime"@@ -2202,6 +2482,120 @@ SQL}}+ materialized_view "kafka_metrics_avro_to_metric_samples" {+ to_table = "posthog.metric_samples1"+ query = <<SQL+SELECT+ toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,+ ifNull(metric_name, '') AS metric_name,+ reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,+ timestamp,+ ifNull(value, 0) AS value,+ toUInt64(ifNull(count, 1)) AS count,+ histogram_bounds,+ arrayMap(x -> toUInt64(x), histogram_counts) AS histogram_counts,+ trace_id,+ span_id,+ ifNull(trace_flags, 0) AS trace_flags+FROM posthog.kafka_metrics_avro+WHERE kafka_metrics_avro.series_fingerprint IS NOT NULL+SETTINGS+ min_insert_block_size_rows = 0,+ min_insert_block_size_bytes = 0+SQL++ column "team_id" {+ type = "Int32"+ }+ column "metric_name" {+ type = "String"+ }+ column "series_fingerprint" {+ type = "UInt64"+ }+ column "timestamp" {+ type = "DateTime64(6)"+ }+ column "value" {+ type = "Float64"+ }+ column "count" {+ type = "UInt64"+ }+ column "histogram_bounds" {+ type = "Array(Float64)"+ }+ column "histogram_counts" {+ type = "Array(UInt64)"+ }+ column "trace_id" {+ type = "String"+ }+ column "span_id" {+ type = "String"+ }+ column "trace_flags" {+ type = "Int32"+ }+ }++ materialized_view "kafka_metrics_avro_to_metric_series" {+ to_table = "posthog.metric_series1"+ query = <<SQL+SELECT+ toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,+ ifNull(metric_name, '') AS metric_name,+ reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,+ ifNull(metric_type, '') AS metric_type,+ ifNull(unit, '') AS unit,+ ifNull(aggregation_temporality, '') AS aggregation_temporality,+ ifNull(is_monotonic, 0) AS is_monotonic,+ ifNull(service_name, '') AS service_name,+ mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)) AS resource_attributes,+ mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), attributes)) AS attributes,+ timestamp AS last_seen+FROM posthog.kafka_metrics_avro+WHERE kafka_metrics_avro.series_fingerprint IS NOT NULL+SETTINGS+ min_insert_block_size_rows = 0,+ min_insert_block_size_bytes = 0+SQL++ column "team_id" {+ type = "Int32"+ }+ column "metric_name" {+ type = "String"+ }+ column "series_fingerprint" {+ type = "UInt64"+ }+ column "metric_type" {+ type = "String"+ }+ column "unit" {+ type = "String"+ }+ column "aggregation_temporality" {+ type = "String"+ }+ column "is_monotonic" {+ type = "UInt8"+ }+ column "service_name" {+ type = "String"+ }+ column "resource_attributes" {+ type = "Map(String, String)"+ }+ column "attributes" {+ type = "Map(String, String)"+ }+ column "last_seen" {+ type = "DateTime64(6)"+ }+ }+materialized_view "kafka_trace_spans_avro_mv" {to_table = "posthog.trace_spans"query = <<SQL@@ -2355,6 +2749,73 @@ SQL}}+ materialized_view "logs34_to_log_attributes3" {+ to_table = "posthog.log_attributes3"+ query = <<SQL+SELECT+ team_id,+ time_bucket,+ original_expiry_time_bucket,+ service_name,+ resource_fingerprint,+ attribute_key,+ attribute_value,+ attribute_type,+ severity_text,+ attribute_count+FROM+ (+ SELECT+ team_id AS team_id,+ toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,+ toStartOfInterval(original_expiry_timestamp, toIntervalMinute(10)) AS original_expiry_time_bucket,+ service_name AS service_name,+ resource_fingerprint,+ severity_text AS severity_text,+ mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS attributes,+ arrayJoin(attributes) AS attribute,+ 'log' AS attribute_type,+ attribute.1 AS attribute_key,+ attribute.2 AS attribute_value,+ sumSimpleState(1) AS attribute_count+ FROM posthog.logs34+ GROUP BY+ team_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, attributes+ )+SQL++ column "team_id" {+ type = "Int32"+ }+ column "time_bucket" {+ type = "DateTime64(0)"+ }+ column "original_expiry_time_bucket" {+ type = "DateTime64(0)"+ }+ column "service_name" {+ type = "LowCardinality(String)"+ }+ column "resource_fingerprint" {+ type = "UInt64"+ }+ column "attribute_key" {+ type = "LowCardinality(String)"+ }+ column "attribute_value" {+ type = "String"+ }+ column "attribute_type" {+ type = "LowCardinality(String)"+ }+ column "severity_text" {+ type = "LowCardinality(String)"+ }+ column "attribute_count" {+ type = "SimpleAggregateFunction(sum, UInt64)"+ }+ }+materialized_view "logs34_to_resource_attributes" {to_table = "posthog.log_attributes2"query = <<SQL@@ -2416,6 +2877,72 @@ SQL}}+ materialized_view "logs34_to_resource_attributes3" {+ to_table = "posthog.log_attributes3"+ query = <<SQL+SELECT+ team_id,+ time_bucket,+ original_expiry_time_bucket,+ service_name,+ resource_fingerprint,+ attribute_key,+ attribute_value,+ attribute_type,+ severity_text,+ attribute_count+FROM+ (+ SELECT+ team_id AS team_id,+ toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,+ toStartOfInterval(original_expiry_timestamp, toIntervalMinute(10)) AS original_expiry_time_bucket,+ service_name AS service_name,+ resource_fingerprint,+ severity_text AS severity_text,+ arrayJoin(resource_attributes) AS attribute,+ 'resource' AS attribute_type,+ attribute.1 AS attribute_key,+ attribute.2 AS attribute_value,+ sumSimpleState(1) AS attribute_count+ FROM posthog.logs34+ GROUP BY+ team_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, resource_attributes+ )+SQL++ column "team_id" {+ type = "Int32"+ }+ column "time_bucket" {+ type = "DateTime64(0)"+ }+ column "original_expiry_time_bucket" {+ type = "DateTime64(0)"+ }+ column "service_name" {+ type = "LowCardinality(String)"+ }+ column "resource_fingerprint" {+ type = "UInt64"+ }+ column "attribute_key" {+ type = "LowCardinality(String)"+ }+ column "attribute_value" {+ type = "String"+ }+ column "attribute_type" {+ type = "LowCardinality(String)"+ }+ column "severity_text" {+ type = "LowCardinality(String)"+ }+ column "attribute_count" {+ type = "SimpleAggregateFunction(sum, UInt64)"+ }+ }+materialized_view "metrics1_to_metric_attributes" {to_table = "posthog.metric_attributes"query = <<SQLdiff --git a/posthog/clickhouse/hcl/nodes b/posthog/clickhouse/hcl/nodesindex 6c02a9ee6c3f..018f219fb04d 100644--- a/posthog/clickhouse/hcl/nodes+++ b/posthog/clickhouse/hcl/nodes@@ -31,8 +31,8 @@ prod-eu ops roles/shared roles/ops/shared roles/ops/prod roles/ops/prod-local logs roles/logs/localdev logs roles/shared roles/logs/shared roles/logs/dev-prod-us logs roles/shared roles/logs/shared roles/logs/prod-us-prod-eu logs roles/shared roles/logs/shared roles/logs/prod-eu+prod-us logs roles/shared roles/logs/shared roles/logs/prod roles/logs/prod-us+prod-eu logs roles/shared roles/logs/shared roles/logs/prod roles/logs/prod-eu# AI_EVENTS satellite (LLM analytics). local/hobby run the MSK variant# (kafka_ai_events_json + ai_events_json_mv) with a sharded_ai_events data tablediff --git a/posthog/clickhouse/hcl/roles/logs/dev/tables.hcl b/posthog/clickhouse/hcl/roles/logs/dev/tables.hclindex 2f6156bb1030..6e57ac62447c 100644--- a/posthog/clickhouse/hcl/roles/logs/dev/tables.hcl+++ b/posthog/clickhouse/hcl/roles/logs/dev/tables.hcl@@ -147,44 +147,6 @@ database "posthog" {type = "SimpleAggregateFunction(sum, UInt64)"}}- table "log_attributes_distributed" {- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "resource_fingerprint" {- type = "UInt64"- default = "0"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- codec = "ZSTD(5)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- column "attribute_type" {- type = "LowCardinality(String)"- default = "'log'"- }- column "original_expiry_time_bucket" {- type = "DateTime"- default = "now()"- }- engine "distributed" {- cluster_name = "logs"- remote_database = "posthog"- remote_table = "log_attributes2"- }- }table "logs34" {order_by = ["team_id", "time_bucket", "service_name", "resource_fingerprint", "severity_text", "timestamp"]partition_by = "toDate(original_expiry_timestamp)"@@ -345,116 +307,6 @@ database "posthog" {replica_name = "{replica}"}}- table "logs_distributed" {- column "time_bucket" {- type = "DateTime"- materialized = "toStartOfDay(timestamp)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- column "uuid" {- type = "String"- }- column "team_id" {- type = "Int32"- }- column "trace_id" {- type = "String"- }- column "span_id" {- type = "String"- }- column "trace_flags" {- type = "Int32"- }- column "timestamp" {- type = "DateTime64(6)"- codec = "DoubleDelta"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "created_at" {- type = "DateTime64(6)"- materialized = "now()"- }- column "body" {- type = "String"- }- column "severity_text" {- type = "LowCardinality(String)"- }- column "severity_number" {- type = "Int32"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "resource_attributes" {- type = "Map(LowCardinality(String), String)"- }- column "resource_fingerprint" {- type = "UInt64"- materialized = "cityHash64(resource_attributes)"- }- column "instrumentation_scope" {- type = "String"- }- column "event_name" {- type = "String"- }- column "attributes_map_str" {- type = "Map(LowCardinality(String), String)"- }- column "level" {- type = "String"- alias = "severity_text"- }- column "mat_body_ipv4_matches" {- type = "Array(String)"- alias = "extractAll(body, '(\\\\d\\\\.((25[0-5]|(2[0-4]|1(0, 1)[0-9])(0, 1)[0-9])\\\\.)(2, 2)([0-9]))')"- }- column "time_minute" {- type = "DateTime"- alias = "toStartOfMinute(timestamp)"- }- column "attributes" {- type = "Map(LowCardinality(String), String)"- alias = "mapApply((k, v) -> (left(k, -5), v), attributes_map_str)"- }- column "attributes_map_float" {- type = "Map(LowCardinality(String), Float64)"- materialized = "mapFilter((k, v) -> (v IS NOT NULL), mapApply((k, v) -> (concat(left(k, -5), '__float'), toFloat64OrNull(v)), attributes_map_str))"- }- column "attributes_map_datetime" {- type = "Map(LowCardinality(String), DateTime64(6))"- materialized = "mapFilter((k, v) -> (v IS NOT NULL), mapApply((k, v) -> (concat(left(k, -5), '__datetime'), parseDateTimeBestEffortOrNull(v, 6)), attributes_map_str))"- }- column "_partition" {- type = "UInt32"- }- column "_topic" {- type = "String"- }- column "_offset" {- type = "UInt64"- }- column "_bytes_uncompressed" {- type = "UInt64"- }- column "_bytes_compressed" {- type = "UInt64"- }- column "_record_count" {- type = "UInt64"- }- engine "distributed" {- cluster_name = "logs"- remote_database = "posthog"- remote_table = "logs34"- }- }table "metrics" {column "time_bucket" {type = "DateTime"diff --git a/posthog/clickhouse/hcl/roles/logs/local/tables.hcl b/posthog/clickhouse/hcl/roles/logs/local/tables.hclindex 498ab62da04c..5ea28b2eefdf 100644--- a/posthog/clickhouse/hcl/roles/logs/local/tables.hcl+++ b/posthog/clickhouse/hcl/roles/logs/local/tables.hcl@@ -1014,6 +1014,16 @@ database "posthog" {type = "Float64"codec = "Gorilla(8)"}+ column "count" {+ type = "UInt64"+ default = "1"+ }+ column "histogram_bounds" {+ type = "Array(Float64)"+ }+ column "histogram_counts" {+ type = "Array(UInt64)"+ }column "trace_id" {type = "String"}@@ -1055,6 +1065,16 @@ database "posthog" {type = "Float64"codec = "Gorilla(8)"}+ column "count" {+ type = "UInt64"+ default = "1"+ }+ column "histogram_bounds" {+ type = "Array(Float64)"+ }+ column "histogram_counts" {+ type = "Array(UInt64)"+ }column "trace_id" {type = "String"}@@ -1091,6 +1111,13 @@ database "posthog" {column "unit" {type = "LowCardinality(String)"}+ column "aggregation_temporality" {+ type = "LowCardinality(String)"+ }+ column "is_monotonic" {+ type = "Bool"+ default = "false"+ }column "service_name" {type = "LowCardinality(String)"}@@ -1112,6 +1139,7 @@ database "posthog" {}table "metric_series1" {order_by = ["team_id", "metric_name", "series_fingerprint"]+ ttl = "toDateTime(last_seen) + toIntervalDay(90)"settings = {index_granularity = "8192"}@@ -1131,6 +1159,13 @@ database "posthog" {column "unit" {type = "LowCardinality(String)"}+ column "aggregation_temporality" {+ type = "LowCardinality(String)"+ }+ column "is_monotonic" {+ type = "Bool"+ default = "false"+ }column "service_name" {type = "LowCardinality(String)"}diff --git a/posthog/clickhouse/hcl/roles/logs/prod-eu/tables.hcl b/posthog/clickhouse/hcl/roles/logs/prod-eu/tables.hclindex add29fce0692..0f24d21e8174 100644--- a/posthog/clickhouse/hcl/roles/logs/prod-eu/tables.hcl+++ b/posthog/clickhouse/hcl/roles/logs/prod-eu/tables.hcl@@ -296,43 +296,6 @@ database "posthog" {type = "Int32"}}- table "log_attributes_distributed" {- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "resource_fingerprint" {- type = "UInt64"- default = "0"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- column "attribute_type" {- type = "LowCardinality(String)"- default = "'log'"- }- column "original_expiry_time_bucket" {- type = "DateTime"- default = "now()"- }- engine "distributed" {- cluster_name = "logs"- remote_database = "posthog"- remote_table = "log_attributes2"- }- }table "logs34" {order_by = ["team_id", "time_bucket", "service_name", "resource_fingerprint", "severity_text", "timestamp"]partition_by = "toDate(original_expiry_timestamp)"@@ -494,115 +457,6 @@ database "posthog" {replica_name = "{replica}"}}- table "logs_distributed" {- column "time_bucket" {- type = "DateTime"- materialized = "toStartOfDay(timestamp)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- column "uuid" {- type = "String"- }- column "team_id" {- type = "Int32"- }- column "trace_id" {- type = "String"- }- column "span_id" {- type = "String"- }- column "trace_flags" {- type = "Int32"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "created_at" {- type = "DateTime64(6)"- materialized = "now()"- }- column "body" {- type = "String"- }- column "severity_text" {- type = "LowCardinality(String)"- }- column "severity_number" {- type = "Int32"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "resource_attributes" {- type = "Map(LowCardinality(String), String)"- }- column "resource_fingerprint" {- type = "UInt64"- materialized = "cityHash64(resource_attributes)"- }- column "instrumentation_scope" {- type = "String"- }- column "event_name" {- type = "String"- }- column "attributes_map_str" {- type = "Map(LowCardinality(String), String)"- }- column "level" {- type = "String"- alias = "severity_text"- }- column "mat_body_ipv4_matches" {- type = "Array(String)"- alias = "extractAll(body, '(\\\\d\\\\.((25[0-5]|(2[0-4]|1(0, 1)[0-9])(0, 1)[0-9])\\\\.)(2, 2)([0-9]))')"- }- column "time_minute" {- type = "DateTime"- alias = "toStartOfMinute(timestamp)"- }- column "attributes" {- type = "Map(LowCardinality(String), String)"- alias = "mapApply((k, v) -> (left(k, -5), v), attributes_map_str)"- }- column "attributes_map_float" {- type = "Map(LowCardinality(String), Float64)"- materialized = "mapFilter((k, v) -> (v IS NOT NULL), mapApply((k, v) -> (concat(left(k, -5), '__float'), toFloat64OrNull(v)), attributes_map_str))"- }- column "attributes_map_datetime" {- type = "Map(LowCardinality(String), DateTime64(6))"- materialized = "mapFilter((k, v) -> (v IS NOT NULL), mapApply((k, v) -> (concat(left(k, -5), '__datetime'), parseDateTimeBestEffortOrNull(v, 6)), attributes_map_str))"- }- column "_partition" {- type = "UInt32"- }- column "_topic" {- type = "String"- }- column "_offset" {- type = "UInt64"- }- column "_bytes_uncompressed" {- type = "UInt64"- }- column "_bytes_compressed" {- type = "UInt64"- }- column "_record_count" {- type = "UInt64"- }- engine "distributed" {- cluster_name = "logs"- remote_database = "posthog"- remote_table = "logs34"- }- }table "metrics" {column "time_bucket" {type = "DateTime"diff --git a/posthog/clickhouse/hcl/roles/logs/prod-us/tables.hcl b/posthog/clickhouse/hcl/roles/logs/prod-us/tables.hclindex d6cfa22730dc..46cb71f9eae3 100644--- a/posthog/clickhouse/hcl/roles/logs/prod-us/tables.hcl+++ b/posthog/clickhouse/hcl/roles/logs/prod-us/tables.hcl@@ -293,44 +293,6 @@ database "posthog" {type = "Int32"}}- table "log_attributes_distributed" {- column "team_id" {- type = "Int32"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "resource_fingerprint" {- type = "UInt64"- default = "0"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- codec = "ZSTD(5)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- column "attribute_type" {- type = "LowCardinality(String)"- default = "'log'"- }- column "original_expiry_time_bucket" {- type = "DateTime"- default = "now()"- }- engine "distributed" {- cluster_name = "logs"- remote_database = "posthog"- remote_table = "log_attributes2"- }- }table "logs34" {order_by = ["team_id", "time_bucket", "service_name", "resource_fingerprint", "severity_text", "timestamp"]partition_by = "toDate(original_expiry_timestamp)"@@ -494,116 +456,6 @@ database "posthog" {replica_name = "{replica}"}}- table "logs_distributed" {- column "time_bucket" {- type = "DateTime"- materialized = "toStartOfDay(timestamp)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- column "uuid" {- type = "String"- }- column "team_id" {- type = "Int32"- }- column "trace_id" {- type = "String"- }- column "span_id" {- type = "String"- }- column "trace_flags" {- type = "Int32"- }- column "timestamp" {- type = "DateTime64(6)"- codec = "DoubleDelta"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "created_at" {- type = "DateTime64(6)"- materialized = "now()"- }- column "body" {- type = "String"- }- column "severity_text" {- type = "LowCardinality(String)"- }- column "severity_number" {- type = "Int32"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "resource_attributes" {- type = "Map(LowCardinality(String), String)"- }- column "resource_fingerprint" {- type = "UInt64"- materialized = "cityHash64(resource_attributes)"- }- column "instrumentation_scope" {- type = "String"- }- column "event_name" {- type = "String"- }- column "attributes_map_str" {- type = "Map(LowCardinality(String), String)"- }- column "level" {- type = "String"- alias = "severity_text"- }- column "mat_body_ipv4_matches" {- type = "Array(String)"- alias = "extractAll(body, '(\\\\d\\\\.((25[0-5]|(2[0-4]|1(0, 1)[0-9])(0, 1)[0-9])\\\\.)(2, 2)([0-9]))')"- }- column "time_minute" {- type = "DateTime"- alias = "toStartOfMinute(timestamp)"- }- column "attributes" {- type = "Map(LowCardinality(String), String)"- alias = "mapApply((k, v) -> (left(k, -5), v), attributes_map_str)"- }- column "attributes_map_float" {- type = "Map(LowCardinality(String), Float64)"- materialized = "mapFilter((k, v) -> (v IS NOT NULL), mapApply((k, v) -> (concat(left(k, -5), '__float'), toFloat64OrNull(v)), attributes_map_str))"- }- column "attributes_map_datetime" {- type = "Map(LowCardinality(String), DateTime64(6))"- materialized = "mapFilter((k, v) -> (v IS NOT NULL), mapApply((k, v) -> (concat(left(k, -5), '__datetime'), parseDateTimeBestEffortOrNull(v, 6)), attributes_map_str))"- }- column "_partition" {- type = "UInt32"- }- column "_topic" {- type = "String"- }- column "_offset" {- type = "UInt64"- }- column "_bytes_uncompressed" {- type = "UInt64"- }- column "_bytes_compressed" {- type = "UInt64"- }- column "_record_count" {- type = "UInt64"- }- engine "distributed" {- cluster_name = "logs"- remote_database = "posthog"- remote_table = "logs34"- }- }table "metrics" {column "time_bucket" {type = "DateTime"diff --git a/posthog/clickhouse/hcl/roles/logs/prod/sql/kafka_metrics_avro_to_metric_samples.sql b/posthog/clickhouse/hcl/roles/logs/prod/sql/kafka_metrics_avro_to_metric_samples.sqlnew file mode 100644index 000000000000..977ee9a7ea79--- /dev/null+++ b/posthog/clickhouse/hcl/roles/logs/prod/sql/kafka_metrics_avro_to_metric_samples.sql@@ -0,0 +1,17 @@+SELECT+ toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,+ ifNull(metric_name, '') AS metric_name,+ reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,+ timestamp,+ ifNull(value, 0) AS value,+ toUInt64(ifNull(count, 1)) AS count,+ histogram_bounds,+ arrayMap(x -> toUInt64(x), histogram_counts) AS histogram_counts,+ trace_id,+ span_id,+ ifNull(trace_flags, 0) AS trace_flags+FROM posthog.kafka_metrics_avro+WHERE kafka_metrics_avro.series_fingerprint IS NOT NULL+SETTINGS+ min_insert_block_size_rows = 0,+ min_insert_block_size_bytes = 0diff --git a/posthog/clickhouse/hcl/roles/logs/prod/sql/kafka_metrics_avro_to_metric_series.sql b/posthog/clickhouse/hcl/roles/logs/prod/sql/kafka_metrics_avro_to_metric_series.sqlnew file mode 100644index 000000000000..6297629b5a01--- /dev/null+++ b/posthog/clickhouse/hcl/roles/logs/prod/sql/kafka_metrics_avro_to_metric_series.sql@@ -0,0 +1,17 @@+SELECT+ toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,+ ifNull(metric_name, '') AS metric_name,+ reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,+ ifNull(metric_type, '') AS metric_type,+ ifNull(unit, '') AS unit,+ ifNull(aggregation_temporality, '') AS aggregation_temporality,+ ifNull(is_monotonic, 0) AS is_monotonic,+ ifNull(service_name, '') AS service_name,+ mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)) AS resource_attributes,+ mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), attributes)) AS attributes,+ timestamp AS last_seen+FROM posthog.kafka_metrics_avro+WHERE kafka_metrics_avro.series_fingerprint IS NOT NULL+SETTINGS+ min_insert_block_size_rows = 0,+ min_insert_block_size_bytes = 0diff --git a/posthog/clickhouse/hcl/roles/logs/prod/tables.hcl b/posthog/clickhouse/hcl/roles/logs/prod/tables.hclnew file mode 100644index 000000000000..c441e3db4f3e--- /dev/null+++ b/posthog/clickhouse/hcl/roles/logs/prod/tables.hcl@@ -0,0 +1,83 @@+# LOGS role, prod only — the Kafka metrics ingest MVs. Env-identical across+# prod-us / prod-eu (both read the WarpStream metrics_avro topic straight into the+# metric_samples1 / metric_series1 tables). Not present in dev/local, which have no+# metrics ingest path.++database "posthog" {+ materialized_view "kafka_metrics_avro_to_metric_samples" {+ to_table = "posthog.metric_samples1"+ query = file("sql/kafka_metrics_avro_to_metric_samples.sql")++ column "team_id" {+ type = "Int32"+ }+ column "metric_name" {+ type = "String"+ }+ column "series_fingerprint" {+ type = "UInt64"+ }+ column "timestamp" {+ type = "DateTime64(6)"+ }+ column "value" {+ type = "Float64"+ }+ column "count" {+ type = "UInt64"+ }+ column "histogram_bounds" {+ type = "Array(Float64)"+ }+ column "histogram_counts" {+ type = "Array(UInt64)"+ }+ column "trace_id" {+ type = "String"+ }+ column "span_id" {+ type = "String"+ }+ column "trace_flags" {+ type = "Int32"+ }+ }+ materialized_view "kafka_metrics_avro_to_metric_series" {+ to_table = "posthog.metric_series1"+ query = file("sql/kafka_metrics_avro_to_metric_series.sql")++ column "team_id" {+ type = "Int32"+ }+ column "metric_name" {+ type = "String"+ }+ column "series_fingerprint" {+ type = "UInt64"+ }+ column "metric_type" {+ type = "String"+ }+ column "unit" {+ type = "String"+ }+ column "aggregation_temporality" {+ type = "String"+ }+ column "is_monotonic" {+ type = "UInt8"+ }+ column "service_name" {+ type = "String"+ }+ column "resource_attributes" {+ type = "Map(String, String)"+ }+ column "attributes" {+ type = "Map(String, String)"+ }+ column "last_seen" {+ type = "DateTime64(6)"+ }+ }+}diff --git a/posthog/clickhouse/hcl/roles/logs/shared/sql/logs34_to_log_attributes3.sql b/posthog/clickhouse/hcl/roles/logs/shared/sql/logs34_to_log_attributes3.sqlnew file mode 100644index 000000000000..989c537e8b9f--- /dev/null+++ b/posthog/clickhouse/hcl/roles/logs/shared/sql/logs34_to_log_attributes3.sql@@ -0,0 +1,30 @@+SELECT+ team_id,+ time_bucket,+ original_expiry_time_bucket,+ service_name,+ resource_fingerprint,+ attribute_key,+ attribute_value,+ attribute_type,+ severity_text,+ attribute_count+FROM+ (+ SELECT+ team_id AS team_id,+ toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,+ toStartOfInterval(original_expiry_timestamp, toIntervalMinute(10)) AS original_expiry_time_bucket,+ service_name AS service_name,+ resource_fingerprint,+ severity_text AS severity_text,+ mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS attributes,+ arrayJoin(attributes) AS attribute,+ 'log' AS attribute_type,+ attribute.1 AS attribute_key,+ attribute.2 AS attribute_value,+ sumSimpleState(1) AS attribute_count+ FROM posthog.logs34+ GROUP BY+ team_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, attributes+ )diff --git a/posthog/clickhouse/hcl/roles/logs/shared/sql/logs34_to_resource_attributes3.sql b/posthog/clickhouse/hcl/roles/logs/shared/sql/logs34_to_resource_attributes3.sqlnew file mode 100644index 000000000000..3850352c660f--- /dev/null+++ b/posthog/clickhouse/hcl/roles/logs/shared/sql/logs34_to_resource_attributes3.sql@@ -0,0 +1,29 @@+SELECT+ team_id,+ time_bucket,+ original_expiry_time_bucket,+ service_name,+ resource_fingerprint,+ attribute_key,+ attribute_value,+ attribute_type,+ severity_text,+ attribute_count+FROM+ (+ SELECT+ team_id AS team_id,+ toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,+ toStartOfInterval(original_expiry_timestamp, toIntervalMinute(10)) AS original_expiry_time_bucket,+ service_name AS service_name,+ resource_fingerprint,+ severity_text AS severity_text,+ arrayJoin(resource_attributes) AS attribute,+ 'resource' AS attribute_type,+ attribute.1 AS attribute_key,+ attribute.2 AS attribute_value,+ sumSimpleState(1) AS attribute_count+ FROM posthog.logs34+ GROUP BY+ team_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, resource_attributes+ )diff --git a/posthog/clickhouse/hcl/roles/logs/shared/tables.hcl b/posthog/clickhouse/hcl/roles/logs/shared/tables.hclindex 8c051eb73466..db244351f7de 100644--- a/posthog/clickhouse/hcl/roles/logs/shared/tables.hcl+++ b/posthog/clickhouse/hcl/roles/logs/shared/tables.hcl@@ -86,6 +86,9 @@ database "posthog" {column "attributes" {type = "Map(String, String)"}+ column "series_fingerprint" {+ type = "Nullable(Int64)"+ }engine "kafka" {broker_list = "warpstream_metrics"topic_list = "kafka_topic_list = 'clickhouse_metrics'"@@ -575,4 +578,494 @@ database "posthog" {replica_name = "{replica}"}}+ table "log_attributes3" {+ order_by = ["team_id", "attribute_type", "time_bucket", "resource_fingerprint", "attribute_key", "attribute_value", "severity_text"]+ partition_by = "toDate(original_expiry_time_bucket)"+ ttl = "original_expiry_time_bucket"+ settings = {+ deduplicate_merge_projection_mode = "drop"+ index_granularity = "8192"+ }+ column "team_id" {+ type = "Int32"+ }+ column "time_bucket" {+ type = "DateTime64(0)"+ }+ column "service_name" {+ type = "LowCardinality(String)"+ }+ column "resource_fingerprint" {+ type = "UInt64"+ default = "0"+ }+ column "attribute_key" {+ type = "LowCardinality(String)"+ }+ column "attribute_value" {+ type = "String"+ codec = "ZSTD(5)"+ }+ column "attribute_count" {+ type = "SimpleAggregateFunction(sum, UInt64)"+ }+ column "attribute_type" {+ type = "LowCardinality(String)"+ default = "'log'"+ }+ column "original_expiry_time_bucket" {+ type = "DateTime"+ default = "now()"+ }+ column "severity_text" {+ type = "LowCardinality(String)"+ }+ index "idx_attribute_key" {+ expr = "attribute_key"+ type = "bloom_filter(0.01)"+ granularity = 1+ }+ index "idx_attribute_value" {+ expr = "attribute_value"+ type = "bloom_filter(0.01)"+ granularity = 1+ }+ index "idx_attribute_key_n3" {+ expr = "attribute_key"+ type = "ngrambf_v1(3, 32768, 3, 0)"+ granularity = 1+ }+ index "idx_attribute_value_n3" {+ expr = "attribute_value"+ type = "ngrambf_v1(3, 32768, 3, 0)"+ granularity = 1+ }+ engine "replicated_aggregating_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.log_attributes3"+ replica_name = "{replica}-{shard}"+ }+ }+ table "metric_samples" {+ column "team_id" {+ type = "Int32"+ }+ column "metric_name" {+ type = "LowCardinality(String)"+ }+ column "series_fingerprint" {+ type = "UInt64"+ codec = "DoubleDelta"+ }+ column "timestamp" {+ type = "DateTime64(6)"+ codec = "DoubleDelta"+ }+ column "value" {+ type = "Float64"+ codec = "Gorilla(8)"+ }+ column "count" {+ type = "UInt64"+ default = "1"+ }+ column "histogram_bounds" {+ type = "Array(Float64)"+ }+ column "histogram_counts" {+ type = "Array(UInt64)"+ }+ column "trace_id" {+ type = "String"+ }+ column "span_id" {+ type = "String"+ }+ column "trace_flags" {+ type = "Int32"+ }+ engine "distributed" {+ cluster_name = "logs"+ remote_database = "posthog"+ remote_table = "metric_samples1"+ }+ }+ table "metric_samples1" {+ order_by = ["team_id", "metric_name", "series_fingerprint", "timestamp"]+ partition_by = "toDate(timestamp)"+ ttl = "toDateTime(timestamp) + toIntervalDay(30)"+ settings = {+ index_granularity = "8192"+ ttl_only_drop_parts = "1"+ }+ column "team_id" {+ type = "Int32"+ }+ column "metric_name" {+ type = "LowCardinality(String)"+ }+ column "series_fingerprint" {+ type = "UInt64"+ codec = "DoubleDelta"+ }+ column "timestamp" {+ type = "DateTime64(6)"+ codec = "DoubleDelta"+ }+ column "value" {+ type = "Float64"+ codec = "Gorilla(8)"+ }+ column "count" {+ type = "UInt64"+ default = "1"+ }+ column "histogram_bounds" {+ type = "Array(Float64)"+ }+ column "histogram_counts" {+ type = "Array(UInt64)"+ }+ column "trace_id" {+ type = "String"+ }+ column "span_id" {+ type = "String"+ }+ column "trace_flags" {+ type = "Int32"+ }+ index "idx_trace_id_bf" {+ expr = "trace_id"+ type = "bloom_filter(0.01)"+ granularity = 1+ }+ engine "replicated_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.metric_samples1"+ replica_name = "{replica}-{shard}"+ }+ }+ table "metric_series" {+ column "team_id" {+ type = "Int32"+ }+ column "metric_name" {+ type = "LowCardinality(String)"+ }+ column "series_fingerprint" {+ type = "UInt64"+ codec = "DoubleDelta"+ }+ column "metric_type" {+ type = "LowCardinality(String)"+ }+ column "unit" {+ type = "LowCardinality(String)"+ }+ column "aggregation_temporality" {+ type = "LowCardinality(String)"+ }+ column "is_monotonic" {+ type = "Bool"+ default = "false"+ }+ column "service_name" {+ type = "LowCardinality(String)"+ }+ column "resource_attributes" {+ type = "Map(LowCardinality(String), String)"+ }+ column "attributes" {+ type = "Map(LowCardinality(String), String)"+ }+ column "last_seen" {+ type = "DateTime64(6)"+ codec = "DoubleDelta"+ }+ engine "distributed" {+ cluster_name = "logs"+ remote_database = "posthog"+ remote_table = "metric_series1"+ }+ }+ table "metric_series1" {+ order_by = ["team_id", "metric_name", "series_fingerprint"]+ ttl = "toDateTime(last_seen) + toIntervalDay(90)"+ settings = {+ index_granularity = "8192"+ }+ column "team_id" {+ type = "Int32"+ }+ column "metric_name" {+ type = "LowCardinality(String)"+ }+ column "series_fingerprint" {+ type = "UInt64"+ codec = "DoubleDelta"+ }+ column "metric_type" {+ type = "LowCardinality(String)"+ }+ column "unit" {+ type = "LowCardinality(String)"+ }+ column "aggregation_temporality" {+ type = "LowCardinality(String)"+ }+ column "is_monotonic" {+ type = "Bool"+ default = "false"+ }+ column "service_name" {+ type = "LowCardinality(String)"+ }+ column "resource_attributes" {+ type = "Map(LowCardinality(String), String)"+ }+ column "attributes" {+ type = "Map(LowCardinality(String), String)"+ }+ column "last_seen" {+ type = "DateTime64(6)"+ codec = "DoubleDelta"+ }+ index "idx_service_set" {+ expr = "service_name"+ type = "set(1000)"+ granularity = 1+ }+ index "idx_attr_keys" {+ expr = "mapKeys(attributes)"+ type = "bloom_filter(0.01)"+ granularity = 1+ }+ index "idx_attr_values" {+ expr = "mapValues(attributes)"+ type = "bloom_filter(0.01)"+ granularity = 1+ }+ engine "replicated_replacing_merge_tree" {+ zoo_path = "/clickhouse/tables/noshard/posthog.metric_series1"+ replica_name = "{replica}-{shard}"+ version_column = "last_seen"+ }+ }+ materialized_view "logs34_to_log_attributes3" {+ to_table = "posthog.log_attributes3"+ query = file("sql/logs34_to_log_attributes3.sql")++ column "team_id" {+ type = "Int32"+ }+ column "time_bucket" {+ type = "DateTime64(0)"+ }+ column "original_expiry_time_bucket" {+ type = "DateTime64(0)"+ }+ column "service_name" {+ type = "LowCardinality(String)"+ }+ column "resource_fingerprint" {+ type = "UInt64"+ }+ column "attribute_key" {+ type = "LowCardinality(String)"+ }+ column "attribute_value" {+ type = "String"+ }+ column "attribute_type" {+ type = "LowCardinality(String)"+ }+ column "severity_text" {+ type = "LowCardinality(String)"+ }+ column "attribute_count" {+ type = "SimpleAggregateFunction(sum, UInt64)"+ }+ }+ materialized_view "logs34_to_resource_attributes3" {+ to_table = "posthog.log_attributes3"+ query = file("sql/logs34_to_resource_attributes3.sql")++ column "team_id" {+ type = "Int32"+ }+ column "time_bucket" {+ type = "DateTime64(0)"+ }+ column "original_expiry_time_bucket" {+ type = "DateTime64(0)"+ }+ column "service_name" {+ type = "LowCardinality(String)"+ }+ column "resource_fingerprint" {+ type = "UInt64"+ }+ column "attribute_key" {+ type = "LowCardinality(String)"+ }+ column "attribute_value" {+ type = "String"+ }+ column "attribute_type" {+ type = "LowCardinality(String)"+ }+ column "severity_text" {+ type = "LowCardinality(String)"+ }+ column "attribute_count" {+ type = "SimpleAggregateFunction(sum, UInt64)"+ }+ }+ table "log_attributes_distributed" {+ column "team_id" {+ type = "Int32"+ }+ column "time_bucket" {+ type = "DateTime64(0)"+ }+ column "service_name" {+ type = "LowCardinality(String)"+ }+ column "resource_fingerprint" {+ type = "UInt64"+ default = "0"+ }+ column "attribute_key" {+ type = "LowCardinality(String)"+ }+ column "attribute_value" {+ type = "String"+ codec = "ZSTD(5)"+ }+ column "attribute_count" {+ type = "SimpleAggregateFunction(sum, UInt64)"+ }+ column "attribute_type" {+ type = "LowCardinality(String)"+ default = "'log'"+ }+ column "original_expiry_time_bucket" {+ type = "DateTime"+ default = "now()"+ }+ engine "distributed" {+ cluster_name = "logs"+ remote_database = "posthog"+ remote_table = "log_attributes2"+ }+ }+ table "logs_distributed" {+ column "time_bucket" {+ type = "DateTime"+ materialized = "toStartOfDay(timestamp)"+ }+ column "original_expiry_timestamp" {+ type = "DateTime64(6)"+ }+ column "uuid" {+ type = "String"+ }+ column "team_id" {+ type = "Int32"+ }+ column "trace_id" {+ type = "String"+ }+ column "span_id" {+ type = "String"+ }+ column "trace_flags" {+ type = "Int32"+ }+ column "timestamp" {+ type = "DateTime64(6)"+ codec = "DoubleDelta"+ }+ column "observed_timestamp" {+ type = "DateTime64(6)"+ }+ column "created_at" {+ type = "DateTime64(6)"+ materialized = "now()"+ }+ column "body" {+ type = "String"+ }+ column "severity_text" {+ type = "LowCardinality(String)"+ }+ column "severity_number" {+ type = "Int32"+ }+ column "service_name" {+ type = "LowCardinality(String)"+ }+ column "resource_attributes" {+ type = "Map(LowCardinality(String), String)"+ }+ column "resource_fingerprint" {+ type = "UInt64"+ materialized = "cityHash64(resource_attributes)"+ }+ column "instrumentation_scope" {+ type = "String"+ }+ column "event_name" {+ type = "String"+ }+ column "attributes_map_str" {+ type = "Map(LowCardinality(String), String)"+ }+ column "level" {+ type = "String"+ alias = "severity_text"+ }+ column "mat_body_ipv4_matches" {+ type = "Array(String)"+ alias = "extractAll(body, '(\\\\d\\\\.((25[0-5]|(2[0-4]|1(0, 1)[0-9])(0, 1)[0-9])\\\\.)(2, 2)([0-9]))')"+ }+ column "time_minute" {+ type = "DateTime"+ alias = "toStartOfMinute(timestamp)"+ }+ column "attributes" {+ type = "Map(LowCardinality(String), String)"+ alias = "mapApply((k, v) -> (left(k, -5), v), attributes_map_str)"+ }+ column "attributes_map_float" {+ type = "Map(LowCardinality(String), Float64)"+ materialized = "mapFilter((k, v) -> (v IS NOT NULL), mapApply((k, v) -> (concat(left(k, -5), '__float'), toFloat64OrNull(v)), attributes_map_str))"+ }+ column "attributes_map_datetime" {+ type = "Map(LowCardinality(String), DateTime64(6))"+ materialized = "mapFilter((k, v) -> (v IS NOT NULL), mapApply((k, v) -> (concat(left(k, -5), '__datetime'), parseDateTimeBestEffortOrNull(v, 6)), attributes_map_str))"+ }+ column "_partition" {+ type = "UInt32"+ }+ column "_topic" {+ type = "String"+ }+ column "_offset" {+ type = "UInt64"+ }+ column "_bytes_uncompressed" {+ type = "UInt64"+ }+ column "_bytes_compressed" {+ type = "UInt64"+ }+ column "_record_count" {+ type = "UInt64"+ }+ engine "distributed" {+ cluster_name = "logs"+ remote_database = "posthog"+ remote_table = "logs34"+ }+ }}diff --git a/posthog/clickhouse/hcl/sql/dev-logs.sql b/posthog/clickhouse/hcl/sql/dev-logs.sqlindex 5e8a5a7fa9f3..dac19cb54307 100644--- a/posthog/clickhouse/hcl/sql/dev-logs.sql+++ b/posthog/clickhouse/hcl/sql/dev-logs.sql@@ -36,7 +36,8 @@ CREATE TABLE posthog.kafka_metrics_avro (is_monotonic Nullable(UInt8),resource_attributes Map(String, String),instrumentation_scope Nullable(String),- attributes Map(String, String)+ attributes Map(String, String),+ series_fingerprint Nullable(Int64)) ENGINE = Kafka() SETTINGS kafka_broker_list = 'warpstream_metrics', kafka_format = 'kafka_format = \'Avro\'', kafka_group_name = 'kafka_group_name = \'clickhouse-metrics-avro-new\'', kafka_num_consumers = 8, kafka_poll_max_batch_size = 1000, kafka_poll_timeout_ms = 3000, kafka_skip_broken_messages = 100, kafka_thread_per_consumer = 1, kafka_topic_list = 'kafka_topic_list = \'clickhouse_metrics\'';CREATE TABLE posthog.log_attributes2 (team_id Int32,@@ -53,6 +54,22 @@ CREATE TABLE posthog.log_attributes2 (INDEX idx_attribute_key_n3 attribute_key TYPE ngrambf_v1(3, 32768, 3, 0) GRANULARITY 1,INDEX idx_attribute_value_n3 attribute_value TYPE ngrambf_v1(3, 32768, 3, 0) GRANULARITY 1) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/logs/{shard}/log_attributes34', '{replica}') ORDER BY (team_id, attribute_type, time_bucket, resource_fingerprint, attribute_key, attribute_value) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(15) SETTINGS deduplicate_merge_projection_mode = 'drop', index_granularity = 8192;+CREATE TABLE posthog.log_attributes3 (+ team_id Int32,+ time_bucket DateTime64(0),+ service_name LowCardinality(String),+ resource_fingerprint UInt64 DEFAULT 0,+ attribute_key LowCardinality(String),+ attribute_value String CODEC(ZSTD(5)),+ attribute_count SimpleAggregateFunction(sum, UInt64),+ attribute_type LowCardinality(String) DEFAULT 'log',+ original_expiry_time_bucket DateTime DEFAULT now(),+ severity_text LowCardinality(String),+ INDEX idx_attribute_key attribute_key TYPE bloom_filter(0.01) GRANULARITY 1,+ INDEX idx_attribute_value attribute_value TYPE bloom_filter(0.01) GRANULARITY 1,+ INDEX idx_attribute_key_n3 attribute_key TYPE ngrambf_v1(3, 32768, 3, 0) GRANULARITY 1,+ INDEX idx_attribute_value_n3 attribute_value TYPE ngrambf_v1(3, 32768, 3, 0) GRANULARITY 1+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.log_attributes3', '{replica}-{shard}') ORDER BY (team_id, attribute_type, time_bucket, resource_fingerprint, attribute_key, attribute_value, severity_text) PARTITION BY toDate(original_expiry_time_bucket) TTL original_expiry_time_bucket SETTINGS deduplicate_merge_projection_mode = 'drop', index_granularity = 8192;CREATE TABLE posthog.log_attributes_distributed (team_id Int32,time_bucket DateTime64(0),@@ -186,6 +203,36 @@ CREATE TABLE posthog.metric_attributes (INDEX idx_attribute_key_n3 attribute_key TYPE ngrambf_v1(3, 32768, 3, 0) GRANULARITY 1,INDEX idx_attribute_value_n3 attribute_value TYPE ngrambf_v1(3, 32768, 3, 0) GRANULARITY 1) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/logs/{shard}/posthog.metric_attributes', '{replica}') ORDER BY (team_id, attribute_type, time_bucket, resource_fingerprint, attribute_key, attribute_value) PARTITION BY toDate(time_bucket) SETTINGS deduplicate_merge_projection_mode = 'drop', index_granularity = 8192;+CREATE TABLE posthog.metric_samples1 (+ team_id Int32,+ metric_name LowCardinality(String),+ series_fingerprint UInt64 CODEC(DoubleDelta),+ timestamp DateTime64(6) CODEC(DoubleDelta),+ value Float64 CODEC(Gorilla(8)),+ count UInt64 DEFAULT 1,+ histogram_bounds Array(Float64),+ histogram_counts Array(UInt64),+ trace_id String,+ span_id String,+ trace_flags Int32,+ INDEX idx_trace_id_bf trace_id TYPE bloom_filter(0.01) GRANULARITY 1+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.metric_samples1', '{replica}-{shard}') ORDER BY (team_id, metric_name, series_fingerprint, timestamp) PARTITION BY toDate(timestamp) TTL toDateTime(timestamp) + toIntervalDay(30) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;+CREATE TABLE posthog.metric_series1 (+ team_id Int32,+ metric_name LowCardinality(String),+ series_fingerprint UInt64 CODEC(DoubleDelta),+ metric_type LowCardinality(String),+ unit LowCardinality(String),+ aggregation_temporality LowCardinality(String),+ is_monotonic Bool DEFAULT false,+ service_name LowCardinality(String),+ resource_attributes Map(LowCardinality(String), String),+ attributes Map(LowCardinality(String), String),+ last_seen DateTime64(6) CODEC(DoubleDelta),+ INDEX idx_service_set service_name TYPE set(1000) GRANULARITY 1,+ INDEX idx_attr_keys mapKeys(attributes) TYPE bloom_filter(0.01) GRANULARITY 1,+ INDEX idx_attr_values mapValues(attributes) TYPE bloom_filter(0.01) GRANULARITY 1+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.metric_series1', '{replica}-{shard}', last_seen) ORDER BY (team_id, metric_name, series_fingerprint) TTL toDateTime(last_seen) + toIntervalDay(90) SETTINGS index_granularity = 8192;CREATE TABLE posthog.metrics1 (time_bucket DateTime MATERIALIZED toStartOfDay(timestamp),uuid String,@@ -476,6 +523,36 @@ FROMGROUP BYteam_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, attributes);+CREATE MATERIALIZED VIEW posthog.logs34_to_log_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 SELECT+ team_id,+ time_bucket,+ original_expiry_time_bucket,+ service_name,+ resource_fingerprint,+ attribute_key,+ attribute_value,+ attribute_type,+ severity_text,+ attribute_count+FROM+ (+ SELECT+ team_id AS team_id,+ toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,+ toStartOfInterval(original_expiry_timestamp, toIntervalMinute(10)) AS original_expiry_time_bucket,+ service_name AS service_name,+ resource_fingerprint,+ severity_text AS severity_text,+ mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS attributes,+ arrayJoin(attributes) AS attribute,+ 'log' AS attribute_type,+ attribute.1 AS attribute_key,+ attribute.2 AS attribute_value,+ sumSimpleState(1) AS attribute_count+ FROM posthog.logs34+ GROUP BY+ team_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, attributes+ );CREATE MATERIALIZED VIEW posthog.logs34_to_resource_attributes TO posthog.log_attributes2 (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), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,time_bucket,@@ -503,6 +580,35 @@ FROMGROUP BYteam_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, resource_attributes);+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 SELECT+ team_id,+ time_bucket,+ original_expiry_time_bucket,+ service_name,+ resource_fingerprint,+ attribute_key,+ attribute_value,+ attribute_type,+ severity_text,+ attribute_count+FROM+ (+ SELECT+ team_id AS team_id,+ toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,+ toStartOfInterval(original_expiry_timestamp, toIntervalMinute(10)) AS original_expiry_time_bucket,+ service_name AS service_name,+ resource_fingerprint,+ severity_text AS severity_text,+ arrayJoin(resource_attributes) AS attribute,+ 'resource' AS attribute_type,+ attribute.1 AS attribute_key,+ attribute.2 AS attribute_value,+ sumSimpleState(1) AS attribute_count+ FROM posthog.logs34+ GROUP BY+ team_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, resource_attributes+ );CREATE MATERIALIZED VIEW posthog.metrics1_to_metric_attributes TO posthog.metric_attributes (team_id Int32, 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,time_bucket,@@ -690,6 +796,32 @@ CREATE VIEW posthog.custom_metrics_test AS SELECT1 AS value,'Test to check that the metric endpoint is working' AS help,'gauge' AS type;+CREATE TABLE posthog.metric_samples (+ team_id Int32,+ metric_name LowCardinality(String),+ series_fingerprint UInt64 CODEC(DoubleDelta),+ timestamp DateTime64(6) CODEC(DoubleDelta),+ value Float64 CODEC(Gorilla(8)),+ count UInt64 DEFAULT 1,+ histogram_bounds Array(Float64),+ histogram_counts Array(UInt64),+ trace_id String,+ span_id String,+ trace_flags Int32+) ENGINE = Distributed('logs', 'posthog', 'metric_samples1');+CREATE TABLE posthog.metric_series (+ team_id Int32,+ metric_name LowCardinality(String),+ series_fingerprint UInt64 CODEC(DoubleDelta),+ metric_type LowCardinality(String),+ unit LowCardinality(String),+ aggregation_temporality LowCardinality(String),+ is_monotonic Bool DEFAULT false,+ service_name LowCardinality(String),+ resource_attributes Map(LowCardinality(String), String),+ attributes Map(LowCardinality(String), String),+ last_seen DateTime64(6) CODEC(DoubleDelta)+) ENGINE = Distributed('logs', 'posthog', 'metric_series1');CREATE TABLE posthog.metrics (time_bucket DateTime MATERIALIZED toStartOfDay(timestamp),uuid String,diff --git a/posthog/clickhouse/hcl/sql/local-logs.sql b/posthog/clickhouse/hcl/sql/local-logs.sqlindex 9816912c71a0..fb8f59c633fc 100644--- a/posthog/clickhouse/hcl/sql/local-logs.sql+++ b/posthog/clickhouse/hcl/sql/local-logs.sql@@ -229,6 +229,9 @@ CREATE TABLE posthog.metric_samples1 (series_fingerprint UInt64 CODEC(DoubleDelta),timestamp DateTime64(6) CODEC(DoubleDelta),value Float64 CODEC(Gorilla(8)),+ count UInt64 DEFAULT 1,+ histogram_bounds Array(Float64),+ histogram_counts Array(UInt64),trace_id String,span_id String,trace_flags Int32,@@ -240,6 +243,8 @@ CREATE TABLE posthog.metric_series1 (series_fingerprint UInt64 CODEC(DoubleDelta),metric_type LowCardinality(String),unit LowCardinality(String),+ aggregation_temporality LowCardinality(String),+ is_monotonic Bool DEFAULT false,service_name LowCardinality(String),resource_attributes Map(LowCardinality(String), String),attributes Map(LowCardinality(String), String),@@ -247,7 +252,7 @@ CREATE TABLE posthog.metric_series1 (INDEX idx_service_set service_name TYPE set(1000) GRANULARITY 1,INDEX idx_attr_keys mapKeys(attributes) TYPE bloom_filter(0.01) GRANULARITY 1,INDEX idx_attr_values mapValues(attributes) TYPE bloom_filter(0.01) GRANULARITY 1-) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.metric_series1', '{replica}-{shard}', last_seen) ORDER BY (team_id, metric_name, series_fingerprint) SETTINGS index_granularity = 8192;+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.metric_series1', '{replica}-{shard}', last_seen) ORDER BY (team_id, metric_name, series_fingerprint) TTL toDateTime(last_seen) + toIntervalDay(90) SETTINGS index_granularity = 8192;CREATE TABLE posthog.query_log_archive (hostname LowCardinality(String),user LowCardinality(String),@@ -597,6 +602,9 @@ CREATE TABLE posthog.metric_samples (series_fingerprint UInt64 CODEC(DoubleDelta),timestamp DateTime64(6) CODEC(DoubleDelta),value Float64 CODEC(Gorilla(8)),+ count UInt64 DEFAULT 1,+ histogram_bounds Array(Float64),+ histogram_counts Array(UInt64),trace_id String,span_id String,trace_flags Int32@@ -607,6 +615,8 @@ CREATE TABLE posthog.metric_series (series_fingerprint UInt64 CODEC(DoubleDelta),metric_type LowCardinality(String),unit LowCardinality(String),+ aggregation_temporality LowCardinality(String),+ is_monotonic Bool DEFAULT false,service_name LowCardinality(String),resource_attributes Map(LowCardinality(String), String),attributes Map(LowCardinality(String), String),diff --git a/posthog/clickhouse/hcl/sql/prod-eu-logs.sql b/posthog/clickhouse/hcl/sql/prod-eu-logs.sqlindex af4ce4d704fd..1e5e7b293f13 100644--- a/posthog/clickhouse/hcl/sql/prod-eu-logs.sql+++ b/posthog/clickhouse/hcl/sql/prod-eu-logs.sql@@ -37,7 +37,8 @@ CREATE TABLE posthog.kafka_metrics_avro (is_monotonic Nullable(UInt8),resource_attributes Map(String, String),instrumentation_scope Nullable(String),- attributes Map(String, String)+ attributes Map(String, String),+ series_fingerprint Nullable(Int64)) ENGINE = Kafka() SETTINGS kafka_broker_list = 'warpstream_metrics', kafka_format = 'kafka_format = \'Avro\'', kafka_group_name = 'kafka_group_name = \'clickhouse-metrics-avro-new\'', kafka_num_consumers = 8, kafka_poll_max_batch_size = 1000, kafka_poll_timeout_ms = 3000, kafka_skip_broken_messages = 100, kafka_thread_per_consumer = 1, kafka_topic_list = 'kafka_topic_list = \'clickhouse_metrics\'';CREATE TABLE posthog.kafka_trace_spans_avro (uuid String,@@ -77,13 +78,29 @@ CREATE TABLE posthog.log_attributes2 (INDEX idx_attribute_key_n3 attribute_key TYPE ngrambf_v1(3, 32768, 3, 0) GRANULARITY 1,INDEX idx_attribute_value_n3 attribute_value TYPE ngrambf_v1(3, 32768, 3, 0) GRANULARITY 1) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/logs/{shard}/log_attributes34', '{replica}') ORDER BY (team_id, attribute_type, time_bucket, resource_fingerprint, attribute_key, attribute_value) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(15) SETTINGS deduplicate_merge_projection_mode = 'drop', index_granularity = 8192;+CREATE TABLE posthog.log_attributes3 (+ team_id Int32,+ time_bucket DateTime64(0),+ service_name LowCardinality(String),+ resource_fingerprint UInt64 DEFAULT 0,+ attribute_key LowCardinality(String),+ attribute_value String CODEC(ZSTD(5)),+ attribute_count SimpleAggregateFunction(sum, UInt64),+ attribute_type LowCardinality(String) DEFAULT 'log',+ original_expiry_time_bucket DateTime DEFAULT now(),+ severity_text LowCardinality(String),+ INDEX idx_attribute_key attribute_key TYPE bloom_filter(0.01) GRANULARITY 1,+ INDEX idx_attribute_value attribute_value TYPE bloom_filter(0.01) GRANULARITY 1,+ INDEX idx_attribute_key_n3 attribute_key TYPE ngrambf_v1(3, 32768, 3, 0) GRANULARITY 1,+ INDEX idx_attribute_value_n3 attribute_value TYPE ngrambf_v1(3, 32768, 3, 0) GRANULARITY 1+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.log_attributes3', '{replica}-{shard}') ORDER BY (team_id, attribute_type, time_bucket, resource_fingerprint, attribute_key, attribute_value, severity_text) PARTITION BY toDate(original_expiry_time_bucket) TTL original_expiry_time_bucket SETTINGS deduplicate_merge_projection_mode = 'drop', index_granularity = 8192;CREATE TABLE posthog.log_attributes_distributed (team_id Int32,time_bucket DateTime64(0),service_name LowCardinality(String),resource_fingerprint UInt64 DEFAULT 0,attribute_key LowCardinality(String),- attribute_value String,+ attribute_value String CODEC(ZSTD(5)),attribute_count SimpleAggregateFunction(sum, UInt64),attribute_type LowCardinality(String) DEFAULT 'log',original_expiry_time_bucket DateTime DEFAULT now()@@ -153,7 +170,7 @@ CREATE TABLE posthog.logs_distributed (trace_id String,span_id String,trace_flags Int32,- timestamp DateTime64(6),+ timestamp DateTime64(6) CODEC(DoubleDelta),observed_timestamp DateTime64(6),created_at DateTime64(6) MATERIALIZED now(),body String,@@ -210,6 +227,36 @@ CREATE TABLE posthog.metric_attributes (INDEX idx_attribute_key_n3 attribute_key TYPE ngrambf_v1(3, 32768, 3, 0) GRANULARITY 1,INDEX idx_attribute_value_n3 attribute_value TYPE ngrambf_v1(3, 32768, 3, 0) GRANULARITY 1) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/logs/{shard}/posthog.metric_attributes', '{replica}') ORDER BY (team_id, attribute_type, time_bucket, resource_fingerprint, attribute_key, attribute_value) PARTITION BY toDate(time_bucket) SETTINGS deduplicate_merge_projection_mode = 'drop', index_granularity = 8192;+CREATE TABLE posthog.metric_samples1 (+ team_id Int32,+ metric_name LowCardinality(String),+ series_fingerprint UInt64 CODEC(DoubleDelta),+ timestamp DateTime64(6) CODEC(DoubleDelta),+ value Float64 CODEC(Gorilla(8)),+ count UInt64 DEFAULT 1,+ histogram_bounds Array(Float64),+ histogram_counts Array(UInt64),+ trace_id String,+ span_id String,+ trace_flags Int32,+ INDEX idx_trace_id_bf trace_id TYPE bloom_filter(0.01) GRANULARITY 1+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.metric_samples1', '{replica}-{shard}') ORDER BY (team_id, metric_name, series_fingerprint, timestamp) PARTITION BY toDate(timestamp) TTL toDateTime(timestamp) + toIntervalDay(30) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;+CREATE TABLE posthog.metric_series1 (+ team_id Int32,+ metric_name LowCardinality(String),+ series_fingerprint UInt64 CODEC(DoubleDelta),+ metric_type LowCardinality(String),+ unit LowCardinality(String),+ aggregation_temporality LowCardinality(String),+ is_monotonic Bool DEFAULT false,+ service_name LowCardinality(String),+ resource_attributes Map(LowCardinality(String), String),+ attributes Map(LowCardinality(String), String),+ last_seen DateTime64(6) CODEC(DoubleDelta),+ INDEX idx_service_set service_name TYPE set(1000) GRANULARITY 1,+ INDEX idx_attr_keys mapKeys(attributes) TYPE bloom_filter(0.01) GRANULARITY 1,+ INDEX idx_attr_values mapValues(attributes) TYPE bloom_filter(0.01) GRANULARITY 1+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.metric_series1', '{replica}-{shard}', last_seen) ORDER BY (team_id, metric_name, series_fingerprint) TTL toDateTime(last_seen) + toIntervalDay(90) SETTINGS index_granularity = 8192;CREATE TABLE posthog.metrics1 (time_bucket DateTime MATERIALIZED toStartOfDay(timestamp),uuid String,@@ -583,6 +630,40 @@ CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro_mv TO posthog.metrics1 (uuid) AS attributes_map_float,toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_idFROM posthog.kafka_metrics_avro+SETTINGS+ min_insert_block_size_rows = 0,+ min_insert_block_size_bytes = 0;+CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro_to_metric_samples TO posthog.metric_samples1 (team_id Int32, metric_name String, series_fingerprint UInt64, timestamp DateTime64(6), value Float64, count UInt64, histogram_bounds Array(Float64), histogram_counts Array(UInt64), trace_id String, span_id String, trace_flags Int32) AS SELECT+ toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,+ ifNull(metric_name, '') AS metric_name,+ reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,+ timestamp,+ ifNull(value, 0) AS value,+ toUInt64(ifNull(count, 1)) AS count,+ histogram_bounds,+ arrayMap(x -> toUInt64(x), histogram_counts) AS histogram_counts,+ trace_id,+ span_id,+ ifNull(trace_flags, 0) AS trace_flags+FROM posthog.kafka_metrics_avro+WHERE kafka_metrics_avro.series_fingerprint IS NOT NULL+SETTINGS+ min_insert_block_size_rows = 0,+ min_insert_block_size_bytes = 0;+CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro_to_metric_series TO posthog.metric_series1 (team_id Int32, metric_name String, series_fingerprint UInt64, metric_type String, unit String, aggregation_temporality String, is_monotonic UInt8, service_name String, resource_attributes Map(String, String), attributes Map(String, String), last_seen DateTime64(6)) AS SELECT+ toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,+ ifNull(metric_name, '') AS metric_name,+ reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,+ ifNull(metric_type, '') AS metric_type,+ ifNull(unit, '') AS unit,+ ifNull(aggregation_temporality, '') AS aggregation_temporality,+ ifNull(is_monotonic, 0) AS is_monotonic,+ ifNull(service_name, '') AS service_name,+ mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)) AS resource_attributes,+ mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), attributes)) AS attributes,+ timestamp AS last_seen+FROM posthog.kafka_metrics_avro+WHERE kafka_metrics_avro.series_fingerprint IS NOT NULLSETTINGSmin_insert_block_size_rows = 0,min_insert_block_size_bytes = 0;@@ -632,6 +713,36 @@ FROMGROUP BYteam_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, attributes);+CREATE MATERIALIZED VIEW posthog.logs34_to_log_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 SELECT+ team_id,+ time_bucket,+ original_expiry_time_bucket,+ service_name,+ resource_fingerprint,+ attribute_key,+ attribute_value,+ attribute_type,+ severity_text,+ attribute_count+FROM+ (+ SELECT+ team_id AS team_id,+ toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,+ toStartOfInterval(original_expiry_timestamp, toIntervalMinute(10)) AS original_expiry_time_bucket,+ service_name AS service_name,+ resource_fingerprint,+ severity_text AS severity_text,+ mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS attributes,+ arrayJoin(attributes) AS attribute,+ 'log' AS attribute_type,+ attribute.1 AS attribute_key,+ attribute.2 AS attribute_value,+ sumSimpleState(1) AS attribute_count+ FROM posthog.logs34+ GROUP BY+ team_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, attributes+ );CREATE MATERIALIZED VIEW posthog.logs34_to_resource_attributes TO posthog.log_attributes2 (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), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,time_bucket,@@ -659,6 +770,35 @@ FROMGROUP BYteam_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, resource_attributes);+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 SELECT+ team_id,+ time_bucket,+ original_expiry_time_bucket,+ service_name,+ resource_fingerprint,+ attribute_key,+ attribute_value,+ attribute_type,+ severity_text,+ attribute_count+FROM+ (+ SELECT+ team_id AS team_id,+ toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,+ toStartOfInterval(original_expiry_timestamp, toIntervalMinute(10)) AS original_expiry_time_bucket,+ service_name AS service_name,+ resource_fingerprint,+ severity_text AS severity_text,+ arrayJoin(resource_attributes) AS attribute,+ 'resource' AS attribute_type,+ attribute.1 AS attribute_key,+ attribute.2 AS attribute_value,+ sumSimpleState(1) AS attribute_count+ FROM posthog.logs34+ GROUP BY+ team_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, resource_attributes+ );CREATE MATERIALIZED VIEW posthog.metrics1_to_metric_attributes TO posthog.metric_attributes (team_id Int32, 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,time_bucket,@@ -923,6 +1063,32 @@ CREATE VIEW posthog.custom_metrics_test AS SELECT1 AS value,'Test to check that the metric endpoint is working' AS help,'gauge' AS type;+CREATE TABLE posthog.metric_samples (+ team_id Int32,+ metric_name LowCardinality(String),+ series_fingerprint UInt64 CODEC(DoubleDelta),+ timestamp DateTime64(6) CODEC(DoubleDelta),+ value Float64 CODEC(Gorilla(8)),+ count UInt64 DEFAULT 1,+ histogram_bounds Array(Float64),+ histogram_counts Array(UInt64),+ trace_id String,+ span_id String,+ trace_flags Int32+) ENGINE = Distributed('logs', 'posthog', 'metric_samples1');+CREATE TABLE posthog.metric_series (+ team_id Int32,+ metric_name LowCardinality(String),+ series_fingerprint UInt64 CODEC(DoubleDelta),+ metric_type LowCardinality(String),+ unit LowCardinality(String),+ aggregation_temporality LowCardinality(String),+ is_monotonic Bool DEFAULT false,+ service_name LowCardinality(String),+ resource_attributes Map(LowCardinality(String), String),+ attributes Map(LowCardinality(String), String),+ last_seen DateTime64(6) CODEC(DoubleDelta)+) ENGINE = Distributed('logs', 'posthog', 'metric_series1');CREATE TABLE posthog.metrics (time_bucket DateTime MATERIALIZED toStartOfDay(timestamp),uuid String,diff --git a/posthog/clickhouse/hcl/sql/prod-us-logs.sql b/posthog/clickhouse/hcl/sql/prod-us-logs.sqlindex 6158795ff48a..789c3fee7d32 100644--- a/posthog/clickhouse/hcl/sql/prod-us-logs.sql+++ b/posthog/clickhouse/hcl/sql/prod-us-logs.sql@@ -36,7 +36,8 @@ CREATE TABLE posthog.kafka_metrics_avro (is_monotonic Nullable(UInt8),resource_attributes Map(String, String),instrumentation_scope Nullable(String),- attributes Map(String, String)+ attributes Map(String, String),+ series_fingerprint Nullable(Int64)) ENGINE = Kafka() SETTINGS kafka_broker_list = 'warpstream_metrics', kafka_format = 'kafka_format = \'Avro\'', kafka_group_name = 'kafka_group_name = \'clickhouse-metrics-avro-new\'', kafka_num_consumers = 8, kafka_poll_max_batch_size = 1000, kafka_poll_timeout_ms = 3000, kafka_skip_broken_messages = 100, kafka_thread_per_consumer = 1, kafka_topic_list = 'kafka_topic_list = \'clickhouse_metrics\'';CREATE TABLE posthog.kafka_trace_spans_avro (uuid String,@@ -76,6 +77,22 @@ CREATE TABLE posthog.log_attributes2 (INDEX idx_attribute_key_n3 attribute_key TYPE ngrambf_v1(3, 32768, 3, 0) GRANULARITY 1,INDEX idx_attribute_value_n3 attribute_value TYPE ngrambf_v1(3, 32768, 3, 0) GRANULARITY 1) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/logs/{shard}/log_attributes34', '{replica}') ORDER BY (team_id, attribute_type, time_bucket, resource_fingerprint, attribute_key, attribute_value) PARTITION BY toDate(time_bucket) TTL time_bucket + toIntervalDay(15) SETTINGS deduplicate_merge_projection_mode = 'drop', index_granularity = 8192;+CREATE TABLE posthog.log_attributes3 (+ team_id Int32,+ time_bucket DateTime64(0),+ service_name LowCardinality(String),+ resource_fingerprint UInt64 DEFAULT 0,+ attribute_key LowCardinality(String),+ attribute_value String CODEC(ZSTD(5)),+ attribute_count SimpleAggregateFunction(sum, UInt64),+ attribute_type LowCardinality(String) DEFAULT 'log',+ original_expiry_time_bucket DateTime DEFAULT now(),+ severity_text LowCardinality(String),+ INDEX idx_attribute_key attribute_key TYPE bloom_filter(0.01) GRANULARITY 1,+ INDEX idx_attribute_value attribute_value TYPE bloom_filter(0.01) GRANULARITY 1,+ INDEX idx_attribute_key_n3 attribute_key TYPE ngrambf_v1(3, 32768, 3, 0) GRANULARITY 1,+ INDEX idx_attribute_value_n3 attribute_value TYPE ngrambf_v1(3, 32768, 3, 0) GRANULARITY 1+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.log_attributes3', '{replica}-{shard}') ORDER BY (team_id, attribute_type, time_bucket, resource_fingerprint, attribute_key, attribute_value, severity_text) PARTITION BY toDate(original_expiry_time_bucket) TTL original_expiry_time_bucket SETTINGS deduplicate_merge_projection_mode = 'drop', index_granularity = 8192;CREATE TABLE posthog.log_attributes_distributed (team_id Int32,time_bucket DateTime64(0),@@ -209,6 +226,36 @@ CREATE TABLE posthog.metric_attributes (INDEX idx_attribute_key_n3 attribute_key TYPE ngrambf_v1(3, 32768, 3, 0) GRANULARITY 1,INDEX idx_attribute_value_n3 attribute_value TYPE ngrambf_v1(3, 32768, 3, 0) GRANULARITY 1) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/logs/{shard}/posthog.metric_attributes', '{replica}') ORDER BY (team_id, attribute_type, time_bucket, resource_fingerprint, attribute_key, attribute_value) PARTITION BY toDate(time_bucket) SETTINGS deduplicate_merge_projection_mode = 'drop', index_granularity = 8192;+CREATE TABLE posthog.metric_samples1 (+ team_id Int32,+ metric_name LowCardinality(String),+ series_fingerprint UInt64 CODEC(DoubleDelta),+ timestamp DateTime64(6) CODEC(DoubleDelta),+ value Float64 CODEC(Gorilla(8)),+ count UInt64 DEFAULT 1,+ histogram_bounds Array(Float64),+ histogram_counts Array(UInt64),+ trace_id String,+ span_id String,+ trace_flags Int32,+ INDEX idx_trace_id_bf trace_id TYPE bloom_filter(0.01) GRANULARITY 1+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.metric_samples1', '{replica}-{shard}') ORDER BY (team_id, metric_name, series_fingerprint, timestamp) PARTITION BY toDate(timestamp) TTL toDateTime(timestamp) + toIntervalDay(30) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;+CREATE TABLE posthog.metric_series1 (+ team_id Int32,+ metric_name LowCardinality(String),+ series_fingerprint UInt64 CODEC(DoubleDelta),+ metric_type LowCardinality(String),+ unit LowCardinality(String),+ aggregation_temporality LowCardinality(String),+ is_monotonic Bool DEFAULT false,+ service_name LowCardinality(String),+ resource_attributes Map(LowCardinality(String), String),+ attributes Map(LowCardinality(String), String),+ last_seen DateTime64(6) CODEC(DoubleDelta),+ INDEX idx_service_set service_name TYPE set(1000) GRANULARITY 1,+ INDEX idx_attr_keys mapKeys(attributes) TYPE bloom_filter(0.01) GRANULARITY 1,+ INDEX idx_attr_values mapValues(attributes) TYPE bloom_filter(0.01) GRANULARITY 1+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.metric_series1', '{replica}-{shard}', last_seen) ORDER BY (team_id, metric_name, series_fingerprint) TTL toDateTime(last_seen) + toIntervalDay(90) SETTINGS index_granularity = 8192;CREATE TABLE posthog.metrics1 (time_bucket DateTime MATERIALIZED toStartOfDay(timestamp),uuid String,@@ -585,6 +632,40 @@ CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro_mv TO posthog.metrics1 (uuid) AS attributes_map_float,toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_idFROM posthog.kafka_metrics_avro+SETTINGS+ min_insert_block_size_rows = 0,+ min_insert_block_size_bytes = 0;+CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro_to_metric_samples TO posthog.metric_samples1 (team_id Int32, metric_name String, series_fingerprint UInt64, timestamp DateTime64(6), value Float64, count UInt64, histogram_bounds Array(Float64), histogram_counts Array(UInt64), trace_id String, span_id String, trace_flags Int32) AS SELECT+ toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,+ ifNull(metric_name, '') AS metric_name,+ reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,+ timestamp,+ ifNull(value, 0) AS value,+ toUInt64(ifNull(count, 1)) AS count,+ histogram_bounds,+ arrayMap(x -> toUInt64(x), histogram_counts) AS histogram_counts,+ trace_id,+ span_id,+ ifNull(trace_flags, 0) AS trace_flags+FROM posthog.kafka_metrics_avro+WHERE kafka_metrics_avro.series_fingerprint IS NOT NULL+SETTINGS+ min_insert_block_size_rows = 0,+ min_insert_block_size_bytes = 0;+CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro_to_metric_series TO posthog.metric_series1 (team_id Int32, metric_name String, series_fingerprint UInt64, metric_type String, unit String, aggregation_temporality String, is_monotonic UInt8, service_name String, resource_attributes Map(String, String), attributes Map(String, String), last_seen DateTime64(6)) AS SELECT+ toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,+ ifNull(metric_name, '') AS metric_name,+ reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,+ ifNull(metric_type, '') AS metric_type,+ ifNull(unit, '') AS unit,+ ifNull(aggregation_temporality, '') AS aggregation_temporality,+ ifNull(is_monotonic, 0) AS is_monotonic,+ ifNull(service_name, '') AS service_name,+ mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)) AS resource_attributes,+ mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), attributes)) AS attributes,+ timestamp AS last_seen+FROM posthog.kafka_metrics_avro+WHERE kafka_metrics_avro.series_fingerprint IS NOT NULLSETTINGSmin_insert_block_size_rows = 0,min_insert_block_size_bytes = 0;@@ -634,6 +715,36 @@ FROMGROUP BYteam_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, attributes);+CREATE MATERIALIZED VIEW posthog.logs34_to_log_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 SELECT+ team_id,+ time_bucket,+ original_expiry_time_bucket,+ service_name,+ resource_fingerprint,+ attribute_key,+ attribute_value,+ attribute_type,+ severity_text,+ attribute_count+FROM+ (+ SELECT+ team_id AS team_id,+ toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,+ toStartOfInterval(original_expiry_timestamp, toIntervalMinute(10)) AS original_expiry_time_bucket,+ service_name AS service_name,+ resource_fingerprint,+ severity_text AS severity_text,+ mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS attributes,+ arrayJoin(attributes) AS attribute,+ 'log' AS attribute_type,+ attribute.1 AS attribute_key,+ attribute.2 AS attribute_value,+ sumSimpleState(1) AS attribute_count+ FROM posthog.logs34+ GROUP BY+ team_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, attributes+ );CREATE MATERIALIZED VIEW posthog.logs34_to_resource_attributes TO posthog.log_attributes2 (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), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,time_bucket,@@ -661,6 +772,35 @@ FROMGROUP BYteam_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, resource_attributes);+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 SELECT+ team_id,+ time_bucket,+ original_expiry_time_bucket,+ service_name,+ resource_fingerprint,+ attribute_key,+ attribute_value,+ attribute_type,+ severity_text,+ attribute_count+FROM+ (+ SELECT+ team_id AS team_id,+ toStartOfInterval(timestamp, toIntervalMinute(10)) AS time_bucket,+ toStartOfInterval(original_expiry_timestamp, toIntervalMinute(10)) AS original_expiry_time_bucket,+ service_name AS service_name,+ resource_fingerprint,+ severity_text AS severity_text,+ arrayJoin(resource_attributes) AS attribute,+ 'resource' AS attribute_type,+ attribute.1 AS attribute_key,+ attribute.2 AS attribute_value,+ sumSimpleState(1) AS attribute_count+ FROM posthog.logs34+ GROUP BY+ team_id, time_bucket, original_expiry_time_bucket, service_name, resource_fingerprint, severity_text, resource_attributes+ );CREATE MATERIALIZED VIEW posthog.metrics1_to_metric_attributes TO posthog.metric_attributes (team_id Int32, 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,time_bucket,@@ -936,6 +1076,32 @@ CREATE VIEW posthog.custom_metrics_test AS SELECT1 AS value,'Test to check that the metric endpoint is working' AS help,'gauge' AS type;+CREATE TABLE posthog.metric_samples (+ team_id Int32,+ metric_name LowCardinality(String),+ series_fingerprint UInt64 CODEC(DoubleDelta),+ timestamp DateTime64(6) CODEC(DoubleDelta),+ value Float64 CODEC(Gorilla(8)),+ count UInt64 DEFAULT 1,+ histogram_bounds Array(Float64),+ histogram_counts Array(UInt64),+ trace_id String,+ span_id String,+ trace_flags Int32+) ENGINE = Distributed('logs', 'posthog', 'metric_samples1');+CREATE TABLE posthog.metric_series (+ team_id Int32,+ metric_name LowCardinality(String),+ series_fingerprint UInt64 CODEC(DoubleDelta),+ metric_type LowCardinality(String),+ unit LowCardinality(String),+ aggregation_temporality LowCardinality(String),+ is_monotonic Bool DEFAULT false,+ service_name LowCardinality(String),+ resource_attributes Map(LowCardinality(String), String),+ attributes Map(LowCardinality(String), String),+ last_seen DateTime64(6) CODEC(DoubleDelta)+) ENGINE = Distributed('logs', 'posthog', 'metric_series1');CREATE TABLE posthog.metrics (time_bucket DateTime MATERIALIZED toStartOfDay(timestamp),uuid String,