: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(metrics): stop ingestion to the metrics2 and metrics3 tables (#109221)
Frank Hamand6af1930a8a8d
diff --git a/posthog/clickhouse/hcl/golden/dev/logs.hcl b/posthog/clickhouse/hcl/golden/dev/logs.hclindex 10fd828bd9d4..5d3db566e85b 100644--- a/posthog/clickhouse/hcl/golden/dev/logs.hcl+++ b/posthog/clickhouse/hcl/golden/dev/logs.hcl@@ -1,88 +1,4 @@database "posthog" {- table "kafka_metrics_avro2" {- settings = {- input_format_avro_allow_missing_fields = "1"- }- column "uuid" {- type = "String"- }- column "trace_id" {- type = "String"- }- column "span_id" {- type = "String"- }- column "trace_flags" {- type = "Nullable(Int32)"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "Nullable(String)"- }- column "metric_name" {- type = "Nullable(String)"- }- column "metric_type" {- type = "Nullable(String)"- }- column "value" {- type = "Nullable(Float64)"- }- column "count" {- type = "Nullable(Int64)"- }- column "histogram_bounds" {- type = "Array(Float64)"- }- column "histogram_counts" {- type = "Array(Int64)"- }- column "unit" {- type = "Nullable(String)"- }- column "aggregation_temporality" {- type = "Nullable(String)"- }- column "is_monotonic" {- type = "Nullable(UInt8)"- }- column "resource_attributes" {- type = "Map(String, String)"- }- column "instrumentation_scope" {- type = "Nullable(String)"- }- column "attributes" {- type = "Map(String, String)"- }- column "series_fingerprint" {- type = "Nullable(Int64)"- }- column "has_labels" {- type = "Nullable(UInt8)"- }- column "retention_days" {- type = "Nullable(Int32)"- }- engine "kafka" {- collection = "warpstream_metrics"- topic_list = "clickhouse_metrics"- group_name = "clickhouse-metrics-avro2"- format = "Avro"- num_consumers = 4- skip_broken_messages = 100- poll_timeout_ms = 10000- poll_max_batch_size = 500- flush_interval_ms = 10000- thread_per_consumer = true- }- }-table "log_attributes2" {order_by = ["team_id", "attribute_type", "time_bucket", "resource_fingerprint", "attribute_key", "attribute_value"]partition_by = "toDate(time_bucket)"@@ -1882,92 +1798,6 @@ SQL}}- table "metrics2_input" {- column "uuid" {- type = "String"- }- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "metric_type" {- type = "LowCardinality(String)"- }- 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"- }- column "has_labels" {- type = "Bool"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(LowCardinality(String), String)"- }- column "attributes" {- type = "Map(LowCardinality(String), String)"- }- column "_partition" {- type = "UInt32"- }- column "_topic" {- type = "String"- }- column "_offset" {- type = "UInt64"- }- engine "null" {- }- }-table "metrics4_attributes" {order_by = ["team_id", "metric_name", "attribute_type", "time_bucket", "attribute_key", "attribute_value", "service_name", "original_expiry_time_bucket"]partition_by = "toDate(original_expiry_time_bucket)"@@ -3485,144 +3315,6 @@ SQL}}- materialized_view "kafka_metrics_avro2_mv" {- to_table = "posthog.metrics2_input"- query = <<SQL-SELECT- uuid,- toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,- ifNull(metric_name, '') AS metric_name,- reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,- cityHash64(mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes))) AS resource_fingerprint,- timestamp,- observed_timestamp,- timestamp- + toIntervalDay(- assumeNotNull(- if(- (retention_days IS NOT NULL) AND (retention_days > 0),- retention_days,- toInt32OrDefault(_headers.value[indexOf(_headers.name, 'retention-days')], toInt32(30))- )- )- ) AS original_expiry_timestamp,- ifNull(service_name, '') AS service_name,- ifNull(metric_type, '') AS metric_type,- 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,- toBool(ifNull(has_labels, 1)) AS has_labels,- ifNull(unit, '') AS unit,- ifNull(aggregation_temporality, '') AS aggregation_temporality,- ifNull(is_monotonic, 0) AS is_monotonic,- ifNull(instrumentation_scope, '') AS instrumentation_scope,- if(- toBool(ifNull(has_labels, 1)),- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)),- CAST(map(), 'Map(String, String)')- ) AS resource_attributes,- if(- toBool(ifNull(has_labels, 1)),- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), attributes)),- CAST(map(), 'Map(String, String)')- ) AS attributes,- _partition,- _topic,- _offset-FROM posthog.kafka_metrics_avro2-WHERE kafka_metrics_avro2.series_fingerprint IS NOT NULL-SETTINGS- min_insert_block_size_rows = 0,- min_insert_block_size_bytes = 0-SQL-- column "uuid" {- type = "String"- }- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "String"- }- column "series_fingerprint" {- type = "UInt64"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "String"- }- column "metric_type" {- type = "String"- }- 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"- }- column "has_labels" {- type = "Bool"- }- column "unit" {- type = "String"- }- column "aggregation_temporality" {- type = "String"- }- column "is_monotonic" {- type = "UInt8"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(String, String)"- }- column "attributes" {- type = "Map(String, String)"- }- column "_partition" {- type = "UInt64"- }- column "_topic" {- type = "LowCardinality(String)"- }- column "_offset" {- type = "UInt64"- }- }-materialized_view "logs34_to_log_attributes3" {to_table = "posthog.log_attributes3"query = <<SQL@@ -3831,509 +3523,6 @@ SQL}}- materialized_view "metrics2_input_to_metric_attributes" {- to_table = "posthog.metric_attributes2"- query = <<SQL-SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, time_bucket, original_expiry_time_bucket, service_name, filtered_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 "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-- materialized_view "metrics2_input_to_metric_attributes3" {- to_table = "posthog.metric_attributes3"- query = <<SQL-SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- )-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-- materialized_view "metrics2_input_to_metric_names3" {- to_table = "posthog.metric_names3"- query = <<SQL-SELECT- team_id,- metric_name,- toStartOfHour(timestamp) AS time_bucket,- toStartOfHour(input.original_expiry_timestamp) AS original_expiry_time_bucket,- maxSimpleState(input.original_expiry_timestamp) AS original_expiry_timestamp-FROM posthog.metrics2_input AS input-WHERE has_labels-GROUP BY- team_id, time_bucket, metric_name, original_expiry_time_bucket-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_timestamp" {- type = "SimpleAggregateFunction(max, DateTime64(6))"- }- }-- materialized_view "metrics2_input_to_metric_series" {- to_table = "posthog.metric_series2"- query = <<SQL-SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp-FROM posthog.metrics2_input-WHERE has_labels-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "metric_type" {- type = "LowCardinality(String)"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(LowCardinality(String), String)"- }- column "attributes" {- type = "Map(LowCardinality(String), String)"- }- column "last_seen" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- }-- materialized_view "metrics2_input_to_metric_series3" {- to_table = "posthog.metric_series3"- query = <<SQL-SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp-FROM posthog.metrics2_input-WHERE has_labels-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "metric_type" {- type = "LowCardinality(String)"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(LowCardinality(String), String)"- }- column "attributes" {- type = "Map(LowCardinality(String), String)"- }- column "last_seen" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- }-- materialized_view "metrics2_input_to_metrics" {- to_table = "posthog.metrics2"- query = <<SQL-SELECT- team_id,- metric_name,- series_fingerprint,- resource_fingerprint,- timestamp,- observed_timestamp,- original_expiry_timestamp,- service_name,- metric_type,- value,- count,- histogram_bounds,- histogram_counts,- trace_id,- span_id,- trace_flags,- has_labels,- unit,- aggregation_temporality,- is_monotonic,- instrumentation_scope,- _partition,- _topic,- _offset-FROM posthog.metrics2_input-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "metric_type" {- type = "LowCardinality(String)"- }- 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"- }- column "has_labels" {- type = "Bool"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "instrumentation_scope" {- type = "String"- }- column "_partition" {- type = "UInt32"- }- column "_topic" {- type = "String"- }- column "_offset" {- type = "UInt64"- }- }-- materialized_view "metrics2_input_to_resource_attributes" {- to_table = "posthog.metric_attributes2"- query = <<SQL-SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, time_bucket, original_expiry_time_bucket, service_name, filtered_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 "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-- materialized_view "metrics2_input_to_resource_attributes3" {- to_table = "posthog.metric_attributes3"- query = <<SQL-SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- )-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-materialized_view "ops_query_log_archive_mv" {to_table = "posthog.writable_query_log_archive"query = <<SQLdiff --git a/posthog/clickhouse/hcl/golden/local-multi/logs.hcl b/posthog/clickhouse/hcl/golden/local-multi/logs.hclindex 4d873da1c086..44c550ef9a87 100644--- a/posthog/clickhouse/hcl/golden/local-multi/logs.hcl+++ b/posthog/clickhouse/hcl/golden/local-multi/logs.hcl@@ -1,87 +1,4 @@database "posthog" {- table "kafka_metrics_avro2" {- settings = {- input_format_avro_allow_missing_fields = "1"- }- column "uuid" {- type = "String"- }- column "trace_id" {- type = "String"- }- column "span_id" {- type = "String"- }- column "trace_flags" {- type = "Nullable(Int32)"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "Nullable(String)"- }- column "metric_name" {- type = "Nullable(String)"- }- column "metric_type" {- type = "Nullable(String)"- }- column "value" {- type = "Nullable(Float64)"- }- column "count" {- type = "Nullable(Int64)"- }- column "histogram_bounds" {- type = "Array(Float64)"- }- column "histogram_counts" {- type = "Array(Int64)"- }- column "unit" {- type = "Nullable(String)"- }- column "aggregation_temporality" {- type = "Nullable(String)"- }- column "is_monotonic" {- type = "Nullable(UInt8)"- }- column "resource_attributes" {- type = "Map(String, String)"- }- column "instrumentation_scope" {- type = "Nullable(String)"- }- column "attributes" {- type = "Map(String, String)"- }- column "series_fingerprint" {- type = "Nullable(Int64)"- }- column "has_labels" {- type = "Nullable(UInt8)"- }- column "retention_days" {- type = "Nullable(Int32)"- }- engine "kafka" {- collection = "warpstream_metrics"- topic_list = "clickhouse_metrics"- group_name = "clickhouse-metrics-avro2"- format = "Avro"- num_consumers = 1- skip_broken_messages = 100- poll_timeout_ms = 3000- poll_max_batch_size = 1000- thread_per_consumer = true- }- }-table "kafka_trace_spans_avro" {settings = {input_format_avro_allow_missing_fields = "1"@@ -2382,92 +2299,6 @@ SQL}}- table "metrics2_input" {- column "uuid" {- type = "String"- }- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "metric_type" {- type = "LowCardinality(String)"- }- 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"- }- column "has_labels" {- type = "Bool"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(LowCardinality(String), String)"- }- column "attributes" {- type = "Map(LowCardinality(String), String)"- }- column "_partition" {- type = "UInt32"- }- column "_topic" {- type = "String"- }- column "_offset" {- type = "UInt64"- }- engine "null" {- }- }-table "metrics4_attributes" {order_by = ["team_id", "metric_name", "attribute_type", "time_bucket", "attribute_key", "attribute_value", "service_name", "original_expiry_time_bucket"]partition_by = "toDate(original_expiry_time_bucket)"@@ -3900,144 +3731,6 @@ SQL}}- materialized_view "kafka_metrics_avro2_mv" {- to_table = "posthog.metrics2_input"- query = <<SQL-SELECT- uuid,- toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,- ifNull(metric_name, '') AS metric_name,- reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,- cityHash64(mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes))) AS resource_fingerprint,- timestamp,- observed_timestamp,- timestamp- + toIntervalDay(- assumeNotNull(- if(- (retention_days IS NOT NULL) AND (retention_days > 0),- retention_days,- toInt32OrDefault(_headers.value[indexOf(_headers.name, 'retention-days')], toInt32(30))- )- )- ) AS original_expiry_timestamp,- ifNull(service_name, '') AS service_name,- ifNull(metric_type, '') AS metric_type,- 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,- toBool(ifNull(has_labels, 1)) AS has_labels,- ifNull(unit, '') AS unit,- ifNull(aggregation_temporality, '') AS aggregation_temporality,- ifNull(is_monotonic, 0) AS is_monotonic,- ifNull(instrumentation_scope, '') AS instrumentation_scope,- if(- toBool(ifNull(has_labels, 1)),- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)),- CAST(map(), 'Map(String, String)')- ) AS resource_attributes,- if(- toBool(ifNull(has_labels, 1)),- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), attributes)),- CAST(map(), 'Map(String, String)')- ) AS attributes,- _partition,- _topic,- _offset-FROM posthog.kafka_metrics_avro2-WHERE kafka_metrics_avro2.series_fingerprint IS NOT NULL-SETTINGS- min_insert_block_size_rows = 0,- min_insert_block_size_bytes = 0-SQL-- column "uuid" {- type = "String"- }- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "String"- }- column "series_fingerprint" {- type = "UInt64"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "String"- }- column "metric_type" {- type = "String"- }- 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"- }- column "has_labels" {- type = "Bool"- }- column "unit" {- type = "String"- }- column "aggregation_temporality" {- type = "String"- }- column "is_monotonic" {- type = "UInt8"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(String, String)"- }- column "attributes" {- type = "Map(String, String)"- }- column "_partition" {- type = "UInt64"- }- column "_topic" {- type = "LowCardinality(String)"- }- column "_offset" {- type = "UInt64"- }- }-materialized_view "kafka_trace_spans_avro_mv" {to_table = "posthog.trace_spans"query = <<SQL@@ -4483,509 +4176,6 @@ SQL}}- materialized_view "metrics2_input_to_metric_attributes" {- to_table = "posthog.metric_attributes2"- query = <<SQL-SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, time_bucket, original_expiry_time_bucket, service_name, filtered_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 "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-- materialized_view "metrics2_input_to_metric_attributes3" {- to_table = "posthog.metric_attributes3"- query = <<SQL-SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- )-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-- materialized_view "metrics2_input_to_metric_names3" {- to_table = "posthog.metric_names3"- query = <<SQL-SELECT- team_id,- metric_name,- toStartOfHour(timestamp) AS time_bucket,- toStartOfHour(input.original_expiry_timestamp) AS original_expiry_time_bucket,- maxSimpleState(input.original_expiry_timestamp) AS original_expiry_timestamp-FROM posthog.metrics2_input AS input-WHERE has_labels-GROUP BY- team_id, time_bucket, metric_name, original_expiry_time_bucket-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_timestamp" {- type = "SimpleAggregateFunction(max, DateTime64(6))"- }- }-- materialized_view "metrics2_input_to_metric_series" {- to_table = "posthog.metric_series2"- query = <<SQL-SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp-FROM posthog.metrics2_input-WHERE has_labels-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "metric_type" {- type = "LowCardinality(String)"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(LowCardinality(String), String)"- }- column "attributes" {- type = "Map(LowCardinality(String), String)"- }- column "last_seen" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- }-- materialized_view "metrics2_input_to_metric_series3" {- to_table = "posthog.metric_series3"- query = <<SQL-SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp-FROM posthog.metrics2_input-WHERE has_labels-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "metric_type" {- type = "LowCardinality(String)"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(LowCardinality(String), String)"- }- column "attributes" {- type = "Map(LowCardinality(String), String)"- }- column "last_seen" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- }-- materialized_view "metrics2_input_to_metrics" {- to_table = "posthog.metrics2"- query = <<SQL-SELECT- team_id,- metric_name,- series_fingerprint,- resource_fingerprint,- timestamp,- observed_timestamp,- original_expiry_timestamp,- service_name,- metric_type,- value,- count,- histogram_bounds,- histogram_counts,- trace_id,- span_id,- trace_flags,- has_labels,- unit,- aggregation_temporality,- is_monotonic,- instrumentation_scope,- _partition,- _topic,- _offset-FROM posthog.metrics2_input-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "metric_type" {- type = "LowCardinality(String)"- }- 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"- }- column "has_labels" {- type = "Bool"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "instrumentation_scope" {- type = "String"- }- column "_partition" {- type = "UInt32"- }- column "_topic" {- type = "String"- }- column "_offset" {- type = "UInt64"- }- }-- materialized_view "metrics2_input_to_resource_attributes" {- to_table = "posthog.metric_attributes2"- query = <<SQL-SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, time_bucket, original_expiry_time_bucket, service_name, filtered_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 "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-- materialized_view "metrics2_input_to_resource_attributes3" {- to_table = "posthog.metric_attributes3"- query = <<SQL-SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- )-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-materialized_view "trace_span_to_attributes" {to_table = "posthog.trace_attributes"query = <<SQLdiff --git a/posthog/clickhouse/hcl/golden/local-single/all.hcl b/posthog/clickhouse/hcl/golden/local-single/all.hclindex cc8996319d08..77ef10786a94 100644--- a/posthog/clickhouse/hcl/golden/local-single/all.hcl+++ b/posthog/clickhouse/hcl/golden/local-single/all.hcl@@ -3615,89 +3615,6 @@ database "posthog" {}}- table "kafka_metrics_avro2" {- settings = {- input_format_avro_allow_missing_fields = "1"- }- column "uuid" {- type = "String"- }- column "trace_id" {- type = "String"- }- column "span_id" {- type = "String"- }- column "trace_flags" {- type = "Nullable(Int32)"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "Nullable(String)"- }- column "metric_name" {- type = "Nullable(String)"- }- column "metric_type" {- type = "Nullable(String)"- }- column "value" {- type = "Nullable(Float64)"- }- column "count" {- type = "Nullable(Int64)"- }- column "histogram_bounds" {- type = "Array(Float64)"- }- column "histogram_counts" {- type = "Array(Int64)"- }- column "unit" {- type = "Nullable(String)"- }- column "aggregation_temporality" {- type = "Nullable(String)"- }- column "is_monotonic" {- type = "Nullable(UInt8)"- }- column "resource_attributes" {- type = "Map(String, String)"- }- column "instrumentation_scope" {- type = "Nullable(String)"- }- column "attributes" {- type = "Map(String, String)"- }- column "series_fingerprint" {- type = "Nullable(Int64)"- }- column "has_labels" {- type = "Nullable(UInt8)"- }- column "retention_days" {- type = "Nullable(Int32)"- }- engine "kafka" {- collection = "warpstream_metrics"- topic_list = "clickhouse_metrics"- group_name = "clickhouse-metrics-avro2"- format = "Avro"- num_consumers = 1- skip_broken_messages = 100- poll_timeout_ms = 3000- poll_max_batch_size = 1000- thread_per_consumer = true- }- }-table "kafka_metrics_avro4" {settings = {input_format_avro_allow_missing_fields = "1"@@ -7441,92 +7358,6 @@ SQL}}- table "metrics2_input" {- column "uuid" {- type = "String"- }- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "metric_type" {- type = "LowCardinality(String)"- }- 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"- }- column "has_labels" {- type = "Bool"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(LowCardinality(String), String)"- }- column "attributes" {- type = "Map(LowCardinality(String), String)"- }- column "_partition" {- type = "UInt32"- }- column "_topic" {- type = "String"- }- column "_offset" {- type = "UInt64"- }- engine "null" {- }- }-table "metrics4_attributes" {order_by = ["team_id", "metric_name", "attribute_type", "time_bucket", "attribute_key", "attribute_value", "service_name", "original_expiry_time_bucket"]partition_by = "toDate(original_expiry_time_bucket)"@@ -21412,8 +21243,8 @@ SQL}}- materialized_view "kafka_metrics_avro2_mv" {- to_table = "posthog.metrics2_input"+ materialized_view "kafka_metrics_avro4_mv" {+ to_table = "posthog.metrics4_input"query = <<SQLSELECTuuid,@@ -21460,8 +21291,8 @@ SELECT_partition,_topic,_offset-FROM posthog.kafka_metrics_avro2-WHERE kafka_metrics_avro2.series_fingerprint IS NOT NULL+FROM posthog.kafka_metrics_avro4+WHERE kafka_metrics_avro4.series_fingerprint IS NOT NULLSETTINGSmin_insert_block_size_rows = 0,min_insert_block_size_bytes = 0@@ -21550,198 +21381,60 @@ SQL}}- materialized_view "kafka_metrics_avro4_mv" {- to_table = "posthog.metrics4_input"+ materialized_view "kafka_trace_spans_avro_mv" {+ to_table = "posthog.trace_spans"query = <<SQLSELECTuuid,- toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,- ifNull(metric_name, '') AS metric_name,- reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,- cityHash64(mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes))) AS resource_fingerprint,+ trace_id,+ span_id,+ parent_span_id,+ trace_state,+ name,timestamp,+ end_time,observed_timestamp,- timestamp+ service_name,+ instrumentation_scope,+ events,+ links,+ toInt8(kind) AS kind,+ toUInt32(flags) AS flags,+ toUInt32(dropped_attributes_count) AS dropped_attributes_count,+ toUInt32(dropped_events_count) AS dropped_events_count,+ toUInt32(dropped_links_count) AS dropped_links_count,+ toInt16(status_code) AS status_code,+ mapSort(mapApply((k, v) -> (concat(k, '__str'), JSONExtractString(v)), attributes)) AS attributes_map_str,+ mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)) AS resource_attributes,+ toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,+ observed_timestamp+ toIntervalDay(- assumeNotNull(- if(- (retention_days IS NOT NULL) AND (retention_days > 0),- retention_days,- toInt32OrDefault(_headers.value[indexOf(_headers.name, 'retention-days')], toInt32(30))- )+ if(+ (retention_days IS NOT NULL) AND (retention_days > 0),+ retention_days,+ toInt32OrDefault(_headers.value[indexOf(_headers.name, 'retention-days')], toInt32(15)))) AS original_expiry_timestamp,- ifNull(service_name, '') AS service_name,- ifNull(metric_type, '') AS metric_type,- 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,- toBool(ifNull(has_labels, 1)) AS has_labels,- ifNull(unit, '') AS unit,- ifNull(aggregation_temporality, '') AS aggregation_temporality,- ifNull(is_monotonic, 0) AS is_monotonic,- ifNull(instrumentation_scope, '') AS instrumentation_scope,- if(- toBool(ifNull(has_labels, 1)),- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)),- CAST(map(), 'Map(String, String)')- ) AS resource_attributes,- if(- toBool(ifNull(has_labels, 1)),- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), attributes)),- CAST(map(), 'Map(String, String)')- ) AS attributes,_partition,_topic,- _offset-FROM posthog.kafka_metrics_avro4-WHERE kafka_metrics_avro4.series_fingerprint IS NOT NULL-SETTINGS- min_insert_block_size_rows = 0,- min_insert_block_size_bytes = 0+ _offset,+ toInt64OrDefault(_headers.value[indexOf(_headers.name, 'record_count')], toInt64(1)) AS _record_count,+ toInt64OrDefault(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')], toInt64(0)) AS _bytes_uncompressed,+ toInt64OrDefault(_headers.value[indexOf(_headers.name, 'bytes_compressed')], toInt64(0)) AS _bytes_compressed+FROM posthog.kafka_trace_spans_avroSQLcolumn "uuid" {type = "String"}- column "team_id" {- type = "Int32"+ column "trace_id" {+ type = "String"}- column "metric_name" {+ column "span_id" {type = "String"}- column "series_fingerprint" {- type = "UInt64"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "String"- }- column "metric_type" {- type = "String"- }- 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"- }- column "has_labels" {- type = "Bool"- }- column "unit" {- type = "String"- }- column "aggregation_temporality" {- type = "String"- }- column "is_monotonic" {- type = "UInt8"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(String, String)"- }- column "attributes" {- type = "Map(String, String)"- }- column "_partition" {- type = "UInt64"- }- column "_topic" {- type = "LowCardinality(String)"- }- column "_offset" {- type = "UInt64"- }- }-- materialized_view "kafka_trace_spans_avro_mv" {- to_table = "posthog.trace_spans"- query = <<SQL-SELECT- uuid,- trace_id,- span_id,- parent_span_id,- trace_state,- name,- timestamp,- end_time,- observed_timestamp,- service_name,- instrumentation_scope,- events,- links,- toInt8(kind) AS kind,- toUInt32(flags) AS flags,- toUInt32(dropped_attributes_count) AS dropped_attributes_count,- toUInt32(dropped_events_count) AS dropped_events_count,- toUInt32(dropped_links_count) AS dropped_links_count,- toInt16(status_code) AS status_code,- mapSort(mapApply((k, v) -> (concat(k, '__str'), JSONExtractString(v)), attributes)) AS attributes_map_str,- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)) AS resource_attributes,- toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,- observed_timestamp- + toIntervalDay(- if(- (retention_days IS NOT NULL) AND (retention_days > 0),- retention_days,- toInt32OrDefault(_headers.value[indexOf(_headers.name, 'retention-days')], toInt32(15))- )- ) AS original_expiry_timestamp,- _partition,- _topic,- _offset,- toInt64OrDefault(_headers.value[indexOf(_headers.name, 'record_count')], toInt64(1)) AS _record_count,- toInt64OrDefault(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')], toInt64(0)) AS _bytes_uncompressed,- toInt64OrDefault(_headers.value[indexOf(_headers.name, 'bytes_compressed')], toInt64(0)) AS _bytes_compressed-FROM posthog.kafka_trace_spans_avro-SQL-- column "uuid" {- type = "String"- }- column "trace_id" {- type = "String"- }- column "span_id" {- type = "String"- }- column "parent_span_id" {- type = "String"+ column "parent_span_id" {+ type = "String"}column "trace_state" {type = "String"@@ -22356,509 +22049,6 @@ SQL}}- materialized_view "metrics2_input_to_metric_attributes" {- to_table = "posthog.metric_attributes2"- query = <<SQL-SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, time_bucket, original_expiry_time_bucket, service_name, filtered_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 "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-- materialized_view "metrics2_input_to_metric_attributes3" {- to_table = "posthog.metric_attributes3"- query = <<SQL-SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- )-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-- materialized_view "metrics2_input_to_metric_names3" {- to_table = "posthog.metric_names3"- query = <<SQL-SELECT- team_id,- metric_name,- toStartOfHour(timestamp) AS time_bucket,- toStartOfHour(input.original_expiry_timestamp) AS original_expiry_time_bucket,- maxSimpleState(input.original_expiry_timestamp) AS original_expiry_timestamp-FROM posthog.metrics2_input AS input-WHERE has_labels-GROUP BY- team_id, time_bucket, metric_name, original_expiry_time_bucket-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_timestamp" {- type = "SimpleAggregateFunction(max, DateTime64(6))"- }- }-- materialized_view "metrics2_input_to_metric_series" {- to_table = "posthog.metric_series2"- query = <<SQL-SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp-FROM posthog.metrics2_input-WHERE has_labels-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "metric_type" {- type = "LowCardinality(String)"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(LowCardinality(String), String)"- }- column "attributes" {- type = "Map(LowCardinality(String), String)"- }- column "last_seen" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- }-- materialized_view "metrics2_input_to_metric_series3" {- to_table = "posthog.metric_series3"- query = <<SQL-SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp-FROM posthog.metrics2_input-WHERE has_labels-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "metric_type" {- type = "LowCardinality(String)"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(LowCardinality(String), String)"- }- column "attributes" {- type = "Map(LowCardinality(String), String)"- }- column "last_seen" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- }-- materialized_view "metrics2_input_to_metrics" {- to_table = "posthog.metrics2"- query = <<SQL-SELECT- team_id,- metric_name,- series_fingerprint,- resource_fingerprint,- timestamp,- observed_timestamp,- original_expiry_timestamp,- service_name,- metric_type,- value,- count,- histogram_bounds,- histogram_counts,- trace_id,- span_id,- trace_flags,- has_labels,- unit,- aggregation_temporality,- is_monotonic,- instrumentation_scope,- _partition,- _topic,- _offset-FROM posthog.metrics2_input-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "metric_type" {- type = "LowCardinality(String)"- }- 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"- }- column "has_labels" {- type = "Bool"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "instrumentation_scope" {- type = "String"- }- column "_partition" {- type = "UInt32"- }- column "_topic" {- type = "String"- }- column "_offset" {- type = "UInt64"- }- }-- materialized_view "metrics2_input_to_resource_attributes" {- to_table = "posthog.metric_attributes2"- query = <<SQL-SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, time_bucket, original_expiry_time_bucket, service_name, filtered_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 "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-- materialized_view "metrics2_input_to_resource_attributes3" {- to_table = "posthog.metric_attributes3"- query = <<SQL-SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- )-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-materialized_view "metrics4_input_to_metrics4_attributes" {to_table = "posthog.writable_metrics4_attributes"query = <<SQLdiff --git a/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl b/posthog/clickhouse/hcl/golden/prod-eu/logs.hclindex 4379c25b6a00..4d626732c237 100644--- a/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl+++ b/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl@@ -1,87 +1,4 @@database "posthog" {- table "kafka_metrics_avro2" {- settings = {- input_format_avro_allow_missing_fields = "1"- }- column "uuid" {- type = "String"- }- column "trace_id" {- type = "String"- }- column "span_id" {- type = "String"- }- column "trace_flags" {- type = "Nullable(Int32)"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "Nullable(String)"- }- column "metric_name" {- type = "Nullable(String)"- }- column "metric_type" {- type = "Nullable(String)"- }- column "value" {- type = "Nullable(Float64)"- }- column "count" {- type = "Nullable(Int64)"- }- column "histogram_bounds" {- type = "Array(Float64)"- }- column "histogram_counts" {- type = "Array(Int64)"- }- column "unit" {- type = "Nullable(String)"- }- column "aggregation_temporality" {- type = "Nullable(String)"- }- column "is_monotonic" {- type = "Nullable(UInt8)"- }- column "resource_attributes" {- type = "Map(String, String)"- }- column "instrumentation_scope" {- type = "Nullable(String)"- }- column "attributes" {- type = "Map(String, String)"- }- column "series_fingerprint" {- type = "Nullable(Int64)"- }- column "has_labels" {- type = "Nullable(UInt8)"- }- column "retention_days" {- type = "Nullable(Int32)"- }- engine "kafka" {- collection = "warpstream_metrics"- topic_list = "clickhouse_metrics"- group_name = "clickhouse-metrics-avro2"- format = "Avro"- num_consumers = 8- skip_broken_messages = 100- poll_timeout_ms = 3000- poll_max_batch_size = 1000- thread_per_consumer = true- }- }-table "kafka_trace_spans_avro" {settings = {input_format_avro_allow_missing_fields = "1"@@ -1968,92 +1885,6 @@ SQL}}- table "metrics2_input" {- column "uuid" {- type = "String"- }- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "metric_type" {- type = "LowCardinality(String)"- }- 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"- }- column "has_labels" {- type = "Bool"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(LowCardinality(String), String)"- }- column "attributes" {- type = "Map(LowCardinality(String), String)"- }- column "_partition" {- type = "UInt32"- }- column "_topic" {- type = "String"- }- column "_offset" {- type = "UInt64"- }- engine "null" {- }- }-table "metrics4_attributes" {order_by = ["team_id", "metric_name", "attribute_type", "time_bucket", "attribute_key", "attribute_value", "service_name", "original_expiry_time_bucket"]partition_by = "toDate(original_expiry_time_bucket)"@@ -3603,144 +3434,6 @@ SQL}}- materialized_view "kafka_metrics_avro2_mv" {- to_table = "posthog.metrics2_input"- query = <<SQL-SELECT- uuid,- toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,- ifNull(metric_name, '') AS metric_name,- reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,- cityHash64(mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes))) AS resource_fingerprint,- timestamp,- observed_timestamp,- timestamp- + toIntervalDay(- assumeNotNull(- if(- (retention_days IS NOT NULL) AND (retention_days > 0),- retention_days,- toInt32OrDefault(_headers.value[indexOf(_headers.name, 'retention-days')], toInt32(30))- )- )- ) AS original_expiry_timestamp,- ifNull(service_name, '') AS service_name,- ifNull(metric_type, '') AS metric_type,- 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,- toBool(ifNull(has_labels, 1)) AS has_labels,- ifNull(unit, '') AS unit,- ifNull(aggregation_temporality, '') AS aggregation_temporality,- ifNull(is_monotonic, 0) AS is_monotonic,- ifNull(instrumentation_scope, '') AS instrumentation_scope,- if(- toBool(ifNull(has_labels, 1)),- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)),- CAST(map(), 'Map(String, String)')- ) AS resource_attributes,- if(- toBool(ifNull(has_labels, 1)),- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), attributes)),- CAST(map(), 'Map(String, String)')- ) AS attributes,- _partition,- _topic,- _offset-FROM posthog.kafka_metrics_avro2-WHERE kafka_metrics_avro2.series_fingerprint IS NOT NULL-SETTINGS- min_insert_block_size_rows = 0,- min_insert_block_size_bytes = 0-SQL-- column "uuid" {- type = "String"- }- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "String"- }- column "series_fingerprint" {- type = "UInt64"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "String"- }- column "metric_type" {- type = "String"- }- 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"- }- column "has_labels" {- type = "Bool"- }- column "unit" {- type = "String"- }- column "aggregation_temporality" {- type = "String"- }- column "is_monotonic" {- type = "UInt8"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(String, String)"- }- column "attributes" {- type = "Map(String, String)"- }- column "_partition" {- type = "UInt64"- }- column "_topic" {- type = "LowCardinality(String)"- }- column "_offset" {- type = "UInt64"- }- }-materialized_view "kafka_trace_spans_avro_mv" {to_table = "posthog.trace_spans"query = <<SQL@@ -4063,509 +3756,6 @@ SQL}}- materialized_view "metrics2_input_to_metric_attributes" {- to_table = "posthog.metric_attributes2"- query = <<SQL-SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, time_bucket, original_expiry_time_bucket, service_name, filtered_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 "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-- materialized_view "metrics2_input_to_metric_attributes3" {- to_table = "posthog.metric_attributes3"- query = <<SQL-SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- )-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-- materialized_view "metrics2_input_to_metric_names3" {- to_table = "posthog.metric_names3"- query = <<SQL-SELECT- team_id,- metric_name,- toStartOfHour(timestamp) AS time_bucket,- toStartOfHour(input.original_expiry_timestamp) AS original_expiry_time_bucket,- maxSimpleState(input.original_expiry_timestamp) AS original_expiry_timestamp-FROM posthog.metrics2_input AS input-WHERE has_labels-GROUP BY- team_id, time_bucket, metric_name, original_expiry_time_bucket-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_timestamp" {- type = "SimpleAggregateFunction(max, DateTime64(6))"- }- }-- materialized_view "metrics2_input_to_metric_series" {- to_table = "posthog.metric_series2"- query = <<SQL-SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp-FROM posthog.metrics2_input-WHERE has_labels-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "metric_type" {- type = "LowCardinality(String)"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(LowCardinality(String), String)"- }- column "attributes" {- type = "Map(LowCardinality(String), String)"- }- column "last_seen" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- }-- materialized_view "metrics2_input_to_metric_series3" {- to_table = "posthog.metric_series3"- query = <<SQL-SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp-FROM posthog.metrics2_input-WHERE has_labels-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "metric_type" {- type = "LowCardinality(String)"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(LowCardinality(String), String)"- }- column "attributes" {- type = "Map(LowCardinality(String), String)"- }- column "last_seen" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- }-- materialized_view "metrics2_input_to_metrics" {- to_table = "posthog.metrics2"- query = <<SQL-SELECT- team_id,- metric_name,- series_fingerprint,- resource_fingerprint,- timestamp,- observed_timestamp,- original_expiry_timestamp,- service_name,- metric_type,- value,- count,- histogram_bounds,- histogram_counts,- trace_id,- span_id,- trace_flags,- has_labels,- unit,- aggregation_temporality,- is_monotonic,- instrumentation_scope,- _partition,- _topic,- _offset-FROM posthog.metrics2_input-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "metric_type" {- type = "LowCardinality(String)"- }- 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"- }- column "has_labels" {- type = "Bool"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "instrumentation_scope" {- type = "String"- }- column "_partition" {- type = "UInt32"- }- column "_topic" {- type = "String"- }- column "_offset" {- type = "UInt64"- }- }-- materialized_view "metrics2_input_to_resource_attributes" {- to_table = "posthog.metric_attributes2"- query = <<SQL-SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, time_bucket, original_expiry_time_bucket, service_name, filtered_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 "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-- materialized_view "metrics2_input_to_resource_attributes3" {- to_table = "posthog.metric_attributes3"- query = <<SQL-SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- )-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-materialized_view "ops_query_log_archive_mv" {to_table = "posthog.writable_query_log_archive"query = <<SQLdiff --git a/posthog/clickhouse/hcl/golden/prod-us/logs.hcl b/posthog/clickhouse/hcl/golden/prod-us/logs.hclindex 57890e5f41da..fdb556e27ef5 100644--- a/posthog/clickhouse/hcl/golden/prod-us/logs.hcl+++ b/posthog/clickhouse/hcl/golden/prod-us/logs.hcl@@ -1,87 +1,4 @@database "posthog" {- table "kafka_metrics_avro2" {- settings = {- input_format_avro_allow_missing_fields = "1"- }- column "uuid" {- type = "String"- }- column "trace_id" {- type = "String"- }- column "span_id" {- type = "String"- }- column "trace_flags" {- type = "Nullable(Int32)"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "Nullable(String)"- }- column "metric_name" {- type = "Nullable(String)"- }- column "metric_type" {- type = "Nullable(String)"- }- column "value" {- type = "Nullable(Float64)"- }- column "count" {- type = "Nullable(Int64)"- }- column "histogram_bounds" {- type = "Array(Float64)"- }- column "histogram_counts" {- type = "Array(Int64)"- }- column "unit" {- type = "Nullable(String)"- }- column "aggregation_temporality" {- type = "Nullable(String)"- }- column "is_monotonic" {- type = "Nullable(UInt8)"- }- column "resource_attributes" {- type = "Map(String, String)"- }- column "instrumentation_scope" {- type = "Nullable(String)"- }- column "attributes" {- type = "Map(String, String)"- }- column "series_fingerprint" {- type = "Nullable(Int64)"- }- column "has_labels" {- type = "Nullable(UInt8)"- }- column "retention_days" {- type = "Nullable(Int32)"- }- engine "kafka" {- collection = "warpstream_metrics"- topic_list = "clickhouse_metrics"- group_name = "clickhouse-metrics-avro2"- format = "Avro"- num_consumers = 8- skip_broken_messages = 100- poll_timeout_ms = 3000- poll_max_batch_size = 1000- thread_per_consumer = true- }- }-table "kafka_trace_spans_avro" {settings = {input_format_avro_allow_missing_fields = "1"@@ -1968,92 +1885,6 @@ SQL}}- table "metrics2_input" {- column "uuid" {- type = "String"- }- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "metric_type" {- type = "LowCardinality(String)"- }- 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"- }- column "has_labels" {- type = "Bool"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(LowCardinality(String), String)"- }- column "attributes" {- type = "Map(LowCardinality(String), String)"- }- column "_partition" {- type = "UInt32"- }- column "_topic" {- type = "String"- }- column "_offset" {- type = "UInt64"- }- engine "null" {- }- }-table "metrics4_attributes" {order_by = ["team_id", "metric_name", "attribute_type", "time_bucket", "attribute_key", "attribute_value", "service_name", "original_expiry_time_bucket"]partition_by = "toDate(original_expiry_time_bucket)"@@ -3585,144 +3416,6 @@ SQL}}- materialized_view "kafka_metrics_avro2_mv" {- to_table = "posthog.metrics2_input"- query = <<SQL-SELECT- uuid,- toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,- ifNull(metric_name, '') AS metric_name,- reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,- cityHash64(mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes))) AS resource_fingerprint,- timestamp,- observed_timestamp,- timestamp- + toIntervalDay(- assumeNotNull(- if(- (retention_days IS NOT NULL) AND (retention_days > 0),- retention_days,- toInt32OrDefault(_headers.value[indexOf(_headers.name, 'retention-days')], toInt32(30))- )- )- ) AS original_expiry_timestamp,- ifNull(service_name, '') AS service_name,- ifNull(metric_type, '') AS metric_type,- 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,- toBool(ifNull(has_labels, 1)) AS has_labels,- ifNull(unit, '') AS unit,- ifNull(aggregation_temporality, '') AS aggregation_temporality,- ifNull(is_monotonic, 0) AS is_monotonic,- ifNull(instrumentation_scope, '') AS instrumentation_scope,- if(- toBool(ifNull(has_labels, 1)),- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)),- CAST(map(), 'Map(String, String)')- ) AS resource_attributes,- if(- toBool(ifNull(has_labels, 1)),- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), attributes)),- CAST(map(), 'Map(String, String)')- ) AS attributes,- _partition,- _topic,- _offset-FROM posthog.kafka_metrics_avro2-WHERE kafka_metrics_avro2.series_fingerprint IS NOT NULL-SETTINGS- min_insert_block_size_rows = 0,- min_insert_block_size_bytes = 0-SQL-- column "uuid" {- type = "String"- }- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "String"- }- column "series_fingerprint" {- type = "UInt64"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "String"- }- column "metric_type" {- type = "String"- }- 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"- }- column "has_labels" {- type = "Bool"- }- column "unit" {- type = "String"- }- column "aggregation_temporality" {- type = "String"- }- column "is_monotonic" {- type = "UInt8"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(String, String)"- }- column "attributes" {- type = "Map(String, String)"- }- column "_partition" {- type = "UInt64"- }- column "_topic" {- type = "LowCardinality(String)"- }- column "_offset" {- type = "UInt64"- }- }-materialized_view "kafka_trace_spans_avro_mv" {to_table = "posthog.trace_spans"query = <<SQL@@ -4045,509 +3738,6 @@ SQL}}- materialized_view "metrics2_input_to_metric_attributes" {- to_table = "posthog.metric_attributes2"- query = <<SQL-SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, time_bucket, original_expiry_time_bucket, service_name, filtered_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 "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-- materialized_view "metrics2_input_to_metric_attributes3" {- to_table = "posthog.metric_attributes3"- query = <<SQL-SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- )-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-- materialized_view "metrics2_input_to_metric_names3" {- to_table = "posthog.metric_names3"- query = <<SQL-SELECT- team_id,- metric_name,- toStartOfHour(timestamp) AS time_bucket,- toStartOfHour(input.original_expiry_timestamp) AS original_expiry_time_bucket,- maxSimpleState(input.original_expiry_timestamp) AS original_expiry_timestamp-FROM posthog.metrics2_input AS input-WHERE has_labels-GROUP BY- team_id, time_bucket, metric_name, original_expiry_time_bucket-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_timestamp" {- type = "SimpleAggregateFunction(max, DateTime64(6))"- }- }-- materialized_view "metrics2_input_to_metric_series" {- to_table = "posthog.metric_series2"- query = <<SQL-SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp-FROM posthog.metrics2_input-WHERE has_labels-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "metric_type" {- type = "LowCardinality(String)"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(LowCardinality(String), String)"- }- column "attributes" {- type = "Map(LowCardinality(String), String)"- }- column "last_seen" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- }-- materialized_view "metrics2_input_to_metric_series3" {- to_table = "posthog.metric_series3"- query = <<SQL-SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp-FROM posthog.metrics2_input-WHERE has_labels-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "metric_type" {- type = "LowCardinality(String)"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(LowCardinality(String), String)"- }- column "attributes" {- type = "Map(LowCardinality(String), String)"- }- column "last_seen" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- }-- materialized_view "metrics2_input_to_metrics" {- to_table = "posthog.metrics2"- query = <<SQL-SELECT- team_id,- metric_name,- series_fingerprint,- resource_fingerprint,- timestamp,- observed_timestamp,- original_expiry_timestamp,- service_name,- metric_type,- value,- count,- histogram_bounds,- histogram_counts,- trace_id,- span_id,- trace_flags,- has_labels,- unit,- aggregation_temporality,- is_monotonic,- instrumentation_scope,- _partition,- _topic,- _offset-FROM posthog.metrics2_input-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "metric_type" {- type = "LowCardinality(String)"- }- 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"- }- column "has_labels" {- type = "Bool"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "instrumentation_scope" {- type = "String"- }- column "_partition" {- type = "UInt32"- }- column "_topic" {- type = "String"- }- column "_offset" {- type = "UInt64"- }- }-- materialized_view "metrics2_input_to_resource_attributes" {- to_table = "posthog.metric_attributes2"- query = <<SQL-SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, time_bucket, original_expiry_time_bucket, service_name, filtered_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 "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-- materialized_view "metrics2_input_to_resource_attributes3" {- to_table = "posthog.metric_attributes3"- query = <<SQL-SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- )-SQL-- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }-materialized_view "ops_query_log_archive_mv" {to_table = "posthog.writable_query_log_archive"query = <<SQLdiff --git a/posthog/clickhouse/hcl/roles/logs/dev/patches.hcl b/posthog/clickhouse/hcl/roles/logs/dev/patches.hclindex d96327533010..23d46f6f1852 100644--- a/posthog/clickhouse/hcl/roles/logs/dev/patches.hcl+++ b/posthog/clickhouse/hcl/roles/logs/dev/patches.hcl@@ -14,21 +14,6 @@ database "posthog" {}}- patch_table "kafka_metrics_avro2" {- engine "kafka" {- collection = "warpstream_metrics"- topic_list = "clickhouse_metrics"- group_name = "clickhouse-metrics-avro2"- format = "Avro"- num_consumers = 4- skip_broken_messages = 100- poll_timeout_ms = 10000- poll_max_batch_size = 500- flush_interval_ms = 10000- thread_per_consumer = true- }- }-patch_table "trace_attributes_distributed" {engine "distributed" {cluster_name = "logs"diff --git a/posthog/clickhouse/hcl/roles/logs/local/tables.hcl b/posthog/clickhouse/hcl/roles/logs/local/tables.hclindex f1705c83903b..1e4a2fed2769 100644--- a/posthog/clickhouse/hcl/roles/logs/local/tables.hcl+++ b/posthog/clickhouse/hcl/roles/logs/local/tables.hcl@@ -631,22 +631,6 @@ SQL}- # Local stacks create every topic with one partition, so only one consumer of this group can- # get an assignment. The rest retry forever, which holds threads and floods the server log.- patch_table "kafka_metrics_avro2" {- engine "kafka" {- collection = "warpstream_metrics"- topic_list = "clickhouse_metrics"- group_name = "clickhouse-metrics-avro2"- format = "Avro"- num_consumers = 1- skip_broken_messages = 100- poll_timeout_ms = 3000- poll_max_batch_size = 1000- thread_per_consumer = true- }- }-patch_table "kafka_trace_spans_avro" {engine "kafka" {collection = "warpstream_traces"diff --git a/posthog/clickhouse/hcl/roles/logs/metrics/metadata3.hcl b/posthog/clickhouse/hcl/roles/logs/metrics/metadata3.hclindex 4015af11797e..26db28c5c32e 100644--- a/posthog/clickhouse/hcl/roles/logs/metrics/metadata3.hcl+++ b/posthog/clickhouse/hcl/roles/logs/metrics/metadata3.hcl@@ -26,25 +26,6 @@ database "posthog" {replica_name = "{replica}-{shard}"}}- materialized_view "metrics2_input_to_metric_names3" {- to_table = "posthog.metric_names3"- query = file("sql/metrics2_input_to_metric_names3.sql")- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_timestamp" {- type = "SimpleAggregateFunction(max, DateTime64(6))"- }- }table "metric_series3" {partition_by = "toDate(original_expiry_timestamp)"order_by = ["team_id", "metric_name", "series_fingerprint"]@@ -188,109 +169,4 @@ database "posthog" {replica_name = "{replica}-{shard}"}}- materialized_view "metrics2_input_to_metric_series3" {- to_table = "posthog.metric_series3"- query = file("sql/metrics2_input_to_metric_series3.sql")- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "metric_type" {- type = "LowCardinality(String)"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(LowCardinality(String), String)"- }- column "attributes" {- type = "Map(LowCardinality(String), String)"- }- column "last_seen" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- }- materialized_view "metrics2_input_to_metric_attributes3" {- to_table = "posthog.metric_attributes3"- query = file("sql/metrics2_input_to_metric_attributes3.sql")- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }- materialized_view "metrics2_input_to_resource_attributes3" {- to_table = "posthog.metric_attributes3"- query = file("sql/metrics2_input_to_resource_attributes3.sql")- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "time_bucket" {- type = "DateTime64(0)"- }- column "original_expiry_time_bucket" {- type = "DateTime64(0)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }}diff --git a/posthog/clickhouse/hcl/roles/logs/metrics/sql/kafka_metrics_avro2_mv.sql b/posthog/clickhouse/hcl/roles/logs/metrics/sql/kafka_metrics_avro2_mv.sqldeleted file mode 100644index 133358c3846f..000000000000--- a/posthog/clickhouse/hcl/roles/logs/metrics/sql/kafka_metrics_avro2_mv.sql+++ /dev/null@@ -1,33 +0,0 @@-SELECT- uuid,- toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,- ifNull(metric_name, '') AS metric_name,- reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,- cityHash64(mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes))) AS resource_fingerprint,- timestamp,- observed_timestamp,- timestamp + toIntervalDay(assumeNotNull(if((retention_days IS NOT NULL) AND (retention_days > 0), retention_days, toInt32OrDefault(_headers.value[indexOf(_headers.name, 'retention-days')], toInt32(30))))) AS original_expiry_timestamp,- ifNull(service_name, '') AS service_name,- ifNull(metric_type, '') AS metric_type,- 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,- toBool(ifNull(has_labels, 1)) AS has_labels,- ifNull(unit, '') AS unit,- ifNull(aggregation_temporality, '') AS aggregation_temporality,- ifNull(is_monotonic, 0) AS is_monotonic,- ifNull(instrumentation_scope, '') AS instrumentation_scope,- if(toBool(ifNull(has_labels, 1)), mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)), CAST(map(), 'Map(String, String)')) AS resource_attributes,- if(toBool(ifNull(has_labels, 1)), mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), attributes)), CAST(map(), 'Map(String, String)')) AS attributes,- _partition,- _topic,- _offset-FROM posthog.kafka_metrics_avro2-WHERE kafka_metrics_avro2.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/metrics/sql/metrics2_input_to_metric_attributes.sql b/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics2_input_to_metric_attributes.sqldeleted file mode 100644index 291d7f196d2c..000000000000--- a/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics2_input_to_metric_attributes.sql+++ /dev/null@@ -1,27 +0,0 @@-SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- )diff --git a/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics2_input_to_metric_attributes3.sql b/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics2_input_to_metric_attributes3.sqldeleted file mode 100644index 880a76e211d6..000000000000--- a/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics2_input_to_metric_attributes3.sql+++ /dev/null@@ -1,29 +0,0 @@-SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- )diff --git a/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics2_input_to_metric_names3.sql b/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics2_input_to_metric_names3.sqldeleted file mode 100644index 78a4b1a53c24..000000000000--- a/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics2_input_to_metric_names3.sql+++ /dev/null@@ -1,9 +0,0 @@-SELECT- team_id,- metric_name,- toStartOfHour(timestamp) AS time_bucket,- toStartOfHour(input.original_expiry_timestamp) AS original_expiry_time_bucket,- maxSimpleState(input.original_expiry_timestamp) AS original_expiry_timestamp-FROM posthog.metrics2_input AS input-WHERE has_labels-GROUP BY team_id, time_bucket, metric_name, original_expiry_time_bucketdiff --git a/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics2_input_to_metric_series.sql b/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics2_input_to_metric_series.sqldeleted file mode 100644index 43e893aebd5c..000000000000--- a/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics2_input_to_metric_series.sql+++ /dev/null@@ -1,16 +0,0 @@-SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp-FROM posthog.metrics2_input-WHERE has_labelsdiff --git a/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics2_input_to_metric_series3.sql b/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics2_input_to_metric_series3.sqldeleted file mode 100644index 43e893aebd5c..000000000000--- a/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics2_input_to_metric_series3.sql+++ /dev/null@@ -1,16 +0,0 @@-SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp-FROM posthog.metrics2_input-WHERE has_labelsdiff --git a/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics2_input_to_metrics.sql b/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics2_input_to_metrics.sqldeleted file mode 100644index 27c4344af7cb..000000000000--- a/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics2_input_to_metrics.sql+++ /dev/null@@ -1,26 +0,0 @@-SELECT- team_id,- metric_name,- series_fingerprint,- resource_fingerprint,- timestamp,- observed_timestamp,- original_expiry_timestamp,- service_name,- metric_type,- value,- count,- histogram_bounds,- histogram_counts,- trace_id,- span_id,- trace_flags,- has_labels,- unit,- aggregation_temporality,- is_monotonic,- instrumentation_scope,- _partition,- _topic,- _offset-FROM posthog.metrics2_inputdiff --git a/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics2_input_to_resource_attributes.sql b/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics2_input_to_resource_attributes.sqldeleted file mode 100644index df4d039e6caa..000000000000--- a/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics2_input_to_resource_attributes.sql+++ /dev/null@@ -1,27 +0,0 @@-SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- )diff --git a/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics2_input_to_resource_attributes3.sql b/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics2_input_to_resource_attributes3.sqldeleted file mode 100644index 91acde351cdb..000000000000--- a/posthog/clickhouse/hcl/roles/logs/metrics/sql/metrics2_input_to_resource_attributes3.sql+++ /dev/null@@ -1,29 +0,0 @@-SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- )diff --git a/posthog/clickhouse/hcl/roles/logs/metrics/tables.hcl b/posthog/clickhouse/hcl/roles/logs/metrics/tables.hclindex 4ddfa0dd137e..e77fd3122324 100644--- a/posthog/clickhouse/hcl/roles/logs/metrics/tables.hcl+++ b/posthog/clickhouse/hcl/roles/logs/metrics/tables.hcl@@ -1,5 +1,5 @@-# This layer defines LOGS role metric storage and the metrics2 ingest chain.-# The legacy Kafka table remains for lag bookkeeping.+# This layer defines LOGS role metric storage. Nothing ingests into the metrics2+# tables now. They stay until their TTL clears the rows.# Patches in roles/logs/shared restore the cloud ZK paths.# The prod codec deltas sit in roles/logs/prod.# The local codec deltas for value and count sit in roles/logs/local.@@ -329,257 +329,6 @@ SQL}}- table "kafka_metrics_avro2" {- column "uuid" {- type = "String"- }- column "trace_id" {- type = "String"- }- column "span_id" {- type = "String"- }- column "trace_flags" {- type = "Nullable(Int32)"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "Nullable(String)"- }- column "metric_name" {- type = "Nullable(String)"- }- column "metric_type" {- type = "Nullable(String)"- }- column "value" {- type = "Nullable(Float64)"- }- column "count" {- type = "Nullable(Int64)"- }- column "histogram_bounds" {- type = "Array(Float64)"- }- column "histogram_counts" {- type = "Array(Int64)"- }- column "unit" {- type = "Nullable(String)"- }- column "aggregation_temporality" {- type = "Nullable(String)"- }- column "is_monotonic" {- type = "Nullable(UInt8)"- }- column "resource_attributes" {- type = "Map(String, String)"- }- column "instrumentation_scope" {- type = "Nullable(String)"- }- column "attributes" {- type = "Map(String, String)"- }- column "series_fingerprint" {- type = "Nullable(Int64)"- }- column "has_labels" {- type = "Nullable(UInt8)"- }- column "retention_days" {- type = "Nullable(Int32)"- }- engine "kafka" {- collection = "warpstream_metrics"- topic_list = "clickhouse_metrics"- group_name = "clickhouse-metrics-avro2"- format = "Avro"- num_consumers = 8- skip_broken_messages = 100- poll_timeout_ms = 3000- poll_max_batch_size = 1000- thread_per_consumer = true- }- settings = {- input_format_avro_allow_missing_fields = "1"- }- }- materialized_view "kafka_metrics_avro2_mv" {- to_table = "posthog.metrics2_input"- query = file("sql/kafka_metrics_avro2_mv.sql")- column "uuid" {- type = "String"- }- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "String"- }- column "series_fingerprint" {- type = "UInt64"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "String"- }- column "metric_type" {- type = "String"- }- 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"- }- column "has_labels" {- type = "Bool"- }- column "unit" {- type = "String"- }- column "aggregation_temporality" {- type = "String"- }- column "is_monotonic" {- type = "UInt8"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(String, String)"- }- column "attributes" {- type = "Map(String, String)"- }- column "_partition" {- type = "UInt64"- }- column "_topic" {- type = "LowCardinality(String)"- }- column "_offset" {- type = "UInt64"- }- }- table "metrics2_input" {- column "uuid" {- type = "String"- }- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "metric_type" {- type = "LowCardinality(String)"- }- 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"- }- column "has_labels" {- type = "Bool"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(LowCardinality(String), String)"- }- column "attributes" {- type = "Map(LowCardinality(String), String)"- }- column "_partition" {- type = "UInt32"- }- column "_topic" {- type = "String"- }- column "_offset" {- type = "UInt64"- }- engine "null" {}- }table "metrics2" {order_by = ["team_id", "metric_name", "time_bucket", "series_fingerprint", "timestamp"]partition_by = "toDate(original_expiry_timestamp)"@@ -1046,179 +795,4 @@ SQLremote_table = "metric_attributes2"}}- materialized_view "metrics2_input_to_metrics" {- to_table = "posthog.metrics2"- query = file("sql/metrics2_input_to_metrics.sql")- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "resource_fingerprint" {- type = "UInt64"- }- column "timestamp" {- type = "DateTime64(6)"- }- column "observed_timestamp" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "metric_type" {- type = "LowCardinality(String)"- }- 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"- }- column "has_labels" {- type = "Bool"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "instrumentation_scope" {- type = "String"- }- column "_partition" {- type = "UInt32"- }- column "_topic" {- type = "String"- }- column "_offset" {- type = "UInt64"- }- }- materialized_view "metrics2_input_to_metric_series" {- to_table = "posthog.metric_series2"- query = file("sql/metrics2_input_to_metric_series.sql")- column "team_id" {- type = "Int32"- }- column "metric_name" {- type = "LowCardinality(String)"- }- column "series_fingerprint" {- type = "UInt64"- }- column "metric_type" {- type = "LowCardinality(String)"- }- column "unit" {- type = "LowCardinality(String)"- }- column "aggregation_temporality" {- type = "LowCardinality(String)"- }- column "is_monotonic" {- type = "Bool"- }- column "service_name" {- type = "LowCardinality(String)"- }- column "instrumentation_scope" {- type = "String"- }- column "resource_attributes" {- type = "Map(LowCardinality(String), String)"- }- column "attributes" {- type = "Map(LowCardinality(String), String)"- }- column "last_seen" {- type = "DateTime64(6)"- }- column "original_expiry_timestamp" {- type = "DateTime64(6)"- }- }- materialized_view "metrics2_input_to_metric_attributes" {- to_table = "posthog.metric_attributes2"- query = file("sql/metrics2_input_to_metric_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 "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }- materialized_view "metrics2_input_to_resource_attributes" {- to_table = "posthog.metric_attributes2"- query = file("sql/metrics2_input_to_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 "attribute_key" {- type = "LowCardinality(String)"- }- column "attribute_value" {- type = "String"- }- column "attribute_type" {- type = "LowCardinality(String)"- }- column "attribute_count" {- type = "SimpleAggregateFunction(sum, UInt64)"- }- }}diff --git a/posthog/clickhouse/hcl/roles/logs/shared/patches.hcl b/posthog/clickhouse/hcl/roles/logs/shared/patches.hclindex 783b83970b45..6e874ad83c82 100644--- a/posthog/clickhouse/hcl/roles/logs/shared/patches.hcl+++ b/posthog/clickhouse/hcl/roles/logs/shared/patches.hcl@@ -121,9 +121,9 @@ database "posthog" {# (noshard ZK paths, posthog_single_shard reader); the cloud envs keep their# per-shard logs-cluster paths for metrics1, metric_attributes and# metrics_kafka_metrics, and read through the logs cluster. The v2 chain- # (metrics2_input, metrics2, metric_series2, metric_attributes2) stays on the+ # tables (metrics2, metric_series2, metric_attributes2) stay on the# noshard path in every env, like metric_samples1 and metric_series1, and only- # its readers are patched above.+ # their readers are patched above.patch_table "metrics" {engine "distributed" {cluster_name = "logs"diff --git a/posthog/clickhouse/hcl/sql/dev/logs.sql b/posthog/clickhouse/hcl/sql/dev/logs.sqlindex 18ee358c43fa..2c8b365b36ad 100644--- a/posthog/clickhouse/hcl/sql/dev/logs.sql+++ b/posthog/clickhouse/hcl/sql/dev/logs.sql@@ -1,30 +1,6 @@-- AUTO-GENERATED from the declarative HCL by ops/gen-sql.sh — do not edit.-- Full CREATE schema for the dev/logs node. Apply to a fresh ClickHouse to build it.-CREATE TABLE posthog.kafka_metrics_avro2 (- uuid String,- trace_id String,- span_id String,- trace_flags Nullable(Int32),- timestamp DateTime64(6),- observed_timestamp DateTime64(6),- service_name Nullable(String),- metric_name Nullable(String),- metric_type Nullable(String),- value Nullable(Float64),- count Nullable(Int64),- histogram_bounds Array(Float64),- histogram_counts Array(Int64),- unit Nullable(String),- aggregation_temporality Nullable(String),- is_monotonic Nullable(UInt8),- resource_attributes Map(String, String),- instrumentation_scope Nullable(String),- attributes Map(String, String),- series_fingerprint Nullable(Int64),- has_labels Nullable(UInt8),- retention_days Nullable(Int32)-) ENGINE = Kafka(warpstream_metrics) SETTINGS input_format_avro_allow_missing_fields = 1, kafka_flush_interval_ms = 10000, kafka_format = 'Avro', kafka_group_name = 'clickhouse-metrics-avro2', kafka_num_consumers = 4, kafka_poll_max_batch_size = 500, kafka_poll_timeout_ms = 10000, kafka_skip_broken_messages = 100, kafka_thread_per_consumer = 1, kafka_topic_list = 'clickhouse_metrics';CREATE TABLE posthog.log_attributes2 (team_id Int32,time_bucket DateTime64(0),@@ -473,35 +449,6 @@ CREATE TABLE posthog.metrics2 (GROUP BYteam_id, service_name, metric_name, metric_type, resource_fingerprint, series_fingerprint, hour)) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.metrics2', '{replica}-{shard}') ORDER BY (team_id, metric_name, time_bucket, series_fingerprint, timestamp) PARTITION BY toDate(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS index_granularity = 8192, index_granularity_bytes = 104857600, ttl_only_drop_parts = 1;-CREATE TABLE posthog.metrics2_input (- uuid String,- team_id Int32,- metric_name LowCardinality(String),- series_fingerprint UInt64,- resource_fingerprint UInt64,- timestamp DateTime64(6),- observed_timestamp DateTime64(6),- original_expiry_timestamp DateTime64(6),- service_name LowCardinality(String),- metric_type LowCardinality(String),- value Float64,- count UInt64,- histogram_bounds Array(Float64),- histogram_counts Array(UInt64),- trace_id String,- span_id String,- trace_flags Int32,- has_labels Bool,- unit LowCardinality(String),- aggregation_temporality LowCardinality(String),- is_monotonic Bool,- instrumentation_scope String,- resource_attributes Map(LowCardinality(String), String),- attributes Map(LowCardinality(String), String),- _partition UInt32,- _topic String,- _offset UInt64-) ENGINE = Null();CREATE TABLE posthog.metrics4_attributes (team_id Int32,metric_name LowCardinality(String),@@ -935,56 +882,6 @@ CREATE MATERIALIZED VIEW posthog.kafka_logs_avro_kafka_metrics_mv TO posthog.logFROM posthog.logs34GROUP BY_partition, _topic;-CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro2_mv TO posthog.metrics2_input (uuid String, team_id Int32, metric_name String, series_fingerprint UInt64, resource_fingerprint UInt64, timestamp DateTime64(6), observed_timestamp DateTime64(6), original_expiry_timestamp DateTime64(6), service_name String, metric_type String, value Float64, count UInt64, histogram_bounds Array(Float64), histogram_counts Array(UInt64), trace_id String, span_id String, trace_flags Int32, has_labels Bool, unit String, aggregation_temporality String, is_monotonic UInt8, instrumentation_scope String, resource_attributes Map(String, String), attributes Map(String, String), _partition UInt64, _topic LowCardinality(String), _offset UInt64) AS SELECT- uuid,- toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,- ifNull(metric_name, '') AS metric_name,- reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,- cityHash64(mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes))) AS resource_fingerprint,- timestamp,- observed_timestamp,- timestamp- + toIntervalDay(- assumeNotNull(- if(- (retention_days IS NOT NULL) AND (retention_days > 0),- retention_days,- toInt32OrDefault(_headers.value[indexOf(_headers.name, 'retention-days')], toInt32(30))- )- )- ) AS original_expiry_timestamp,- ifNull(service_name, '') AS service_name,- ifNull(metric_type, '') AS metric_type,- 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,- toBool(ifNull(has_labels, 1)) AS has_labels,- ifNull(unit, '') AS unit,- ifNull(aggregation_temporality, '') AS aggregation_temporality,- ifNull(is_monotonic, 0) AS is_monotonic,- ifNull(instrumentation_scope, '') AS instrumentation_scope,- if(- toBool(ifNull(has_labels, 1)),- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)),- CAST(map(), 'Map(String, String)')- ) AS resource_attributes,- if(- toBool(ifNull(has_labels, 1)),- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), attributes)),- CAST(map(), 'Map(String, String)')- ) AS attributes,- _partition,- _topic,- _offset-FROM posthog.kafka_metrics_avro2-WHERE kafka_metrics_avro2.series_fingerprint IS NOT NULL-SETTINGS- min_insert_block_size_rows = 0,- min_insert_block_size_bytes = 0;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 SELECTteam_id,time_bucket,@@ -1088,186 +985,6 @@ FROM)GROUP BYteam_id, time_bucket, service_name, namespace, environment, severity_text;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_attributes TO posthog.metric_attributes2 (team_id Int32, time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- );-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_attributes3 TO posthog.metric_attributes3 (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- );-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_names3 TO posthog.metric_names3 (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), original_expiry_timestamp SimpleAggregateFunction(max, DateTime64(6))) AS SELECT- team_id,- metric_name,- toStartOfHour(timestamp) AS time_bucket,- toStartOfHour(input.original_expiry_timestamp) AS original_expiry_time_bucket,- maxSimpleState(input.original_expiry_timestamp) AS original_expiry_timestamp-FROM posthog.metrics2_input AS input-WHERE has_labels-GROUP BY- team_id, time_bucket, metric_name, original_expiry_time_bucket;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_series TO posthog.metric_series2 (team_id Int32, metric_name LowCardinality(String), series_fingerprint UInt64, metric_type LowCardinality(String), unit LowCardinality(String), aggregation_temporality LowCardinality(String), is_monotonic Bool, service_name LowCardinality(String), instrumentation_scope String, resource_attributes Map(LowCardinality(String), String), attributes Map(LowCardinality(String), String), last_seen DateTime64(6), original_expiry_timestamp DateTime64(6)) AS SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp-FROM posthog.metrics2_input-WHERE has_labels;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_series3 TO posthog.metric_series3 (team_id Int32, metric_name LowCardinality(String), series_fingerprint UInt64, metric_type LowCardinality(String), unit LowCardinality(String), aggregation_temporality LowCardinality(String), is_monotonic Bool, service_name LowCardinality(String), instrumentation_scope String, resource_attributes Map(LowCardinality(String), String), attributes Map(LowCardinality(String), String), last_seen DateTime64(6), original_expiry_timestamp DateTime64(6)) AS SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp-FROM posthog.metrics2_input-WHERE has_labels;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metrics TO posthog.metrics2 (team_id Int32, metric_name LowCardinality(String), series_fingerprint UInt64, resource_fingerprint UInt64, timestamp DateTime64(6), observed_timestamp DateTime64(6), original_expiry_timestamp DateTime64(6), service_name LowCardinality(String), metric_type LowCardinality(String), value Float64, count UInt64, histogram_bounds Array(Float64), histogram_counts Array(UInt64), trace_id String, span_id String, trace_flags Int32, has_labels Bool, unit LowCardinality(String), aggregation_temporality LowCardinality(String), is_monotonic Bool, instrumentation_scope String, _partition UInt32, _topic String, _offset UInt64) AS SELECT- team_id,- metric_name,- series_fingerprint,- resource_fingerprint,- timestamp,- observed_timestamp,- original_expiry_timestamp,- service_name,- metric_type,- value,- count,- histogram_bounds,- histogram_counts,- trace_id,- span_id,- trace_flags,- has_labels,- unit,- aggregation_temporality,- is_monotonic,- instrumentation_scope,- _partition,- _topic,- _offset-FROM posthog.metrics2_input;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_resource_attributes TO posthog.metric_attributes2 (team_id Int32, time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- );-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_resource_attributes3 TO posthog.metric_attributes3 (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- );CREATE MATERIALIZED VIEW posthog.ops_query_log_archive_mv TO posthog.writable_query_log_archive (hostname LowCardinality(String), user LowCardinality(String), query_id String, initial_query_id String, is_initial_query UInt8, type Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4), event_date Date, event_time DateTime, event_time_microseconds DateTime64(6), query_start_time DateTime, query_start_time_microseconds DateTime64(6), query_duration_ms UInt64, read_rows UInt64, read_bytes UInt64, written_rows UInt64, written_bytes UInt64, result_rows UInt64, result_bytes UInt64, memory_usage UInt64, peak_threads_usage UInt64, current_database LowCardinality(String), query String, formatted_query String, normalized_query_hash UInt64, query_kind LowCardinality(String), exception_code Int32, exception String, stack_trace String, team_id Int64, log_comment String, ProfileEvents Map(LowCardinality(String), UInt64)) AS SELECThostname,user,diff --git a/posthog/clickhouse/hcl/sql/local-multi/logs.sql b/posthog/clickhouse/hcl/sql/local-multi/logs.sqlindex ea26880d4a15..88a9d6d9a058 100644--- a/posthog/clickhouse/hcl/sql/local-multi/logs.sql+++ b/posthog/clickhouse/hcl/sql/local-multi/logs.sql@@ -1,30 +1,6 @@-- AUTO-GENERATED from the declarative HCL by ops/gen-sql.sh — do not edit.-- Full CREATE schema for the local-multi/logs node. Apply to a fresh ClickHouse to build it.-CREATE TABLE posthog.kafka_metrics_avro2 (- uuid String,- trace_id String,- span_id String,- trace_flags Nullable(Int32),- timestamp DateTime64(6),- observed_timestamp DateTime64(6),- service_name Nullable(String),- metric_name Nullable(String),- metric_type Nullable(String),- value Nullable(Float64),- count Nullable(Int64),- histogram_bounds Array(Float64),- histogram_counts Array(Int64),- unit Nullable(String),- aggregation_temporality Nullable(String),- is_monotonic Nullable(UInt8),- resource_attributes Map(String, String),- instrumentation_scope Nullable(String),- attributes Map(String, String),- series_fingerprint Nullable(Int64),- has_labels Nullable(UInt8),- retention_days Nullable(Int32)-) ENGINE = Kafka(warpstream_metrics) SETTINGS input_format_avro_allow_missing_fields = 1, kafka_format = 'Avro', kafka_group_name = 'clickhouse-metrics-avro2', kafka_num_consumers = 1, kafka_poll_max_batch_size = 1000, kafka_poll_timeout_ms = 3000, kafka_skip_broken_messages = 100, kafka_thread_per_consumer = 1, kafka_topic_list = 'clickhouse_metrics';CREATE TABLE posthog.kafka_trace_spans_avro (uuid String,trace_id String,@@ -565,35 +541,6 @@ CREATE TABLE posthog.metrics2 (GROUP BYteam_id, service_name, metric_name, metric_type, resource_fingerprint, series_fingerprint, hour)) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.metrics2', '{replica}-{shard}') ORDER BY (team_id, metric_name, time_bucket, series_fingerprint, timestamp) PARTITION BY toDate(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS index_granularity = 8192, index_granularity_bytes = 104857600, ttl_only_drop_parts = 1;-CREATE TABLE posthog.metrics2_input (- uuid String,- team_id Int32,- metric_name LowCardinality(String),- series_fingerprint UInt64,- resource_fingerprint UInt64,- timestamp DateTime64(6),- observed_timestamp DateTime64(6),- original_expiry_timestamp DateTime64(6),- service_name LowCardinality(String),- metric_type LowCardinality(String),- value Float64,- count UInt64,- histogram_bounds Array(Float64),- histogram_counts Array(UInt64),- trace_id String,- span_id String,- trace_flags Int32,- has_labels Bool,- unit LowCardinality(String),- aggregation_temporality LowCardinality(String),- is_monotonic Bool,- instrumentation_scope String,- resource_attributes Map(LowCardinality(String), String),- attributes Map(LowCardinality(String), String),- _partition UInt32,- _topic String,- _offset UInt64-) ENGINE = Null();CREATE TABLE posthog.metrics4_attributes (team_id Int32,metric_name LowCardinality(String),@@ -999,56 +946,6 @@ CREATE MATERIALIZED VIEW posthog.kafka_logs_avro_kafka_metrics_mv TO posthog.logFROM posthog.logs34GROUP BY_partition, _topic;-CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro2_mv TO posthog.metrics2_input (uuid String, team_id Int32, metric_name String, series_fingerprint UInt64, resource_fingerprint UInt64, timestamp DateTime64(6), observed_timestamp DateTime64(6), original_expiry_timestamp DateTime64(6), service_name String, metric_type String, value Float64, count UInt64, histogram_bounds Array(Float64), histogram_counts Array(UInt64), trace_id String, span_id String, trace_flags Int32, has_labels Bool, unit String, aggregation_temporality String, is_monotonic UInt8, instrumentation_scope String, resource_attributes Map(String, String), attributes Map(String, String), _partition UInt64, _topic LowCardinality(String), _offset UInt64) AS SELECT- uuid,- toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,- ifNull(metric_name, '') AS metric_name,- reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,- cityHash64(mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes))) AS resource_fingerprint,- timestamp,- observed_timestamp,- timestamp- + toIntervalDay(- assumeNotNull(- if(- (retention_days IS NOT NULL) AND (retention_days > 0),- retention_days,- toInt32OrDefault(_headers.value[indexOf(_headers.name, 'retention-days')], toInt32(30))- )- )- ) AS original_expiry_timestamp,- ifNull(service_name, '') AS service_name,- ifNull(metric_type, '') AS metric_type,- 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,- toBool(ifNull(has_labels, 1)) AS has_labels,- ifNull(unit, '') AS unit,- ifNull(aggregation_temporality, '') AS aggregation_temporality,- ifNull(is_monotonic, 0) AS is_monotonic,- ifNull(instrumentation_scope, '') AS instrumentation_scope,- if(- toBool(ifNull(has_labels, 1)),- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)),- CAST(map(), 'Map(String, String)')- ) AS resource_attributes,- if(- toBool(ifNull(has_labels, 1)),- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), attributes)),- CAST(map(), 'Map(String, String)')- ) AS attributes,- _partition,- _topic,- _offset-FROM posthog.kafka_metrics_avro2-WHERE kafka_metrics_avro2.series_fingerprint IS NOT NULL-SETTINGS- min_insert_block_size_rows = 0,- min_insert_block_size_bytes = 0;CREATE MATERIALIZED VIEW posthog.kafka_trace_spans_avro_mv TO posthog.trace_spans (uuid String, trace_id String, span_id String, parent_span_id String, trace_state String, name String, kind Int8, flags UInt32, timestamp DateTime64(6), end_time DateTime64(6), observed_timestamp DateTime64(6), service_name String, resource_attributes Map(LowCardinality(String), String), instrumentation_scope String, attributes_map_str Map(LowCardinality(String), String), dropped_attributes_count UInt32, events Array(String), dropped_events_count UInt32, links Array(String), dropped_links_count UInt32, status_code Int16, team_id Int32, original_expiry_timestamp DateTime64(6)) AS SELECTuuid,trace_id,@@ -1245,186 +1142,6 @@ FROM)GROUP BYteam_id, time_bucket, service_name, namespace, environment, severity_text;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_attributes TO posthog.metric_attributes2 (team_id Int32, time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- );-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_attributes3 TO posthog.metric_attributes3 (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- );-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_names3 TO posthog.metric_names3 (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), original_expiry_timestamp SimpleAggregateFunction(max, DateTime64(6))) AS SELECT- team_id,- metric_name,- toStartOfHour(timestamp) AS time_bucket,- toStartOfHour(input.original_expiry_timestamp) AS original_expiry_time_bucket,- maxSimpleState(input.original_expiry_timestamp) AS original_expiry_timestamp-FROM posthog.metrics2_input AS input-WHERE has_labels-GROUP BY- team_id, time_bucket, metric_name, original_expiry_time_bucket;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_series TO posthog.metric_series2 (team_id Int32, metric_name LowCardinality(String), series_fingerprint UInt64, metric_type LowCardinality(String), unit LowCardinality(String), aggregation_temporality LowCardinality(String), is_monotonic Bool, service_name LowCardinality(String), instrumentation_scope String, resource_attributes Map(LowCardinality(String), String), attributes Map(LowCardinality(String), String), last_seen DateTime64(6), original_expiry_timestamp DateTime64(6)) AS SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp-FROM posthog.metrics2_input-WHERE has_labels;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_series3 TO posthog.metric_series3 (team_id Int32, metric_name LowCardinality(String), series_fingerprint UInt64, metric_type LowCardinality(String), unit LowCardinality(String), aggregation_temporality LowCardinality(String), is_monotonic Bool, service_name LowCardinality(String), instrumentation_scope String, resource_attributes Map(LowCardinality(String), String), attributes Map(LowCardinality(String), String), last_seen DateTime64(6), original_expiry_timestamp DateTime64(6)) AS SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp-FROM posthog.metrics2_input-WHERE has_labels;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metrics TO posthog.metrics2 (team_id Int32, metric_name LowCardinality(String), series_fingerprint UInt64, resource_fingerprint UInt64, timestamp DateTime64(6), observed_timestamp DateTime64(6), original_expiry_timestamp DateTime64(6), service_name LowCardinality(String), metric_type LowCardinality(String), value Float64, count UInt64, histogram_bounds Array(Float64), histogram_counts Array(UInt64), trace_id String, span_id String, trace_flags Int32, has_labels Bool, unit LowCardinality(String), aggregation_temporality LowCardinality(String), is_monotonic Bool, instrumentation_scope String, _partition UInt32, _topic String, _offset UInt64) AS SELECT- team_id,- metric_name,- series_fingerprint,- resource_fingerprint,- timestamp,- observed_timestamp,- original_expiry_timestamp,- service_name,- metric_type,- value,- count,- histogram_bounds,- histogram_counts,- trace_id,- span_id,- trace_flags,- has_labels,- unit,- aggregation_temporality,- is_monotonic,- instrumentation_scope,- _partition,- _topic,- _offset-FROM posthog.metrics2_input;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_resource_attributes TO posthog.metric_attributes2 (team_id Int32, time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- );-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_resource_attributes3 TO posthog.metric_attributes3 (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- );CREATE MATERIALIZED VIEW posthog.trace_span_to_attributes TO posthog.trace_attributes (team_id Int32, original_expiry_time_bucket DateTime64(0), time_bucket DateTime64(0), service_name LowCardinality(String), resource_fingerprint UInt64, attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,original_expiry_time_bucket,diff --git a/posthog/clickhouse/hcl/sql/local-single/all.sql b/posthog/clickhouse/hcl/sql/local-single/all.sqlindex a1dc5d01994e..60d556164e22 100644--- a/posthog/clickhouse/hcl/sql/local-single/all.sql+++ b/posthog/clickhouse/hcl/sql/local-single/all.sql@@ -599,30 +599,6 @@ CREATE TABLE posthog.kafka_message_assets (is_deleted UInt8,html String) ENGINE = Kafka(warpstream_cyclotron) SETTINGS kafka_format = 'JSONEachRow', kafka_group_name = 'clickhouse_message_assets', kafka_skip_broken_messages = 100, kafka_topic_list = 'clickhouse_message_assets';-CREATE TABLE posthog.kafka_metrics_avro2 (- uuid String,- trace_id String,- span_id String,- trace_flags Nullable(Int32),- timestamp DateTime64(6),- observed_timestamp DateTime64(6),- service_name Nullable(String),- metric_name Nullable(String),- metric_type Nullable(String),- value Nullable(Float64),- count Nullable(Int64),- histogram_bounds Array(Float64),- histogram_counts Array(Int64),- unit Nullable(String),- aggregation_temporality Nullable(String),- is_monotonic Nullable(UInt8),- resource_attributes Map(String, String),- instrumentation_scope Nullable(String),- attributes Map(String, String),- series_fingerprint Nullable(Int64),- has_labels Nullable(UInt8),- retention_days Nullable(Int32)-) ENGINE = Kafka(warpstream_metrics) SETTINGS input_format_avro_allow_missing_fields = 1, kafka_format = 'Avro', kafka_group_name = 'clickhouse-metrics-avro2', kafka_num_consumers = 1, kafka_poll_max_batch_size = 1000, kafka_poll_timeout_ms = 3000, kafka_skip_broken_messages = 100, kafka_thread_per_consumer = 1, kafka_topic_list = 'clickhouse_metrics';CREATE TABLE posthog.kafka_metrics_avro4 (uuid String,trace_id String,@@ -1507,35 +1483,6 @@ CREATE TABLE posthog.metrics2 (GROUP BYteam_id, service_name, metric_name, metric_type, resource_fingerprint, series_fingerprint, hour)) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.metrics2', '{replica}-{shard}') ORDER BY (team_id, metric_name, time_bucket, series_fingerprint, timestamp) PARTITION BY toDate(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS index_granularity = 8192, index_granularity_bytes = 104857600, ttl_only_drop_parts = 1;-CREATE TABLE posthog.metrics2_input (- uuid String,- team_id Int32,- metric_name LowCardinality(String),- series_fingerprint UInt64,- resource_fingerprint UInt64,- timestamp DateTime64(6),- observed_timestamp DateTime64(6),- original_expiry_timestamp DateTime64(6),- service_name LowCardinality(String),- metric_type LowCardinality(String),- value Float64,- count UInt64,- histogram_bounds Array(Float64),- histogram_counts Array(UInt64),- trace_id String,- span_id String,- trace_flags Int32,- has_labels Bool,- unit LowCardinality(String),- aggregation_temporality LowCardinality(String),- is_monotonic Bool,- instrumentation_scope String,- resource_attributes Map(LowCardinality(String), String),- attributes Map(LowCardinality(String), String),- _partition UInt32,- _topic String,- _offset UInt64-) ENGINE = Null();CREATE TABLE posthog.metrics4_attributes (team_id Int32,metric_name LowCardinality(String),@@ -4993,56 +4940,6 @@ CREATE MATERIALIZED VIEW posthog.kafka_logs_avro_kafka_metrics_mv TO posthog.logFROM posthog.logs34GROUP BY_partition, _topic;-CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro2_mv TO posthog.metrics2_input (uuid String, team_id Int32, metric_name String, series_fingerprint UInt64, resource_fingerprint UInt64, timestamp DateTime64(6), observed_timestamp DateTime64(6), original_expiry_timestamp DateTime64(6), service_name String, metric_type String, value Float64, count UInt64, histogram_bounds Array(Float64), histogram_counts Array(UInt64), trace_id String, span_id String, trace_flags Int32, has_labels Bool, unit String, aggregation_temporality String, is_monotonic UInt8, instrumentation_scope String, resource_attributes Map(String, String), attributes Map(String, String), _partition UInt64, _topic LowCardinality(String), _offset UInt64) AS SELECT- uuid,- toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,- ifNull(metric_name, '') AS metric_name,- reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,- cityHash64(mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes))) AS resource_fingerprint,- timestamp,- observed_timestamp,- timestamp- + toIntervalDay(- assumeNotNull(- if(- (retention_days IS NOT NULL) AND (retention_days > 0),- retention_days,- toInt32OrDefault(_headers.value[indexOf(_headers.name, 'retention-days')], toInt32(30))- )- )- ) AS original_expiry_timestamp,- ifNull(service_name, '') AS service_name,- ifNull(metric_type, '') AS metric_type,- 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,- toBool(ifNull(has_labels, 1)) AS has_labels,- ifNull(unit, '') AS unit,- ifNull(aggregation_temporality, '') AS aggregation_temporality,- ifNull(is_monotonic, 0) AS is_monotonic,- ifNull(instrumentation_scope, '') AS instrumentation_scope,- if(- toBool(ifNull(has_labels, 1)),- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)),- CAST(map(), 'Map(String, String)')- ) AS resource_attributes,- if(- toBool(ifNull(has_labels, 1)),- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), attributes)),- CAST(map(), 'Map(String, String)')- ) AS attributes,- _partition,- _topic,- _offset-FROM posthog.kafka_metrics_avro2-WHERE kafka_metrics_avro2.series_fingerprint IS NOT NULL-SETTINGS- min_insert_block_size_rows = 0,- min_insert_block_size_bytes = 0;CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro4_mv TO posthog.metrics4_input (uuid String, team_id Int32, metric_name String, series_fingerprint UInt64, resource_fingerprint UInt64, timestamp DateTime64(6), observed_timestamp DateTime64(6), original_expiry_timestamp DateTime64(6), service_name String, metric_type String, value Float64, count UInt64, histogram_bounds Array(Float64), histogram_counts Array(UInt64), trace_id String, span_id String, trace_flags Int32, has_labels Bool, unit String, aggregation_temporality String, is_monotonic UInt8, instrumentation_scope String, resource_attributes Map(String, String), attributes Map(String, String), _partition UInt64, _topic LowCardinality(String), _offset UInt64) AS SELECTuuid,toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,@@ -5346,186 +5243,6 @@ CREATE MATERIALIZED VIEW posthog.message_assets_mv TO posthog.message_assets_dat_offset,_partitionFROM posthog.kafka_message_assets;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_attributes TO posthog.metric_attributes2 (team_id Int32, time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- );-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_attributes3 TO posthog.metric_attributes3 (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- );-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_names3 TO posthog.metric_names3 (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), original_expiry_timestamp SimpleAggregateFunction(max, DateTime64(6))) AS SELECT- team_id,- metric_name,- toStartOfHour(timestamp) AS time_bucket,- toStartOfHour(input.original_expiry_timestamp) AS original_expiry_time_bucket,- maxSimpleState(input.original_expiry_timestamp) AS original_expiry_timestamp-FROM posthog.metrics2_input AS input-WHERE has_labels-GROUP BY- team_id, time_bucket, metric_name, original_expiry_time_bucket;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_series TO posthog.metric_series2 (team_id Int32, metric_name LowCardinality(String), series_fingerprint UInt64, metric_type LowCardinality(String), unit LowCardinality(String), aggregation_temporality LowCardinality(String), is_monotonic Bool, service_name LowCardinality(String), instrumentation_scope String, resource_attributes Map(LowCardinality(String), String), attributes Map(LowCardinality(String), String), last_seen DateTime64(6), original_expiry_timestamp DateTime64(6)) AS SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp-FROM posthog.metrics2_input-WHERE has_labels;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_series3 TO posthog.metric_series3 (team_id Int32, metric_name LowCardinality(String), series_fingerprint UInt64, metric_type LowCardinality(String), unit LowCardinality(String), aggregation_temporality LowCardinality(String), is_monotonic Bool, service_name LowCardinality(String), instrumentation_scope String, resource_attributes Map(LowCardinality(String), String), attributes Map(LowCardinality(String), String), last_seen DateTime64(6), original_expiry_timestamp DateTime64(6)) AS SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp-FROM posthog.metrics2_input-WHERE has_labels;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metrics TO posthog.metrics2 (team_id Int32, metric_name LowCardinality(String), series_fingerprint UInt64, resource_fingerprint UInt64, timestamp DateTime64(6), observed_timestamp DateTime64(6), original_expiry_timestamp DateTime64(6), service_name LowCardinality(String), metric_type LowCardinality(String), value Float64, count UInt64, histogram_bounds Array(Float64), histogram_counts Array(UInt64), trace_id String, span_id String, trace_flags Int32, has_labels Bool, unit LowCardinality(String), aggregation_temporality LowCardinality(String), is_monotonic Bool, instrumentation_scope String, _partition UInt32, _topic String, _offset UInt64) AS SELECT- team_id,- metric_name,- series_fingerprint,- resource_fingerprint,- timestamp,- observed_timestamp,- original_expiry_timestamp,- service_name,- metric_type,- value,- count,- histogram_bounds,- histogram_counts,- trace_id,- span_id,- trace_flags,- has_labels,- unit,- aggregation_temporality,- is_monotonic,- instrumentation_scope,- _partition,- _topic,- _offset-FROM posthog.metrics2_input;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_resource_attributes TO posthog.metric_attributes2 (team_id Int32, time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- );-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_resource_attributes3 TO posthog.metric_attributes3 (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- );CREATE MATERIALIZED VIEW posthog.metrics4_input_to_metrics4_attributes TO posthog.writable_metrics4_attributes (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECTteam_id,metric_name,diff --git a/posthog/clickhouse/hcl/sql/prod-eu/logs.sql b/posthog/clickhouse/hcl/sql/prod-eu/logs.sqlindex 574a00c73739..bbe28e68ada3 100644--- a/posthog/clickhouse/hcl/sql/prod-eu/logs.sql+++ b/posthog/clickhouse/hcl/sql/prod-eu/logs.sql@@ -1,30 +1,6 @@-- AUTO-GENERATED from the declarative HCL by ops/gen-sql.sh — do not edit.-- Full CREATE schema for the prod-eu/logs node. Apply to a fresh ClickHouse to build it.-CREATE TABLE posthog.kafka_metrics_avro2 (- uuid String,- trace_id String,- span_id String,- trace_flags Nullable(Int32),- timestamp DateTime64(6),- observed_timestamp DateTime64(6),- service_name Nullable(String),- metric_name Nullable(String),- metric_type Nullable(String),- value Nullable(Float64),- count Nullable(Int64),- histogram_bounds Array(Float64),- histogram_counts Array(Int64),- unit Nullable(String),- aggregation_temporality Nullable(String),- is_monotonic Nullable(UInt8),- resource_attributes Map(String, String),- instrumentation_scope Nullable(String),- attributes Map(String, String),- series_fingerprint Nullable(Int64),- has_labels Nullable(UInt8),- retention_days Nullable(Int32)-) ENGINE = Kafka(warpstream_metrics) SETTINGS input_format_avro_allow_missing_fields = 1, kafka_format = 'Avro', kafka_group_name = 'clickhouse-metrics-avro2', 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 = 'clickhouse_metrics';CREATE TABLE posthog.kafka_trace_spans_avro (uuid String,trace_id String,@@ -497,35 +473,6 @@ CREATE TABLE posthog.metrics2 (GROUP BYteam_id, service_name, metric_name, metric_type, resource_fingerprint, series_fingerprint, hour)) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.metrics2', '{replica}-{shard}') ORDER BY (team_id, metric_name, time_bucket, series_fingerprint, timestamp) PARTITION BY toDate(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS index_granularity = 8192, index_granularity_bytes = 104857600, ttl_only_drop_parts = 1;-CREATE TABLE posthog.metrics2_input (- uuid String,- team_id Int32,- metric_name LowCardinality(String),- series_fingerprint UInt64,- resource_fingerprint UInt64,- timestamp DateTime64(6),- observed_timestamp DateTime64(6),- original_expiry_timestamp DateTime64(6),- service_name LowCardinality(String),- metric_type LowCardinality(String),- value Float64,- count UInt64,- histogram_bounds Array(Float64),- histogram_counts Array(UInt64),- trace_id String,- span_id String,- trace_flags Int32,- has_labels Bool,- unit LowCardinality(String),- aggregation_temporality LowCardinality(String),- is_monotonic Bool,- instrumentation_scope String,- resource_attributes Map(LowCardinality(String), String),- attributes Map(LowCardinality(String), String),- _partition UInt32,- _topic String,- _offset UInt64-) ENGINE = Null();CREATE TABLE posthog.metrics4_attributes (team_id Int32,metric_name LowCardinality(String),@@ -974,56 +921,6 @@ CREATE MATERIALIZED VIEW posthog.kafka_logs_avro_kafka_metrics_mv TO posthog.logFROM posthog.logs34GROUP BY_partition, _topic;-CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro2_mv TO posthog.metrics2_input (uuid String, team_id Int32, metric_name String, series_fingerprint UInt64, resource_fingerprint UInt64, timestamp DateTime64(6), observed_timestamp DateTime64(6), original_expiry_timestamp DateTime64(6), service_name String, metric_type String, value Float64, count UInt64, histogram_bounds Array(Float64), histogram_counts Array(UInt64), trace_id String, span_id String, trace_flags Int32, has_labels Bool, unit String, aggregation_temporality String, is_monotonic UInt8, instrumentation_scope String, resource_attributes Map(String, String), attributes Map(String, String), _partition UInt64, _topic LowCardinality(String), _offset UInt64) AS SELECT- uuid,- toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,- ifNull(metric_name, '') AS metric_name,- reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,- cityHash64(mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes))) AS resource_fingerprint,- timestamp,- observed_timestamp,- timestamp- + toIntervalDay(- assumeNotNull(- if(- (retention_days IS NOT NULL) AND (retention_days > 0),- retention_days,- toInt32OrDefault(_headers.value[indexOf(_headers.name, 'retention-days')], toInt32(30))- )- )- ) AS original_expiry_timestamp,- ifNull(service_name, '') AS service_name,- ifNull(metric_type, '') AS metric_type,- 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,- toBool(ifNull(has_labels, 1)) AS has_labels,- ifNull(unit, '') AS unit,- ifNull(aggregation_temporality, '') AS aggregation_temporality,- ifNull(is_monotonic, 0) AS is_monotonic,- ifNull(instrumentation_scope, '') AS instrumentation_scope,- if(- toBool(ifNull(has_labels, 1)),- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)),- CAST(map(), 'Map(String, String)')- ) AS resource_attributes,- if(- toBool(ifNull(has_labels, 1)),- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), attributes)),- CAST(map(), 'Map(String, String)')- ) AS attributes,- _partition,- _topic,- _offset-FROM posthog.kafka_metrics_avro2-WHERE kafka_metrics_avro2.series_fingerprint IS NOT NULL-SETTINGS- min_insert_block_size_rows = 0,- min_insert_block_size_bytes = 0;CREATE MATERIALIZED VIEW posthog.kafka_trace_spans_avro_mv TO posthog.trace_spans (uuid String, trace_id String, span_id String, parent_span_id String, trace_state String, name String, kind Int8, flags UInt32, timestamp DateTime64(6), end_time DateTime64(6), observed_timestamp DateTime64(6), service_name String, resource_attributes Map(LowCardinality(String), String), instrumentation_scope String, attributes_map_str Map(LowCardinality(String), String), dropped_attributes_count UInt32, events Array(String), dropped_events_count UInt32, links Array(String), dropped_links_count UInt32, status_code Int16, team_id Int32, original_expiry_timestamp DateTime64(6)) AS SELECTuuid,trace_id,@@ -1165,186 +1062,6 @@ FROM)GROUP BYteam_id, time_bucket, service_name, namespace, environment, severity_text;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_attributes TO posthog.metric_attributes2 (team_id Int32, time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- );-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_attributes3 TO posthog.metric_attributes3 (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- );-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_names3 TO posthog.metric_names3 (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), original_expiry_timestamp SimpleAggregateFunction(max, DateTime64(6))) AS SELECT- team_id,- metric_name,- toStartOfHour(timestamp) AS time_bucket,- toStartOfHour(input.original_expiry_timestamp) AS original_expiry_time_bucket,- maxSimpleState(input.original_expiry_timestamp) AS original_expiry_timestamp-FROM posthog.metrics2_input AS input-WHERE has_labels-GROUP BY- team_id, time_bucket, metric_name, original_expiry_time_bucket;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_series TO posthog.metric_series2 (team_id Int32, metric_name LowCardinality(String), series_fingerprint UInt64, metric_type LowCardinality(String), unit LowCardinality(String), aggregation_temporality LowCardinality(String), is_monotonic Bool, service_name LowCardinality(String), instrumentation_scope String, resource_attributes Map(LowCardinality(String), String), attributes Map(LowCardinality(String), String), last_seen DateTime64(6), original_expiry_timestamp DateTime64(6)) AS SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp-FROM posthog.metrics2_input-WHERE has_labels;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_series3 TO posthog.metric_series3 (team_id Int32, metric_name LowCardinality(String), series_fingerprint UInt64, metric_type LowCardinality(String), unit LowCardinality(String), aggregation_temporality LowCardinality(String), is_monotonic Bool, service_name LowCardinality(String), instrumentation_scope String, resource_attributes Map(LowCardinality(String), String), attributes Map(LowCardinality(String), String), last_seen DateTime64(6), original_expiry_timestamp DateTime64(6)) AS SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp-FROM posthog.metrics2_input-WHERE has_labels;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metrics TO posthog.metrics2 (team_id Int32, metric_name LowCardinality(String), series_fingerprint UInt64, resource_fingerprint UInt64, timestamp DateTime64(6), observed_timestamp DateTime64(6), original_expiry_timestamp DateTime64(6), service_name LowCardinality(String), metric_type LowCardinality(String), value Float64, count UInt64, histogram_bounds Array(Float64), histogram_counts Array(UInt64), trace_id String, span_id String, trace_flags Int32, has_labels Bool, unit LowCardinality(String), aggregation_temporality LowCardinality(String), is_monotonic Bool, instrumentation_scope String, _partition UInt32, _topic String, _offset UInt64) AS SELECT- team_id,- metric_name,- series_fingerprint,- resource_fingerprint,- timestamp,- observed_timestamp,- original_expiry_timestamp,- service_name,- metric_type,- value,- count,- histogram_bounds,- histogram_counts,- trace_id,- span_id,- trace_flags,- has_labels,- unit,- aggregation_temporality,- is_monotonic,- instrumentation_scope,- _partition,- _topic,- _offset-FROM posthog.metrics2_input;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_resource_attributes TO posthog.metric_attributes2 (team_id Int32, time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- );-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_resource_attributes3 TO posthog.metric_attributes3 (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- );CREATE MATERIALIZED VIEW posthog.ops_query_log_archive_mv TO posthog.writable_query_log_archive (hostname LowCardinality(String), user LowCardinality(String), query_id String, initial_query_id String, is_initial_query UInt8, type Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4), event_date Date, event_time DateTime, event_time_microseconds DateTime64(6), query_start_time DateTime, query_start_time_microseconds DateTime64(6), query_duration_ms UInt64, read_rows UInt64, read_bytes UInt64, written_rows UInt64, written_bytes UInt64, result_rows UInt64, result_bytes UInt64, memory_usage UInt64, peak_threads_usage UInt64, current_database LowCardinality(String), query String, formatted_query String, normalized_query_hash UInt64, query_kind LowCardinality(String), exception_code Int32, exception String, stack_trace String, team_id Int64, log_comment String, ProfileEvents Map(LowCardinality(String), UInt64)) AS SELECThostname,user,diff --git a/posthog/clickhouse/hcl/sql/prod-us/logs.sql b/posthog/clickhouse/hcl/sql/prod-us/logs.sqlindex 8dd308d1b61e..272c7730b40a 100644--- a/posthog/clickhouse/hcl/sql/prod-us/logs.sql+++ b/posthog/clickhouse/hcl/sql/prod-us/logs.sql@@ -1,30 +1,6 @@-- AUTO-GENERATED from the declarative HCL by ops/gen-sql.sh — do not edit.-- Full CREATE schema for the prod-us/logs node. Apply to a fresh ClickHouse to build it.-CREATE TABLE posthog.kafka_metrics_avro2 (- uuid String,- trace_id String,- span_id String,- trace_flags Nullable(Int32),- timestamp DateTime64(6),- observed_timestamp DateTime64(6),- service_name Nullable(String),- metric_name Nullable(String),- metric_type Nullable(String),- value Nullable(Float64),- count Nullable(Int64),- histogram_bounds Array(Float64),- histogram_counts Array(Int64),- unit Nullable(String),- aggregation_temporality Nullable(String),- is_monotonic Nullable(UInt8),- resource_attributes Map(String, String),- instrumentation_scope Nullable(String),- attributes Map(String, String),- series_fingerprint Nullable(Int64),- has_labels Nullable(UInt8),- retention_days Nullable(Int32)-) ENGINE = Kafka(warpstream_metrics) SETTINGS input_format_avro_allow_missing_fields = 1, kafka_format = 'Avro', kafka_group_name = 'clickhouse-metrics-avro2', 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 = 'clickhouse_metrics';CREATE TABLE posthog.kafka_trace_spans_avro (uuid String,trace_id String,@@ -497,35 +473,6 @@ CREATE TABLE posthog.metrics2 (GROUP BYteam_id, service_name, metric_name, metric_type, resource_fingerprint, series_fingerprint, hour)) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.metrics2', '{replica}-{shard}') ORDER BY (team_id, metric_name, time_bucket, series_fingerprint, timestamp) PARTITION BY toDate(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS index_granularity = 8192, index_granularity_bytes = 104857600, ttl_only_drop_parts = 1;-CREATE TABLE posthog.metrics2_input (- uuid String,- team_id Int32,- metric_name LowCardinality(String),- series_fingerprint UInt64,- resource_fingerprint UInt64,- timestamp DateTime64(6),- observed_timestamp DateTime64(6),- original_expiry_timestamp DateTime64(6),- service_name LowCardinality(String),- metric_type LowCardinality(String),- value Float64,- count UInt64,- histogram_bounds Array(Float64),- histogram_counts Array(UInt64),- trace_id String,- span_id String,- trace_flags Int32,- has_labels Bool,- unit LowCardinality(String),- aggregation_temporality LowCardinality(String),- is_monotonic Bool,- instrumentation_scope String,- resource_attributes Map(LowCardinality(String), String),- attributes Map(LowCardinality(String), String),- _partition UInt32,- _topic String,- _offset UInt64-) ENGINE = Null();CREATE TABLE posthog.metrics4_attributes (team_id Int32,metric_name LowCardinality(String),@@ -968,56 +915,6 @@ CREATE MATERIALIZED VIEW posthog.kafka_logs_avro_kafka_metrics_mv TO posthog.logFROM posthog.logs34GROUP BY_partition, _topic;-CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro2_mv TO posthog.metrics2_input (uuid String, team_id Int32, metric_name String, series_fingerprint UInt64, resource_fingerprint UInt64, timestamp DateTime64(6), observed_timestamp DateTime64(6), original_expiry_timestamp DateTime64(6), service_name String, metric_type String, value Float64, count UInt64, histogram_bounds Array(Float64), histogram_counts Array(UInt64), trace_id String, span_id String, trace_flags Int32, has_labels Bool, unit String, aggregation_temporality String, is_monotonic UInt8, instrumentation_scope String, resource_attributes Map(String, String), attributes Map(String, String), _partition UInt64, _topic LowCardinality(String), _offset UInt64) AS SELECT- uuid,- toInt32OrZero(_headers.value[indexOf(_headers.name, 'team_id')]) AS team_id,- ifNull(metric_name, '') AS metric_name,- reinterpretAsUInt64(assumeNotNull(series_fingerprint)) AS series_fingerprint,- cityHash64(mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes))) AS resource_fingerprint,- timestamp,- observed_timestamp,- timestamp- + toIntervalDay(- assumeNotNull(- if(- (retention_days IS NOT NULL) AND (retention_days > 0),- retention_days,- toInt32OrDefault(_headers.value[indexOf(_headers.name, 'retention-days')], toInt32(30))- )- )- ) AS original_expiry_timestamp,- ifNull(service_name, '') AS service_name,- ifNull(metric_type, '') AS metric_type,- 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,- toBool(ifNull(has_labels, 1)) AS has_labels,- ifNull(unit, '') AS unit,- ifNull(aggregation_temporality, '') AS aggregation_temporality,- ifNull(is_monotonic, 0) AS is_monotonic,- ifNull(instrumentation_scope, '') AS instrumentation_scope,- if(- toBool(ifNull(has_labels, 1)),- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), resource_attributes)),- CAST(map(), 'Map(String, String)')- ) AS resource_attributes,- if(- toBool(ifNull(has_labels, 1)),- mapSort(mapApply((k, v) -> (k, JSONExtractString(v)), attributes)),- CAST(map(), 'Map(String, String)')- ) AS attributes,- _partition,- _topic,- _offset-FROM posthog.kafka_metrics_avro2-WHERE kafka_metrics_avro2.series_fingerprint IS NOT NULL-SETTINGS- min_insert_block_size_rows = 0,- min_insert_block_size_bytes = 0;CREATE MATERIALIZED VIEW posthog.kafka_trace_spans_avro_mv TO posthog.trace_spans (uuid String, trace_id String, span_id String, parent_span_id String, trace_state String, name String, kind Int8, flags UInt32, timestamp DateTime64(6), end_time DateTime64(6), observed_timestamp DateTime64(6), service_name String, resource_attributes Map(LowCardinality(String), String), instrumentation_scope String, attributes_map_str Map(LowCardinality(String), String), dropped_attributes_count UInt32, events Array(String), dropped_events_count UInt32, links Array(String), dropped_links_count UInt32, status_code Int16, team_id Int32, original_expiry_timestamp DateTime64(6)) AS SELECTuuid,trace_id,@@ -1159,186 +1056,6 @@ FROM)GROUP BYteam_id, time_bucket, service_name, namespace, environment, severity_text;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_attributes TO posthog.metric_attributes2 (team_id Int32, time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- );-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_attributes3 TO posthog.metric_attributes3 (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- );-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_names3 TO posthog.metric_names3 (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), original_expiry_timestamp SimpleAggregateFunction(max, DateTime64(6))) AS SELECT- team_id,- metric_name,- toStartOfHour(timestamp) AS time_bucket,- toStartOfHour(input.original_expiry_timestamp) AS original_expiry_time_bucket,- maxSimpleState(input.original_expiry_timestamp) AS original_expiry_timestamp-FROM posthog.metrics2_input AS input-WHERE has_labels-GROUP BY- team_id, time_bucket, metric_name, original_expiry_time_bucket;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_series TO posthog.metric_series2 (team_id Int32, metric_name LowCardinality(String), series_fingerprint UInt64, metric_type LowCardinality(String), unit LowCardinality(String), aggregation_temporality LowCardinality(String), is_monotonic Bool, service_name LowCardinality(String), instrumentation_scope String, resource_attributes Map(LowCardinality(String), String), attributes Map(LowCardinality(String), String), last_seen DateTime64(6), original_expiry_timestamp DateTime64(6)) AS SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp-FROM posthog.metrics2_input-WHERE has_labels;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_series3 TO posthog.metric_series3 (team_id Int32, metric_name LowCardinality(String), series_fingerprint UInt64, metric_type LowCardinality(String), unit LowCardinality(String), aggregation_temporality LowCardinality(String), is_monotonic Bool, service_name LowCardinality(String), instrumentation_scope String, resource_attributes Map(LowCardinality(String), String), attributes Map(LowCardinality(String), String), last_seen DateTime64(6), original_expiry_timestamp DateTime64(6)) AS SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp-FROM posthog.metrics2_input-WHERE has_labels;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metrics TO posthog.metrics2 (team_id Int32, metric_name LowCardinality(String), series_fingerprint UInt64, resource_fingerprint UInt64, timestamp DateTime64(6), observed_timestamp DateTime64(6), original_expiry_timestamp DateTime64(6), service_name LowCardinality(String), metric_type LowCardinality(String), value Float64, count UInt64, histogram_bounds Array(Float64), histogram_counts Array(UInt64), trace_id String, span_id String, trace_flags Int32, has_labels Bool, unit LowCardinality(String), aggregation_temporality LowCardinality(String), is_monotonic Bool, instrumentation_scope String, _partition UInt32, _topic String, _offset UInt64) AS SELECT- team_id,- metric_name,- series_fingerprint,- resource_fingerprint,- timestamp,- observed_timestamp,- original_expiry_timestamp,- service_name,- metric_type,- value,- count,- histogram_bounds,- histogram_counts,- trace_id,- span_id,- trace_flags,- has_labels,- unit,- aggregation_temporality,- is_monotonic,- instrumentation_scope,- _partition,- _topic,- _offset-FROM posthog.metrics2_input;-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_resource_attributes TO posthog.metric_attributes2 (team_id Int32, time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- );-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_resource_attributes3 TO posthog.metric_attributes3 (team_id Int32, metric_name LowCardinality(String), time_bucket DateTime64(0), original_expiry_time_bucket DateTime64(0), service_name LowCardinality(String), attribute_key LowCardinality(String), attribute_value String, attribute_type LowCardinality(String), attribute_count SimpleAggregateFunction(sum, UInt64)) AS SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count-FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog.metrics2_input- WHERE has_labels- GROUP BY- team_id, metric_name, time_bucket, original_expiry_time_bucket, service_name, filtered_attributes- );CREATE MATERIALIZED VIEW posthog.ops_query_log_archive_mv TO posthog.writable_query_log_archive (hostname LowCardinality(String), user LowCardinality(String), query_id String, initial_query_id String, is_initial_query UInt8, type Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4), event_date Date, event_time DateTime, event_time_microseconds DateTime64(6), query_start_time DateTime, query_start_time_microseconds DateTime64(6), query_duration_ms UInt64, read_rows UInt64, read_bytes UInt64, written_rows UInt64, written_bytes UInt64, result_rows UInt64, result_bytes UInt64, memory_usage UInt64, peak_threads_usage UInt64, current_database LowCardinality(String), query String, formatted_query String, normalized_query_hash UInt64, query_kind LowCardinality(String), exception_code Int32, exception String, stack_trace String, team_id Int64, log_comment String, ProfileEvents Map(LowCardinality(String), UInt64)) AS SELECThostname,user,diff --git a/posthog/clickhouse/migrations/0347_drop_metrics2_ingest.py b/posthog/clickhouse/migrations/0347_drop_metrics2_ingest.pynew file mode 100644index 000000000000..8b43777efe01--- /dev/null+++ b/posthog/clickhouse/migrations/0347_drop_metrics2_ingest.py@@ -0,0 +1,20 @@+from posthog.clickhouse.client.connection import NodeRole+from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions++# metrics4 owns metrics ingest now and HogQL reads only metrics4. Stop the metrics2 chain:+# drop the Kafka view first so the consumer stops, then the Kafka table, the views out of+# metrics2_input, and metrics2_input. The metrics2 and metrics3 tables stay until their TTL+# clears the rows. None of these objects is replicated, so no SYNC.+operations = [+ run_sql_with_exceptions("DROP TABLE IF EXISTS kafka_metrics_avro2_mv", node_roles=[NodeRole.LOGS]),+ run_sql_with_exceptions("DROP TABLE IF EXISTS kafka_metrics_avro2", node_roles=[NodeRole.LOGS]),+ run_sql_with_exceptions("DROP TABLE IF EXISTS metrics2_input_to_metrics", node_roles=[NodeRole.LOGS]),+ run_sql_with_exceptions("DROP TABLE IF EXISTS metrics2_input_to_metric_series", node_roles=[NodeRole.LOGS]),+ run_sql_with_exceptions("DROP TABLE IF EXISTS metrics2_input_to_metric_attributes", node_roles=[NodeRole.LOGS]),+ run_sql_with_exceptions("DROP TABLE IF EXISTS metrics2_input_to_resource_attributes", node_roles=[NodeRole.LOGS]),+ run_sql_with_exceptions("DROP TABLE IF EXISTS metrics2_input_to_metric_series3", node_roles=[NodeRole.LOGS]),+ run_sql_with_exceptions("DROP TABLE IF EXISTS metrics2_input_to_metric_attributes3", node_roles=[NodeRole.LOGS]),+ run_sql_with_exceptions("DROP TABLE IF EXISTS metrics2_input_to_resource_attributes3", node_roles=[NodeRole.LOGS]),+ run_sql_with_exceptions("DROP TABLE IF EXISTS metrics2_input_to_metric_names3", node_roles=[NodeRole.LOGS]),+ run_sql_with_exceptions("DROP TABLE IF EXISTS metrics2_input", node_roles=[NodeRole.LOGS]),+]diff --git a/posthog/clickhouse/migrations/max_migration.txt b/posthog/clickhouse/migrations/max_migration.txtindex f280afd8f1f6..ce57d41a6de9 100644--- a/posthog/clickhouse/migrations/max_migration.txt+++ b/posthog/clickhouse/migrations/max_migration.txt@@ -1 +1 @@-0346_platform_alert_events_source_kind+0347_drop_metrics2_ingestdiff --git a/posthog/clickhouse/schema.py b/posthog/clickhouse/schema.pyindex 9a68fcc74b75..9693115945dc 100644--- a/posthog/clickhouse/schema.py+++ b/posthog/clickhouse/schema.py@@ -59,15 +59,6 @@ from posthog.clickhouse.metrics import (METRIC_SERIES_TABLE_SQL,METRICS1_TABLE_SQL,METRICS2_DISTRIBUTED_TABLE_SQL,- METRICS2_INPUT_TABLE_SQL,- METRICS2_INPUT_TO_METRIC_ATTRIBUTES3_MV,- METRICS2_INPUT_TO_METRIC_ATTRIBUTES_MV,- METRICS2_INPUT_TO_METRIC_NAMES3_MV,- METRICS2_INPUT_TO_METRIC_SERIES3_MV,- METRICS2_INPUT_TO_METRIC_SERIES_MV,- METRICS2_INPUT_TO_METRICS_MV,- METRICS2_INPUT_TO_RESOURCE_ATTRIBUTES3_MV,- METRICS2_INPUT_TO_RESOURCE_ATTRIBUTES_MV,METRICS2_TABLE_SQL,METRICS4_ATTRIBUTES_TABLE_SQL,METRICS4_INPUT_TABLE_SQL,@@ -505,7 +496,6 @@ CREATE_MERGETREE_TABLE_QUERIES = (METRIC_SERIES_TABLE_SQL,METRIC_SAMPLES_TABLE_SQL,METRIC_ATTRIBUTES_TABLE_SQL,- METRICS2_INPUT_TABLE_SQL,METRICS4_INPUT_TABLE_SQL,METRICS2_TABLE_SQL,METRIC_SERIES2_TABLE_SQL,@@ -706,14 +696,6 @@ CREATE_MV_TABLE_QUERIES = (LOGS34_TO_LOG_ATTRIBUTES3_MV,LOGS34_TO_RESOURCE_ATTRIBUTES3_MV,LOGS34_TO_VOLUME_BUCKETS_MV,- METRICS2_INPUT_TO_METRICS_MV,- METRICS2_INPUT_TO_METRIC_SERIES_MV,- METRICS2_INPUT_TO_METRIC_SERIES3_MV,- METRICS2_INPUT_TO_METRIC_ATTRIBUTES_MV,- METRICS2_INPUT_TO_METRIC_ATTRIBUTES3_MV,- METRICS2_INPUT_TO_METRIC_NAMES3_MV,- METRICS2_INPUT_TO_RESOURCE_ATTRIBUTES_MV,- METRICS2_INPUT_TO_RESOURCE_ATTRIBUTES3_MV,METRICS4_INPUT_TO_METRICS4_SAMPLES_MV,METRICS4_INPUT_TO_METRICS4_SERIES_MV,METRICS4_INPUT_TO_METRICS4_NAMES_MV,diff --git a/posthog/clickhouse/test/__snapshots__/test_schema.ambr b/posthog/clickhouse/test/__snapshots__/test_schema.ambrindex 5895cc530256..6542df5da073 100644--- a/posthog/clickhouse/test/__snapshots__/test_schema.ambr+++ b/posthog/clickhouse/test/__snapshots__/test_schema.ambr@@ -4761,345 +4761,6 @@'''# ----# name: test_create_table_query[metrics2_input]- '''-- CREATE TABLE IF NOT EXISTS posthog_test.metrics2_input- (- `uuid` String,- `team_id` Int32,- `metric_name` LowCardinality(String),- `series_fingerprint` UInt64,- `resource_fingerprint` UInt64,- `timestamp` DateTime64(6),- `observed_timestamp` DateTime64(6),- `original_expiry_timestamp` DateTime64(6),- `service_name` LowCardinality(String),- `metric_type` LowCardinality(String),- `value` Float64,- `count` UInt64,- `histogram_bounds` Array(Float64),- `histogram_counts` Array(UInt64),- `trace_id` String,- `span_id` String,- `trace_flags` Int32,- `has_labels` Bool,- `unit` LowCardinality(String),- `aggregation_temporality` LowCardinality(String),- `is_monotonic` Bool,- `instrumentation_scope` String,- `resource_attributes` Map(LowCardinality(String), String),- `attributes` Map(LowCardinality(String), String),- `_partition` UInt32,- `_topic` String,- `_offset` UInt64- )- ENGINE = Null-- '''-# ----# name: test_create_table_query[metrics2_input_to_metric_attributes3]- '''-- CREATE MATERIALIZED VIEW IF NOT EXISTS posthog_test.metrics2_input_to_metric_attributes3 TO posthog_test.metric_attributes3- (- `team_id` Int32,- `metric_name` LowCardinality(String),- `time_bucket` DateTime64(0),- `original_expiry_time_bucket` DateTime64(0),- `service_name` LowCardinality(String),- `attribute_key` LowCardinality(String),- `attribute_value` String,- `attribute_type` LowCardinality(String),- `attribute_count` SimpleAggregateFunction(sum, UInt64)- )- AS SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count- FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog_test.metrics2_input- WHERE has_labels- GROUP BY- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- filtered_attributes- )-- '''-# ----# name: test_create_table_query[metrics2_input_to_metric_attributes]- '''-- CREATE MATERIALIZED VIEW IF NOT EXISTS posthog_test.metrics2_input_to_metric_attributes TO posthog_test.metric_attributes2- (- `team_id` Int32,- `time_bucket` DateTime64(0),- `original_expiry_time_bucket` DateTime64(0),- `service_name` LowCardinality(String),- `attribute_key` LowCardinality(String),- `attribute_value` String,- `attribute_type` LowCardinality(String),- `attribute_count` SimpleAggregateFunction(sum, UInt64)- )- AS SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count- FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- mapFilter((k, v) -> ((length(k) < 256) AND (length(v) < 256)), attributes) AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'metric' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog_test.metrics2_input- WHERE has_labels- GROUP BY- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- filtered_attributes- )-- '''-# ----# name: test_create_table_query[metrics2_input_to_metric_names3]- '''-- CREATE MATERIALIZED VIEW IF NOT EXISTS posthog_test.metrics2_input_to_metric_names3 TO posthog_test.metric_names3- (- `team_id` Int32,- `metric_name` LowCardinality(String),- `time_bucket` DateTime64(0),- `original_expiry_time_bucket` DateTime64(0),- `original_expiry_timestamp` SimpleAggregateFunction(max, DateTime64(6))- )- AS SELECT- team_id,- metric_name,- toStartOfHour(timestamp) AS time_bucket,- toStartOfHour(input.original_expiry_timestamp) AS original_expiry_time_bucket,- maxSimpleState(input.original_expiry_timestamp) AS original_expiry_timestamp- FROM posthog_test.metrics2_input AS input- WHERE has_labels- GROUP BY team_id, time_bucket, metric_name, original_expiry_time_bucket-- '''-# ----# name: test_create_table_query[metrics2_input_to_metric_series3]- '''-- CREATE MATERIALIZED VIEW IF NOT EXISTS posthog_test.metrics2_input_to_metric_series3 TO posthog_test.metric_series3- AS SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp- FROM posthog_test.metrics2_input- WHERE has_labels-- '''-# ----# name: test_create_table_query[metrics2_input_to_metric_series]- '''-- CREATE MATERIALIZED VIEW IF NOT EXISTS posthog_test.metrics2_input_to_metric_series TO posthog_test.metric_series2- AS SELECT- team_id,- metric_name,- series_fingerprint,- metric_type,- unit,- aggregation_temporality,- is_monotonic,- service_name,- instrumentation_scope,- resource_attributes,- attributes,- timestamp AS last_seen,- original_expiry_timestamp- FROM posthog_test.metrics2_input- WHERE has_labels-- '''-# ----# name: test_create_table_query[metrics2_input_to_metrics]- '''-- CREATE MATERIALIZED VIEW IF NOT EXISTS posthog_test.metrics2_input_to_metrics TO posthog_test.metrics2- AS SELECT- team_id,- metric_name,- series_fingerprint,- resource_fingerprint,- timestamp,- observed_timestamp,- original_expiry_timestamp,- service_name,- metric_type,- value,- count,- histogram_bounds,- histogram_counts,- trace_id,- span_id,- trace_flags,- has_labels,- unit,- aggregation_temporality,- is_monotonic,- instrumentation_scope,- _partition,- _topic,- _offset- FROM posthog_test.metrics2_input-- '''-# ----# name: test_create_table_query[metrics2_input_to_resource_attributes3]- '''-- CREATE MATERIALIZED VIEW IF NOT EXISTS posthog_test.metrics2_input_to_resource_attributes3 TO posthog_test.metric_attributes3- (- `team_id` Int32,- `metric_name` LowCardinality(String),- `time_bucket` DateTime64(0),- `original_expiry_time_bucket` DateTime64(0),- `service_name` LowCardinality(String),- `attribute_key` LowCardinality(String),- `attribute_value` String,- `attribute_type` LowCardinality(String),- `attribute_count` SimpleAggregateFunction(sum, UInt64)- )- AS SELECT- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count- FROM- (- SELECT- team_id AS team_id,- metric_name AS metric_name,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog_test.metrics2_input- WHERE has_labels- GROUP BY- team_id,- metric_name,- time_bucket,- original_expiry_time_bucket,- service_name,- filtered_attributes- )-- '''-# ----# name: test_create_table_query[metrics2_input_to_resource_attributes]- '''-- CREATE MATERIALIZED VIEW IF NOT EXISTS posthog_test.metrics2_input_to_resource_attributes TO posthog_test.metric_attributes2- (- `team_id` Int32,- `time_bucket` DateTime64(0),- `original_expiry_time_bucket` DateTime64(0),- `service_name` LowCardinality(String),- `attribute_key` LowCardinality(String),- `attribute_value` String,- `attribute_type` LowCardinality(String),- `attribute_count` SimpleAggregateFunction(sum, UInt64)- )- AS SELECT- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- attribute_key,- attribute_value,- attribute_type,- attribute_count- FROM- (- SELECT- team_id AS team_id,- toStartOfInterval(timestamp, toIntervalHour(1)) AS time_bucket,- toStartOfInterval(original_expiry_timestamp, toIntervalHour(1)) AS original_expiry_time_bucket,- service_name AS service_name,- resource_attributes AS filtered_attributes,- arrayJoin(filtered_attributes) AS attribute,- 'resource' AS attribute_type,- attribute.1 AS attribute_key,- attribute.2 AS attribute_value,- sumSimpleState(1) AS attribute_count- FROM posthog_test.metrics2_input- WHERE has_labels- GROUP BY- team_id,- time_bucket,- original_expiry_time_bucket,- service_name,- filtered_attributes- )-- '''-# ---# name: test_create_table_query[metrics4_attributes]'''@@ -12697,43 +12358,6 @@'''# ----# name: test_create_table_query_replicated_and_storage[metrics2_input]- '''-- CREATE TABLE IF NOT EXISTS posthog_test.metrics2_input- (- `uuid` String,- `team_id` Int32,- `metric_name` LowCardinality(String),- `series_fingerprint` UInt64,- `resource_fingerprint` UInt64,- `timestamp` DateTime64(6),- `observed_timestamp` DateTime64(6),- `original_expiry_timestamp` DateTime64(6),- `service_name` LowCardinality(String),- `metric_type` LowCardinality(String),- `value` Float64,- `count` UInt64,- `histogram_bounds` Array(Float64),- `histogram_counts` Array(UInt64),- `trace_id` String,- `span_id` String,- `trace_flags` Int32,- `has_labels` Bool,- `unit` LowCardinality(String),- `aggregation_temporality` LowCardinality(String),- `is_monotonic` Bool,- `instrumentation_scope` String,- `resource_attributes` Map(LowCardinality(String), String),- `attributes` Map(LowCardinality(String), String),- `_partition` UInt32,- `_topic` String,- `_offset` UInt64- )- ENGINE = Null-- '''-# ---# name: test_create_table_query_replicated_and_storage[metrics4_attributes]'''diff --git a/products/metrics/backend/tests/_seeder.py b/products/metrics/backend/tests/_seeder.pyindex bed3cd4c4cfa..c960d9b0f1de 100644--- a/products/metrics/backend/tests/_seeder.py+++ b/products/metrics/backend/tests/_seeder.py@@ -1,12 +1,10 @@-"""Test-only metric row seeder for the metrics2 and metrics4 chains.+"""Test-only metric row seeder for the metrics4 chain.-Inserts rows into `metrics2_input` and `metrics4_input` via `sync_execute` rather than driving the+Inserts rows into `metrics4_input` via `sync_execute` rather than driving theOTLP pipe, so tests don't depend on capture-logs + metrics-ingestion-consumer-running. `metrics2_input` is the Null-engine table the Kafka MV writes to, so one-insert fans out through the same MVs production uses: `metrics2` (data points),-`metric_series2` (labels, one row per series) and `metric_attributes2` (the-attribute rollups). The `metrics4_input` insert fills the metrics4 tables that-HogQL reads.+running. `metrics4_input` is the Null-engine table the Kafka MV writes to, so one+insert fans out through the same MVs production uses into the metrics4 tables+that HogQL reads.The shape mirrors what `rust/capture-logs/src/metric_record.rs` emits — everyquery-runner test (filters, group-by, rate, histogram_quantile) leans on this@@ -24,7 +22,7 @@ from typing import Anyfrom posthog.clickhouse.client import sync_execute-# `metrics2` and `metric_series2` hardcode `TTL original_expiry_timestamp`+# The metrics4 tables hardcode their TTL on the original expiry columns# instead of going through `ttl_period()`, so the seeder has to keep its rows# alive itself. A far-future expiry pins that independent of the wall clock._EXPIRY = dt.datetime(2200, 1, 1, tzinfo=dt.UTC)@@ -61,9 +59,6 @@ def truncate_metrics_tables() -> None:"""Clear every table the seeder's inserts fan out into, so leftovers can'tleak between tests."""for table in (- "metrics2",- "metric_series2",- "metric_attributes2","metrics4_samples","metrics4_series","metrics4_names",@@ -94,9 +89,9 @@ def seed_metric(span_id: str = "",count: int = 1,) -> None:- """Insert one `metrics2_input` row per `(timestamp, value)` point; the- ingest MVs write the `metrics2` rows, the `metric_series2` row and the- `metric_attributes2` rollups from it.+ """Insert one `metrics4_input` row per `(timestamp, value)` point; the+ ingest MVs write the metrics4 samples, series, names and attribute rollups+ from it.Every point in one call is a sample of the *same* series, since the seriesidentity (`service_name`, `metric_type`, both attribute maps) is fixed per@@ -151,9 +146,7 @@ def seed_metric()payload = "\n".join(json.dumps(row) for row in rows)- # HogQL reads the metrics4 tables. The metrics2 chain stays seeded for the readers that still use it.- for input_table in ("metrics2_input", "metrics4_input"):- sync_execute(f"INSERT INTO {input_table} FORMAT JSONEachRow {payload}")+ sync_execute(f"INSERT INTO metrics4_input FORMAT JSONEachRow {payload}")def seed_metric_event(diff --git a/products/metrics/backend/tests/test_metrics_histogram_query_runner.py b/products/metrics/backend/tests/test_metrics_histogram_query_runner.pyindex 9e6aba95b940..e68c8edd325a 100644--- a/products/metrics/backend/tests/test_metrics_histogram_query_runner.py+++ b/products/metrics/backend/tests/test_metrics_histogram_query_runner.py@@ -121,7 +121,7 @@ class TestMetricsHistogramQueryRunner(ClickhouseTestMixin, APIBaseTest):self.assertEqual(len(response.times), 3)def test_weekly_buckets_keep_their_counts(self):- monday = dt.datetime(2026, 9, 7, 0, 0, 0, tzinfo=dt.UTC)+ monday = dt.datetime(2026, 9, 14, 0, 0, 0, tzinfo=dt.UTC)self._seed_histogram([(monday + dt.timedelta(hours=3), [4, 4, 4, 0])])response = self._run(