Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

revert: "feat(logs): track logs_ingestion partitions in logs_kafka_metrics" (#110102)

Frank Hamand1d6fd47b9fe8
diff --git a/posthog/clickhouse/hcl/golden/dev/apm.hcl b/posthog/clickhouse/hcl/golden/dev/apm.hcl
index a871fedb150b..88eb157eb9c3 100644
--- a/posthog/clickhouse/hcl/golden/dev/apm.hcl
+++ b/posthog/clickhouse/hcl/golden/dev/apm.hcl
@@ -434,12 +434,6 @@ database "posthog" {
column "pattern_version" {
type = "UInt8"
}
- column "_source_topic" {
- type = "String"
- }
- column "_source_partition" {
- type = "UInt32"
- }
engine "distributed" {
cluster_name = "logs"
remote_database = "posthog"
@@ -1114,9 +1108,7 @@ SELECT
toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) / _record_count AS _bytes_uncompressed,
toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) / _record_count AS _bytes_compressed,
ifNull(pattern, '') AS pattern,
- toUInt8(ifNull(pattern_version, 0)) AS pattern_version,
- _headers.value[indexOf(_headers.name, 'source_topic')] AS _source_topic,
- toUInt32OrZero(_headers.value[indexOf(_headers.name, 'source_partition')]) AS _source_partition
+ toUInt8(ifNull(pattern_version, 0)) AS pattern_version
FROM posthog.kafka_logs_avro
SQL
@@ -1192,12 +1184,6 @@ SQL
column "pattern_version" {
type = "UInt8"
}
- column "_source_topic" {
- type = "String"
- }
- column "_source_partition" {
- type = "UInt32"
- }
}
materialized_view "kafka_metrics_avro4_mv" {
diff --git a/posthog/clickhouse/hcl/golden/dev/logs.hcl b/posthog/clickhouse/hcl/golden/dev/logs.hcl
index 002eb416fece..bb1a5a9e75d2 100644
--- a/posthog/clickhouse/hcl/golden/dev/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/dev/logs.hcl
@@ -382,12 +382,6 @@ database "posthog" {
column "pattern_version" {
type = "UInt8"
}
- column "_source_topic" {
- type = "String"
- }
- column "_source_partition" {
- type = "UInt32"
- }
index "idx_severity_text_set" {
expr = "severity_text"
type = "set(10)"
@@ -616,12 +610,6 @@ SQL
column "pattern_version" {
type = "UInt8"
}
- column "_source_topic" {
- type = "String"
- }
- column "_source_partition" {
- type = "UInt32"
- }
engine "distributed" {
cluster_name = "logs"
remote_database = "posthog"
@@ -3442,27 +3430,16 @@ SQL
to_table = "posthog.logs_kafka_metrics"
query = <<SQL
SELECT
- kafka_partition AS _partition,
- kafka_topic AS _topic,
- maxSimpleState(kafka_offset) AS max_offset,
+ _partition,
+ _topic,
+ maxSimpleState(_offset) AS max_offset,
maxSimpleState(observed_timestamp) AS max_observed_timestamp,
maxSimpleState(timestamp) AS max_timestamp,
maxSimpleState(now()) AS max_created_at,
maxSimpleState(now() - observed_timestamp) AS max_lag
-FROM
- (
- SELECT
- kafka_source.1 AS kafka_topic,
- kafka_source.2 AS kafka_partition,
- kafka_source.3 AS kafka_offset,
- observed_timestamp,
- timestamp
- FROM
- posthog.logs34 ARRAY JOIN [(_topic, _partition, _offset), (_source_topic, _source_partition, 0)] AS kafka_source
- WHERE kafka_topic != ''
- )
+FROM posthog.logs34
GROUP BY
- kafka_partition, kafka_topic
+ _partition, _topic
SQL
column "_partition" {
diff --git a/posthog/clickhouse/hcl/golden/local-multi/ingestion_events.hcl b/posthog/clickhouse/hcl/golden/local-multi/ingestion_events.hcl
index 3f7e463dde47..fead3407d47a 100644
--- a/posthog/clickhouse/hcl/golden/local-multi/ingestion_events.hcl
+++ b/posthog/clickhouse/hcl/golden/local-multi/ingestion_events.hcl
@@ -783,12 +783,6 @@ database "posthog" {
column "pattern_version" {
type = "UInt8"
}
- column "_source_topic" {
- type = "String"
- }
- column "_source_partition" {
- type = "UInt32"
- }
engine "distributed" {
cluster_name = "logs"
remote_database = "posthog"
@@ -990,9 +984,7 @@ SELECT
toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) / _record_count AS _bytes_uncompressed,
toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) / _record_count AS _bytes_compressed,
ifNull(pattern, '') AS pattern,
- toUInt8(ifNull(pattern_version, 0)) AS pattern_version,
- _headers.value[indexOf(_headers.name, 'source_topic')] AS _source_topic,
- toUInt32OrZero(_headers.value[indexOf(_headers.name, 'source_partition')]) AS _source_partition
+ toUInt8(ifNull(pattern_version, 0)) AS pattern_version
FROM posthog.kafka_logs_avro
SQL
@@ -1068,12 +1060,6 @@ SQL
column "pattern_version" {
type = "UInt8"
}
- column "_source_topic" {
- type = "String"
- }
- column "_source_partition" {
- type = "UInt32"
- }
}
}
diff --git a/posthog/clickhouse/hcl/golden/local-multi/logs.hcl b/posthog/clickhouse/hcl/golden/local-multi/logs.hcl
index 217258a20a35..8f6a67baf71a 100644
--- a/posthog/clickhouse/hcl/golden/local-multi/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/local-multi/logs.hcl
@@ -879,12 +879,6 @@ SQL
column "pattern_version" {
type = "UInt8"
}
- column "_source_topic" {
- type = "String"
- }
- column "_source_partition" {
- type = "UInt32"
- }
index "idx_severity_text_set" {
expr = "severity_text"
type = "set(10)"
@@ -1113,12 +1107,6 @@ SQL
column "pattern_version" {
type = "UInt8"
}
- column "_source_topic" {
- type = "String"
- }
- column "_source_partition" {
- type = "UInt32"
- }
engine "distributed" {
cluster_name = "posthog_single_shard"
remote_database = "posthog"
@@ -3857,27 +3845,16 @@ SQL
to_table = "posthog.logs_kafka_metrics"
query = <<SQL
SELECT
- kafka_partition AS _partition,
- kafka_topic AS _topic,
- maxSimpleState(kafka_offset) AS max_offset,
+ _partition,
+ _topic,
+ maxSimpleState(_offset) AS max_offset,
maxSimpleState(observed_timestamp) AS max_observed_timestamp,
maxSimpleState(timestamp) AS max_timestamp,
maxSimpleState(now()) AS max_created_at,
maxSimpleState(now() - observed_timestamp) AS max_lag
-FROM
- (
- SELECT
- kafka_source.1 AS kafka_topic,
- kafka_source.2 AS kafka_partition,
- kafka_source.3 AS kafka_offset,
- observed_timestamp,
- timestamp
- FROM
- posthog.logs34 ARRAY JOIN [(_topic, _partition, _offset), (_source_topic, _source_partition, 0)] AS kafka_source
- WHERE kafka_topic != ''
- )
+FROM posthog.logs34
GROUP BY
- kafka_partition, kafka_topic
+ _partition, _topic
SQL
column "_partition" {
diff --git a/posthog/clickhouse/hcl/golden/local-single/all.hcl b/posthog/clickhouse/hcl/golden/local-single/all.hcl
index 6ab4edcc22c3..3af04d1ac906 100644
--- a/posthog/clickhouse/hcl/golden/local-single/all.hcl
+++ b/posthog/clickhouse/hcl/golden/local-single/all.hcl
@@ -5569,12 +5569,6 @@ SQL
column "pattern_version" {
type = "UInt8"
}
- column "_source_topic" {
- type = "String"
- }
- column "_source_partition" {
- type = "UInt32"
- }
index "idx_severity_text_set" {
expr = "severity_text"
type = "set(10)"
@@ -5803,12 +5797,6 @@ SQL
column "pattern_version" {
type = "UInt8"
}
- column "_source_topic" {
- type = "String"
- }
- column "_source_partition" {
- type = "UInt32"
- }
engine "distributed" {
cluster_name = "posthog_single_shard"
remote_database = "posthog"
@@ -17697,12 +17685,6 @@ SQL
column "pattern_version" {
type = "UInt8"
}
- column "_source_topic" {
- type = "String"
- }
- column "_source_partition" {
- type = "UInt32"
- }
engine "distributed" {
cluster_name = "posthog_single_shard"
remote_database = "posthog"
@@ -21108,9 +21090,7 @@ SELECT
toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) / _record_count AS _bytes_uncompressed,
toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) / _record_count AS _bytes_compressed,
ifNull(pattern, '') AS pattern,
- toUInt8(ifNull(pattern_version, 0)) AS pattern_version,
- _headers.value[indexOf(_headers.name, 'source_topic')] AS _source_topic,
- toUInt32OrZero(_headers.value[indexOf(_headers.name, 'source_partition')]) AS _source_partition
+ toUInt8(ifNull(pattern_version, 0)) AS pattern_version
FROM posthog.kafka_logs_avro
SQL
@@ -21186,12 +21166,6 @@ SQL
column "pattern_version" {
type = "UInt8"
}
- column "_source_topic" {
- type = "String"
- }
- column "_source_partition" {
- type = "UInt32"
- }
}
materialized_view "kafka_logs_avro_billing_metrics_mv" {
@@ -21242,27 +21216,16 @@ SQL
to_table = "posthog.logs_kafka_metrics"
query = <<SQL
SELECT
- kafka_partition AS _partition,
- kafka_topic AS _topic,
- maxSimpleState(kafka_offset) AS max_offset,
+ _partition,
+ _topic,
+ maxSimpleState(_offset) AS max_offset,
maxSimpleState(observed_timestamp) AS max_observed_timestamp,
maxSimpleState(timestamp) AS max_timestamp,
maxSimpleState(now()) AS max_created_at,
maxSimpleState(now() - observed_timestamp) AS max_lag
-FROM
- (
- SELECT
- kafka_source.1 AS kafka_topic,
- kafka_source.2 AS kafka_partition,
- kafka_source.3 AS kafka_offset,
- observed_timestamp,
- timestamp
- FROM
- posthog.logs34 ARRAY JOIN [(_topic, _partition, _offset), (_source_topic, _source_partition, 0)] AS kafka_source
- WHERE kafka_topic != ''
- )
+FROM posthog.logs34
GROUP BY
- kafka_partition, kafka_topic
+ _partition, _topic
SQL
column "_partition" {
diff --git a/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl b/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl
index 4bc8751ea2cd..a4ceec626c4c 100644
--- a/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl
@@ -464,12 +464,6 @@ database "posthog" {
column "pattern_version" {
type = "UInt8"
}
- column "_source_topic" {
- type = "String"
- }
- column "_source_partition" {
- type = "UInt32"
- }
index "idx_severity_text_set" {
expr = "severity_text"
type = "set(10)"
@@ -698,12 +692,6 @@ SQL
column "pattern_version" {
type = "UInt8"
}
- column "_source_topic" {
- type = "String"
- }
- column "_source_partition" {
- type = "UInt32"
- }
engine "distributed" {
cluster_name = "logs"
remote_database = "posthog"
@@ -3560,27 +3548,16 @@ SQL
to_table = "posthog.logs_kafka_metrics"
query = <<SQL
SELECT
- kafka_partition AS _partition,
- kafka_topic AS _topic,
- maxSimpleState(kafka_offset) AS max_offset,
+ _partition,
+ _topic,
+ maxSimpleState(_offset) AS max_offset,
maxSimpleState(observed_timestamp) AS max_observed_timestamp,
maxSimpleState(timestamp) AS max_timestamp,
maxSimpleState(now()) AS max_created_at,
maxSimpleState(now() - observed_timestamp) AS max_lag
-FROM
- (
- SELECT
- kafka_source.1 AS kafka_topic,
- kafka_source.2 AS kafka_partition,
- kafka_source.3 AS kafka_offset,
- observed_timestamp,
- timestamp
- FROM
- posthog.logs34 ARRAY JOIN [(_topic, _partition, _offset), (_source_topic, _source_partition, 0)] AS kafka_source
- WHERE kafka_topic != ''
- )
+FROM posthog.logs34
GROUP BY
- kafka_partition, kafka_topic
+ _partition, _topic
SQL
column "_partition" {
diff --git a/posthog/clickhouse/hcl/golden/prod-us/logs.hcl b/posthog/clickhouse/hcl/golden/prod-us/logs.hcl
index 857e3413d2da..ae8b17962239 100644
--- a/posthog/clickhouse/hcl/golden/prod-us/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/prod-us/logs.hcl
@@ -464,12 +464,6 @@ database "posthog" {
column "pattern_version" {
type = "UInt8"
}
- column "_source_topic" {
- type = "String"
- }
- column "_source_partition" {
- type = "UInt32"
- }
index "idx_severity_text_set" {
expr = "severity_text"
type = "set(10)"
@@ -698,12 +692,6 @@ SQL
column "pattern_version" {
type = "UInt8"
}
- column "_source_topic" {
- type = "String"
- }
- column "_source_partition" {
- type = "UInt32"
- }
engine "distributed" {
cluster_name = "logs"
remote_database = "posthog"
@@ -3542,27 +3530,16 @@ SQL
to_table = "posthog.logs_kafka_metrics"
query = <<SQL
SELECT
- kafka_partition AS _partition,
- kafka_topic AS _topic,
- maxSimpleState(kafka_offset) AS max_offset,
+ _partition,
+ _topic,
+ maxSimpleState(_offset) AS max_offset,
maxSimpleState(observed_timestamp) AS max_observed_timestamp,
maxSimpleState(timestamp) AS max_timestamp,
maxSimpleState(now()) AS max_created_at,
maxSimpleState(now() - observed_timestamp) AS max_lag
-FROM
- (
- SELECT
- kafka_source.1 AS kafka_topic,
- kafka_source.2 AS kafka_partition,
- kafka_source.3 AS kafka_offset,
- observed_timestamp,
- timestamp
- FROM
- posthog.logs34 ARRAY JOIN [(_topic, _partition, _offset), (_source_topic, _source_partition, 0)] AS kafka_source
- WHERE kafka_topic != ''
- )
+FROM posthog.logs34
GROUP BY
- kafka_partition, kafka_topic
+ _partition, _topic
SQL
column "_partition" {
diff --git a/posthog/clickhouse/hcl/roles/coshared/logs_avro_ingest/sql/kafka_logs34_avro_mv.sql b/posthog/clickhouse/hcl/roles/coshared/logs_avro_ingest/sql/kafka_logs34_avro_mv.sql
index 94b2ee52baf7..267ac14d472c 100644
--- a/posthog/clickhouse/hcl/roles/coshared/logs_avro_ingest/sql/kafka_logs34_avro_mv.sql
+++ b/posthog/clickhouse/hcl/roles/coshared/logs_avro_ingest/sql/kafka_logs34_avro_mv.sql
@@ -29,7 +29,5 @@ SELECT
toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) / _record_count AS _bytes_uncompressed,
toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) / _record_count AS _bytes_compressed,
ifNull(pattern, '') AS pattern,
- toUInt8(ifNull(pattern_version, 0)) AS pattern_version,
- _headers.value[indexOf(_headers.name, 'source_topic')] AS _source_topic,
- toUInt32OrZero(_headers.value[indexOf(_headers.name, 'source_partition')]) AS _source_partition
+ toUInt8(ifNull(pattern_version, 0)) AS pattern_version
FROM posthog.kafka_logs_avro
diff --git a/posthog/clickhouse/hcl/roles/coshared/logs_avro_ingest/tables.hcl b/posthog/clickhouse/hcl/roles/coshared/logs_avro_ingest/tables.hcl
index 29f5f64d5c90..2eb8d14faf71 100644
--- a/posthog/clickhouse/hcl/roles/coshared/logs_avro_ingest/tables.hcl
+++ b/posthog/clickhouse/hcl/roles/coshared/logs_avro_ingest/tables.hcl
@@ -144,12 +144,6 @@ database "posthog" {
column "pattern_version" {
type = "UInt8"
}
- column "_source_topic" {
- type = "String"
- }
- column "_source_partition" {
- type = "UInt32"
- }
}
table "writable_logs34" {
@@ -262,12 +256,6 @@ database "posthog" {
column "pattern_version" {
type = "UInt8"
}
- column "_source_topic" {
- type = "String"
- }
- column "_source_partition" {
- type = "UInt32"
- }
settings = {
background_insert_batch = "1"
}
diff --git a/posthog/clickhouse/hcl/roles/logs/base/sql/kafka_logs_avro_kafka_metrics_mv.sql b/posthog/clickhouse/hcl/roles/logs/base/sql/kafka_logs_avro_kafka_metrics_mv.sql
index 55eeab4cb42c..6f4c3cdd0ba4 100644
--- a/posthog/clickhouse/hcl/roles/logs/base/sql/kafka_logs_avro_kafka_metrics_mv.sql
+++ b/posthog/clickhouse/hcl/roles/logs/base/sql/kafka_logs_avro_kafka_metrics_mv.sql
@@ -1,22 +1,11 @@
SELECT
- kafka_partition AS _partition,
- kafka_topic AS _topic,
- maxSimpleState(kafka_offset) AS max_offset,
+ _partition,
+ _topic,
+ maxSimpleState(_offset) AS max_offset,
maxSimpleState(observed_timestamp) AS max_observed_timestamp,
maxSimpleState(timestamp) AS max_timestamp,
maxSimpleState(now()) AS max_created_at,
maxSimpleState(now() - observed_timestamp) AS max_lag
-FROM
- (
- SELECT
- kafka_source.1 AS kafka_topic,
- kafka_source.2 AS kafka_partition,
- kafka_source.3 AS kafka_offset,
- observed_timestamp,
- timestamp
- FROM posthog.logs34
- ARRAY JOIN [(_topic, _partition, _offset), (_source_topic, _source_partition, 0)] AS kafka_source
- WHERE kafka_topic != ''
- )
+FROM posthog.logs34
GROUP BY
- kafka_partition, kafka_topic
+ _partition, _topic
diff --git a/posthog/clickhouse/hcl/roles/logs/base/tables.hcl b/posthog/clickhouse/hcl/roles/logs/base/tables.hcl
index b3b4512caf63..5ba62b99d817 100644
--- a/posthog/clickhouse/hcl/roles/logs/base/tables.hcl
+++ b/posthog/clickhouse/hcl/roles/logs/base/tables.hcl
@@ -595,12 +595,6 @@ database "posthog" {
column "pattern_version" {
type = "UInt8"
}
- column "_source_topic" {
- type = "String"
- }
- column "_source_partition" {
- type = "UInt32"
- }
engine "distributed" {
cluster_name = "posthog_single_shard"
remote_database = "posthog"
@@ -1030,12 +1024,6 @@ database "posthog" {
column "pattern_version" {
type = "UInt8"
}
- column "_source_topic" {
- type = "String"
- }
- column "_source_partition" {
- type = "UInt32"
- }
index "idx_severity_text_set" {
expr = "severity_text"
type = "set(10)"
diff --git a/posthog/clickhouse/hcl/sql/dev/apm.sql b/posthog/clickhouse/hcl/sql/dev/apm.sql
index c17bc41d70ff..da2ff4d573fe 100644
--- a/posthog/clickhouse/hcl/sql/dev/apm.sql
+++ b/posthog/clickhouse/hcl/sql/dev/apm.sql
@@ -130,9 +130,7 @@ CREATE TABLE posthog.writable_logs34 (
_bytes_compressed UInt64,
_record_count UInt64,
pattern String,
- pattern_version UInt8,
- _source_topic String,
- _source_partition UInt32
+ pattern_version UInt8
) ENGINE = Distributed('logs', 'posthog', 'logs34') SETTINGS background_insert_batch = 1;
CREATE TABLE posthog.writable_metric_samples1 (
team_id Int32,
@@ -330,7 +328,7 @@ CREATE TABLE posthog.writable_trace_spans (
_bytes_compressed UInt64,
_record_count UInt64
) ENGINE = Distributed('logs', 'posthog', 'trace_spans');
-CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34 (uuid String, trace_id String, span_id String, trace_flags Int32, timestamp DateTime64(6), observed_timestamp DateTime64(6), body String, severity_text String, severity_number Int32, service_name String, instrumentation_scope String, event_name String, attributes_map_str Map(String, String), resource_attributes Map(String, String), team_id Int32, original_expiry_timestamp Nullable(DateTime64(6)), _partition UInt64, _topic LowCardinality(String), _offset UInt64, _record_count Int64, _bytes_uncompressed Nullable(Float64), _bytes_compressed Nullable(Float64), pattern String, pattern_version UInt8, _source_topic String, _source_partition UInt32) AS SELECT
+CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34 (uuid String, trace_id String, span_id String, trace_flags Int32, timestamp DateTime64(6), observed_timestamp DateTime64(6), body String, severity_text String, severity_number Int32, service_name String, instrumentation_scope String, event_name String, attributes_map_str Map(String, String), resource_attributes Map(String, String), team_id Int32, original_expiry_timestamp Nullable(DateTime64(6)), _partition UInt64, _topic LowCardinality(String), _offset UInt64, _record_count Int64, _bytes_uncompressed Nullable(Float64), _bytes_compressed Nullable(Float64), pattern String, pattern_version UInt8) AS SELECT
uuid,
trace_id,
span_id,
@@ -361,9 +359,7 @@ CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34
toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) / _record_count AS _bytes_uncompressed,
toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) / _record_count AS _bytes_compressed,
ifNull(pattern, '') AS pattern,
- toUInt8(ifNull(pattern_version, 0)) AS pattern_version,
- _headers.value[indexOf(_headers.name, 'source_topic')] AS _source_topic,
- toUInt32OrZero(_headers.value[indexOf(_headers.name, 'source_partition')]) AS _source_partition
+ toUInt8(ifNull(pattern_version, 0)) AS pattern_version
FROM posthog.kafka_logs_avro;
CREATE MATERIALIZED VIEW posthog.kafka_metrics_avro4_mv TO posthog.metrics4_input (uuid String, team_id Int32, metric_name String, series_fingerprint UInt64, resource_fingerprint UInt64, timestamp DateTime64(6), observed_timestamp DateTime64(6), original_expiry_timestamp DateTime64(6), service_name String, metric_type String, value Float64, count UInt64, histogram_bounds Array(Float64), histogram_counts Array(UInt64), trace_id String, span_id String, trace_flags Int32, has_labels Bool, unit String, aggregation_temporality String, is_monotonic UInt8, instrumentation_scope String, resource_attributes Map(String, String), attributes Map(String, String), _partition UInt64, _topic LowCardinality(String), _offset UInt64) AS SELECT
uuid,
diff --git a/posthog/clickhouse/hcl/sql/dev/logs.sql b/posthog/clickhouse/hcl/sql/dev/logs.sql
index da74c300f690..22e047ee1d57 100644
--- a/posthog/clickhouse/hcl/sql/dev/logs.sql
+++ b/posthog/clickhouse/hcl/sql/dev/logs.sql
@@ -102,8 +102,6 @@ CREATE TABLE posthog.logs34 (
_record_count UInt64,
pattern String,
pattern_version UInt8,
- _source_topic String,
- _source_partition UInt32,
INDEX idx_severity_text_set severity_text TYPE set(10) GRANULARITY 1,
INDEX idx_attributes_str_keys mapKeys(attributes_map_str) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_attributes_str_values mapValues(attributes_map_str) TYPE bloom_filter(0.001) GRANULARITY 1,
@@ -172,9 +170,7 @@ CREATE TABLE posthog.logs_distributed (
_bytes_compressed UInt64,
_record_count UInt64,
pattern String,
- pattern_version UInt8,
- _source_topic String,
- _source_partition UInt32
+ pattern_version UInt8
) ENGINE = Distributed('logs', 'posthog', 'logs34');
CREATE TABLE posthog.logs_kafka_metrics (
_partition UInt32,
@@ -919,27 +915,16 @@ FROM
GROUP BY
team_id, time_bucket, service_name;
CREATE MATERIALIZED VIEW posthog.kafka_logs_avro_kafka_metrics_mv TO posthog.logs_kafka_metrics (_partition UInt32, _topic String, max_offset SimpleAggregateFunction(max, UInt64), max_observed_timestamp SimpleAggregateFunction(max, DateTime64(6)), max_timestamp SimpleAggregateFunction(max, DateTime64(6)), max_created_at SimpleAggregateFunction(max, DateTime), max_lag SimpleAggregateFunction(max, Decimal(18, 6))) AS SELECT
- kafka_partition AS _partition,
- kafka_topic AS _topic,
- maxSimpleState(kafka_offset) AS max_offset,
+ _partition,
+ _topic,
+ maxSimpleState(_offset) AS max_offset,
maxSimpleState(observed_timestamp) AS max_observed_timestamp,
maxSimpleState(timestamp) AS max_timestamp,
maxSimpleState(now()) AS max_created_at,
maxSimpleState(now() - observed_timestamp) AS max_lag
-FROM
- (
- SELECT
- kafka_source.1 AS kafka_topic,
- kafka_source.2 AS kafka_partition,
- kafka_source.3 AS kafka_offset,
- observed_timestamp,
- timestamp
- FROM
- posthog.logs34 ARRAY JOIN [(_topic, _partition, _offset), (_source_topic, _source_partition, 0)] AS kafka_source
- WHERE kafka_topic != ''
- )
+FROM posthog.logs34
GROUP BY
- kafka_partition, kafka_topic;
+ _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,
diff --git a/posthog/clickhouse/hcl/sql/local-multi/ingestion_events.sql b/posthog/clickhouse/hcl/sql/local-multi/ingestion_events.sql
index 0fe85ba25fe4..2d908b2dfa24 100644
--- a/posthog/clickhouse/hcl/sql/local-multi/ingestion_events.sql
+++ b/posthog/clickhouse/hcl/sql/local-multi/ingestion_events.sql
@@ -223,9 +223,7 @@ CREATE TABLE posthog.writable_logs34 (
_bytes_compressed UInt64,
_record_count UInt64,
pattern String,
- pattern_version UInt8,
- _source_topic String,
- _source_partition UInt32
+ pattern_version UInt8
) ENGINE = Distributed('logs', 'posthog', 'logs34') SETTINGS background_insert_batch = 1;
CREATE MATERIALIZED VIEW posthog.events_json_table_mv TO posthog.writable_events_json (uuid UUID, event String, properties String, temporary_properties String, inserted_at DateTime64(3), timestamp DateTime64(6, 'UTC'), team_id Int64, distinct_id String, elements_chain String, created_at DateTime64(6, 'UTC'), person_id UUID, person_properties String, person_created_at DateTime64(3), group0_properties String, group1_properties String, group2_properties String, group3_properties String, group4_properties String, group0_created_at DateTime64(3), group1_created_at DateTime64(3), group2_created_at DateTime64(3), group3_created_at DateTime64(3), group4_created_at DateTime64(3), person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2), historical_migration Bool, captured_at DateTime64(6, 'UTC'), _timestamp Nullable(DateTime), _offset UInt64, _partition UInt64, consumer_breadcrumbs Array(String), total_event_size UInt32) AS SELECT
*,
@@ -287,7 +285,7 @@ FROM
SETTINGS
input_format_try_infer_dates = 0,
input_format_try_infer_datetimes = 0;
-CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34 (uuid String, trace_id String, span_id String, trace_flags Int32, timestamp DateTime64(6), observed_timestamp DateTime64(6), body String, severity_text String, severity_number Int32, service_name String, instrumentation_scope String, event_name String, attributes_map_str Map(String, String), resource_attributes Map(String, String), team_id Int32, original_expiry_timestamp DateTime64(6), _partition UInt64, _topic LowCardinality(String), _offset UInt64, _record_count Int64, _bytes_uncompressed Nullable(Int64), _bytes_compressed Nullable(Int64), pattern String, pattern_version UInt8, _source_topic String, _source_partition UInt32) AS SELECT
+CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34 (uuid String, trace_id String, span_id String, trace_flags Int32, timestamp DateTime64(6), observed_timestamp DateTime64(6), body String, severity_text String, severity_number Int32, service_name String, instrumentation_scope String, event_name String, attributes_map_str Map(String, String), resource_attributes Map(String, String), team_id Int32, original_expiry_timestamp DateTime64(6), _partition UInt64, _topic LowCardinality(String), _offset UInt64, _record_count Int64, _bytes_uncompressed Nullable(Int64), _bytes_compressed Nullable(Int64), pattern String, pattern_version UInt8) AS SELECT
uuid,
trace_id,
span_id,
@@ -318,7 +316,5 @@ CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34
toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) / _record_count AS _bytes_uncompressed,
toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) / _record_count AS _bytes_compressed,
ifNull(pattern, '') AS pattern,
- toUInt8(ifNull(pattern_version, 0)) AS pattern_version,
- _headers.value[indexOf(_headers.name, 'source_topic')] AS _source_topic,
- toUInt32OrZero(_headers.value[indexOf(_headers.name, 'source_partition')]) AS _source_partition
+ toUInt8(ifNull(pattern_version, 0)) AS pattern_version
FROM posthog.kafka_logs_avro;
diff --git a/posthog/clickhouse/hcl/sql/local-multi/logs.sql b/posthog/clickhouse/hcl/sql/local-multi/logs.sql
index 09943fb96ab3..59009ada1fb0 100644
--- a/posthog/clickhouse/hcl/sql/local-multi/logs.sql
+++ b/posthog/clickhouse/hcl/sql/local-multi/logs.sql
@@ -194,8 +194,6 @@ CREATE TABLE posthog.logs34 (
_record_count UInt64,
pattern String,
pattern_version UInt8,
- _source_topic String,
- _source_partition UInt32,
INDEX idx_severity_text_set severity_text TYPE set(10) GRANULARITY 1,
INDEX idx_attributes_str_keys mapKeys(attributes_map_str) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_attributes_str_values mapValues(attributes_map_str) TYPE bloom_filter(0.001) GRANULARITY 1,
@@ -264,9 +262,7 @@ CREATE TABLE posthog.logs_distributed (
_bytes_compressed UInt64,
_record_count UInt64,
pattern String,
- pattern_version UInt8,
- _source_topic String,
- _source_partition UInt32
+ pattern_version UInt8
) ENGINE = Distributed('posthog_single_shard', 'posthog', 'logs34');
CREATE TABLE posthog.logs_kafka_metrics (
_partition UInt32,
@@ -983,27 +979,16 @@ FROM
GROUP BY
team_id, time_bucket, service_name;
CREATE MATERIALIZED VIEW posthog.kafka_logs_avro_kafka_metrics_mv TO posthog.logs_kafka_metrics (_partition UInt32, _topic String, max_offset SimpleAggregateFunction(max, UInt64), max_observed_timestamp SimpleAggregateFunction(max, DateTime64(6)), max_timestamp SimpleAggregateFunction(max, DateTime64(6)), max_created_at SimpleAggregateFunction(max, DateTime), max_lag SimpleAggregateFunction(max, Decimal(18, 6))) AS SELECT
- kafka_partition AS _partition,
- kafka_topic AS _topic,
- maxSimpleState(kafka_offset) AS max_offset,
+ _partition,
+ _topic,
+ maxSimpleState(_offset) AS max_offset,
maxSimpleState(observed_timestamp) AS max_observed_timestamp,
maxSimpleState(timestamp) AS max_timestamp,
maxSimpleState(now()) AS max_created_at,
maxSimpleState(now() - observed_timestamp) AS max_lag
-FROM
- (
- SELECT
- kafka_source.1 AS kafka_topic,
- kafka_source.2 AS kafka_partition,
- kafka_source.3 AS kafka_offset,
- observed_timestamp,
- timestamp
- FROM
- posthog.logs34 ARRAY JOIN [(_topic, _partition, _offset), (_source_topic, _source_partition, 0)] AS kafka_source
- WHERE kafka_topic != ''
- )
+FROM posthog.logs34
GROUP BY
- kafka_partition, kafka_topic;
+ _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,
diff --git a/posthog/clickhouse/hcl/sql/local-single/all.sql b/posthog/clickhouse/hcl/sql/local-single/all.sql
index e198568875a4..de2f623d4941 100644
--- a/posthog/clickhouse/hcl/sql/local-single/all.sql
+++ b/posthog/clickhouse/hcl/sql/local-single/all.sql
@@ -1111,8 +1111,6 @@ CREATE TABLE posthog.logs34 (
_record_count UInt64,
pattern String,
pattern_version UInt8,
- _source_topic String,
- _source_partition UInt32,
INDEX idx_severity_text_set severity_text TYPE set(10) GRANULARITY 1,
INDEX idx_attributes_str_keys mapKeys(attributes_map_str) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_attributes_str_values mapValues(attributes_map_str) TYPE bloom_filter(0.001) GRANULARITY 1,
@@ -1181,9 +1179,7 @@ CREATE TABLE posthog.logs_distributed (
_bytes_compressed UInt64,
_record_count UInt64,
pattern String,
- pattern_version UInt8,
- _source_topic String,
- _source_partition UInt32
+ pattern_version UInt8
) ENGINE = Distributed('posthog_single_shard', 'posthog', 'logs34');
CREATE TABLE posthog.logs_kafka_metrics (
_partition UInt32,
@@ -4014,9 +4010,7 @@ CREATE TABLE posthog.writable_logs34 (
_bytes_compressed UInt64,
_record_count UInt64,
pattern String,
- pattern_version UInt8,
- _source_topic String,
- _source_partition UInt32
+ pattern_version UInt8
) ENGINE = Distributed('posthog_single_shard', 'posthog', 'logs34') SETTINGS background_insert_batch = 1;
CREATE TABLE posthog.writable_metrics4_attributes (
team_id Int32,
@@ -4902,7 +4896,7 @@ CREATE MATERIALIZED VIEW posthog.ingestion_warnings_v2_mv TO posthog.ingestion_w
_offset,
_partition
FROM posthog.kafka_ingestion_warnings_v2;
-CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34 (uuid String, trace_id String, span_id String, trace_flags Int32, timestamp DateTime64(6), observed_timestamp DateTime64(6), body String, severity_text String, severity_number Int32, service_name String, instrumentation_scope String, event_name String, attributes_map_str Map(String, String), resource_attributes Map(String, String), team_id Int32, original_expiry_timestamp DateTime64(6), _partition UInt64, _topic LowCardinality(String), _offset UInt64, _record_count Int64, _bytes_uncompressed Nullable(Int64), _bytes_compressed Nullable(Int64), pattern String, pattern_version UInt8, _source_topic String, _source_partition UInt32) AS SELECT
+CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34 (uuid String, trace_id String, span_id String, trace_flags Int32, timestamp DateTime64(6), observed_timestamp DateTime64(6), body String, severity_text String, severity_number Int32, service_name String, instrumentation_scope String, event_name String, attributes_map_str Map(String, String), resource_attributes Map(String, String), team_id Int32, original_expiry_timestamp DateTime64(6), _partition UInt64, _topic LowCardinality(String), _offset UInt64, _record_count Int64, _bytes_uncompressed Nullable(Int64), _bytes_compressed Nullable(Int64), pattern String, pattern_version UInt8) AS SELECT
uuid,
trace_id,
span_id,
@@ -4933,9 +4927,7 @@ CREATE MATERIALIZED VIEW posthog.kafka_logs34_avro_mv TO posthog.writable_logs34
toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) / _record_count AS _bytes_uncompressed,
toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) / _record_count AS _bytes_compressed,
ifNull(pattern, '') AS pattern,
- toUInt8(ifNull(pattern_version, 0)) AS pattern_version,
- _headers.value[indexOf(_headers.name, 'source_topic')] AS _source_topic,
- toUInt32OrZero(_headers.value[indexOf(_headers.name, 'source_partition')]) AS _source_partition
+ toUInt8(ifNull(pattern_version, 0)) AS pattern_version
FROM posthog.kafka_logs_avro;
CREATE MATERIALIZED VIEW posthog.kafka_logs_avro_billing_metrics_mv TO posthog.logs_billing_metrics (team_id Int32, time_bucket DateTime, service_name LowCardinality(String), bytes_uncompressed SimpleAggregateFunction(sum, Float64), bytes_compressed SimpleAggregateFunction(sum, Float64), record_count SimpleAggregateFunction(sum, UInt64)) AS SELECT
team_id,
@@ -4957,27 +4949,16 @@ FROM
GROUP BY
team_id, time_bucket, service_name;
CREATE MATERIALIZED VIEW posthog.kafka_logs_avro_kafka_metrics_mv TO posthog.logs_kafka_metrics (_partition UInt32, _topic String, max_offset SimpleAggregateFunction(max, UInt64), max_observed_timestamp SimpleAggregateFunction(max, DateTime64(6)), max_timestamp SimpleAggregateFunction(max, DateTime64(6)), max_created_at SimpleAggregateFunction(max, DateTime), max_lag SimpleAggregateFunction(max, Decimal(18, 6))) AS SELECT
- kafka_partition AS _partition,
- kafka_topic AS _topic,
- maxSimpleState(kafka_offset) AS max_offset,
+ _partition,
+ _topic,
+ maxSimpleState(_offset) AS max_offset,
maxSimpleState(observed_timestamp) AS max_observed_timestamp,
maxSimpleState(timestamp) AS max_timestamp,
maxSimpleState(now()) AS max_created_at,
maxSimpleState(now() - observed_timestamp) AS max_lag
-FROM
- (
- SELECT
- kafka_source.1 AS kafka_topic,
- kafka_source.2 AS kafka_partition,
- kafka_source.3 AS kafka_offset,
- observed_timestamp,
- timestamp
- FROM
- posthog.logs34 ARRAY JOIN [(_topic, _partition, _offset), (_source_topic, _source_partition, 0)] AS kafka_source
- WHERE kafka_topic != ''
- )
+FROM posthog.logs34
GROUP BY
- kafka_partition, kafka_topic;
+ _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,
diff --git a/posthog/clickhouse/hcl/sql/prod-eu/logs.sql b/posthog/clickhouse/hcl/sql/prod-eu/logs.sql
index 697a2c1247e4..ad0cd16e90ce 100644
--- a/posthog/clickhouse/hcl/sql/prod-eu/logs.sql
+++ b/posthog/clickhouse/hcl/sql/prod-eu/logs.sql
@@ -126,8 +126,6 @@ CREATE TABLE posthog.logs34 (
_record_count UInt64,
pattern String,
pattern_version UInt8,
- _source_topic String,
- _source_partition UInt32,
INDEX idx_severity_text_set severity_text TYPE set(10) GRANULARITY 1,
INDEX idx_attributes_str_keys mapKeys(attributes_map_str) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_attributes_str_values mapValues(attributes_map_str) TYPE bloom_filter(0.001) GRANULARITY 1,
@@ -196,9 +194,7 @@ CREATE TABLE posthog.logs_distributed (
_bytes_compressed UInt64,
_record_count UInt64,
pattern String,
- pattern_version UInt8,
- _source_topic String,
- _source_partition UInt32
+ pattern_version UInt8
) ENGINE = Distributed('logs', 'posthog', 'logs34');
CREATE TABLE posthog.logs_kafka_metrics (
_partition UInt32,
@@ -958,27 +954,16 @@ FROM
GROUP BY
team_id, time_bucket, service_name;
CREATE MATERIALIZED VIEW posthog.kafka_logs_avro_kafka_metrics_mv TO posthog.logs_kafka_metrics (_partition UInt32, _topic String, max_offset SimpleAggregateFunction(max, UInt64), max_observed_timestamp SimpleAggregateFunction(max, DateTime64(6)), max_timestamp SimpleAggregateFunction(max, DateTime64(6)), max_created_at SimpleAggregateFunction(max, DateTime), max_lag SimpleAggregateFunction(max, Decimal(18, 6))) AS SELECT
- kafka_partition AS _partition,
- kafka_topic AS _topic,
- maxSimpleState(kafka_offset) AS max_offset,
+ _partition,
+ _topic,
+ maxSimpleState(_offset) AS max_offset,
maxSimpleState(observed_timestamp) AS max_observed_timestamp,
maxSimpleState(timestamp) AS max_timestamp,
maxSimpleState(now()) AS max_created_at,
maxSimpleState(now() - observed_timestamp) AS max_lag
-FROM
- (
- SELECT
- kafka_source.1 AS kafka_topic,
- kafka_source.2 AS kafka_partition,
- kafka_source.3 AS kafka_offset,
- observed_timestamp,
- timestamp
- FROM
- posthog.logs34 ARRAY JOIN [(_topic, _partition, _offset), (_source_topic, _source_partition, 0)] AS kafka_source
- WHERE kafka_topic != ''
- )
+FROM posthog.logs34
GROUP BY
- kafka_partition, kafka_topic;
+ _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,
diff --git a/posthog/clickhouse/hcl/sql/prod-us/logs.sql b/posthog/clickhouse/hcl/sql/prod-us/logs.sql
index 59d93d3ddc1c..1ae52a0a4a19 100644
--- a/posthog/clickhouse/hcl/sql/prod-us/logs.sql
+++ b/posthog/clickhouse/hcl/sql/prod-us/logs.sql
@@ -126,8 +126,6 @@ CREATE TABLE posthog.logs34 (
_record_count UInt64,
pattern String,
pattern_version UInt8,
- _source_topic String,
- _source_partition UInt32,
INDEX idx_severity_text_set severity_text TYPE set(10) GRANULARITY 1,
INDEX idx_attributes_str_keys mapKeys(attributes_map_str) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_attributes_str_values mapValues(attributes_map_str) TYPE bloom_filter(0.001) GRANULARITY 1,
@@ -196,9 +194,7 @@ CREATE TABLE posthog.logs_distributed (
_bytes_compressed UInt64,
_record_count UInt64,
pattern String,
- pattern_version UInt8,
- _source_topic String,
- _source_partition UInt32
+ pattern_version UInt8
) ENGINE = Distributed('logs', 'posthog', 'logs34');
CREATE TABLE posthog.logs_kafka_metrics (
_partition UInt32,
@@ -952,27 +948,16 @@ FROM
GROUP BY
team_id, time_bucket, service_name;
CREATE MATERIALIZED VIEW posthog.kafka_logs_avro_kafka_metrics_mv TO posthog.logs_kafka_metrics (_partition UInt32, _topic String, max_offset SimpleAggregateFunction(max, UInt64), max_observed_timestamp SimpleAggregateFunction(max, DateTime64(6)), max_timestamp SimpleAggregateFunction(max, DateTime64(6)), max_created_at SimpleAggregateFunction(max, DateTime), max_lag SimpleAggregateFunction(max, Decimal(18, 6))) AS SELECT
- kafka_partition AS _partition,
- kafka_topic AS _topic,
- maxSimpleState(kafka_offset) AS max_offset,
+ _partition,
+ _topic,
+ maxSimpleState(_offset) AS max_offset,
maxSimpleState(observed_timestamp) AS max_observed_timestamp,
maxSimpleState(timestamp) AS max_timestamp,
maxSimpleState(now()) AS max_created_at,
maxSimpleState(now() - observed_timestamp) AS max_lag
-FROM
- (
- SELECT
- kafka_source.1 AS kafka_topic,
- kafka_source.2 AS kafka_partition,
- kafka_source.3 AS kafka_offset,
- observed_timestamp,
- timestamp
- FROM
- posthog.logs34 ARRAY JOIN [(_topic, _partition, _offset), (_source_topic, _source_partition, 0)] AS kafka_source
- WHERE kafka_topic != ''
- )
+FROM posthog.logs34
GROUP BY
- kafka_partition, kafka_topic;
+ _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,
diff --git a/posthog/clickhouse/logs/__init__.py b/posthog/clickhouse/logs/__init__.py
index 4c8edc146b8f..fdcdc9c07d09 100644
--- a/posthog/clickhouse/logs/__init__.py
+++ b/posthog/clickhouse/logs/__init__.py
@@ -15,7 +15,6 @@ from .logs34 import (
KAFKA_LOGS34_AVRO_MV_SELECT,
KAFKA_LOGS_AVRO_BILLING_METRICS_MV,
KAFKA_LOGS_AVRO_KAFKA_METRICS_MV,
- KAFKA_LOGS_AVRO_KAFKA_METRICS_MV_SELECT,
KAFKA_LOGS_AVRO_TABLE_SQL,
LOGS34_TABLE_SQL,
LOGS34_TO_LOG_ATTRIBUTES3_MV,
@@ -51,7 +50,6 @@ __all__ = [
"KAFKA_LOGS34_AVRO_MV",
"KAFKA_LOGS34_AVRO_MV_SELECT",
"KAFKA_LOGS_AVRO_KAFKA_METRICS_MV",
- "KAFKA_LOGS_AVRO_KAFKA_METRICS_MV_SELECT",
"KAFKA_LOGS_AVRO_BILLING_METRICS_MV",
"LOG_ATTRIBUTES2_TABLE_SQL",
"LOG_ATTRIBUTES2_DISTRIBUTED_TABLE_SQL",
diff --git a/posthog/clickhouse/logs/logs34.py b/posthog/clickhouse/logs/logs34.py
index b0ec3e1e1562..6c02f1d783f3 100644
--- a/posthog/clickhouse/logs/logs34.py
+++ b/posthog/clickhouse/logs/logs34.py
@@ -49,8 +49,6 @@ CREATE TABLE IF NOT EXISTS {settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE}.{TABLE_NA
`_record_count` UInt64,
`pattern` String,
`pattern_version` UInt8,
- `_source_topic` String,
- `_source_partition` UInt32,
INDEX idx_severity_text_set severity_text TYPE set(10) GRANULARITY 1,
INDEX idx_attributes_str_keys mapKeys(attributes_map_str) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_attributes_str_values mapValues(attributes_map_str) TYPE bloom_filter(0.001) GRANULARITY 1,
@@ -149,9 +147,7 @@ CREATE TABLE IF NOT EXISTS {db}.writable_logs34
`_bytes_compressed` UInt64,
`_record_count` UInt64,
`pattern` String,
- `pattern_version` UInt8,
- `_source_topic` String,
- `_source_partition` UInt32
+ `pattern_version` UInt8
)
ENGINE = {Distributed(data_table=TABLE_NAME, cluster=settings.CLICKHOUSE_LOGS_WRITE_CLUSTER)}
SETTINGS background_insert_batch = 1
@@ -324,9 +320,7 @@ def KAFKA_LOGS34_AVRO_MV_SELECT():
toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_uncompressed')]) / _record_count AS _bytes_uncompressed,
toInt64OrNull(_headers.value[indexOf(_headers.name, 'bytes_compressed')]) / _record_count AS _bytes_compressed,
ifNull(pattern, '') AS pattern,
- toUInt8(ifNull(pattern_version, 0)) AS pattern_version,
- _headers.value[indexOf(_headers.name, 'source_topic')] AS _source_topic,
- toUInt32OrZero(_headers.value[indexOf(_headers.name, 'source_partition')]) AS _source_partition
+ toUInt8(ifNull(pattern_version, 0)) AS pattern_version
FROM {db}.{KAFKA_TABLE_NAME}"""
@@ -362,9 +356,7 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS {db}.kafka_logs34_avro_mv TO {db}.{to_tab
`_bytes_uncompressed` Nullable(Int64),
`_bytes_compressed` Nullable(Int64),
`pattern` String,
- `pattern_version` UInt8,
- `_source_topic` String,
- `_source_partition` UInt32
+ `pattern_version` UInt8
)
AS {KAFKA_LOGS34_AVRO_MV_SELECT()}
"""
@@ -439,35 +431,6 @@ AS {LOGS34_TO_VOLUME_BUCKETS_MV_SELECT()}
"""
-def KAFKA_LOGS_AVRO_KAFKA_METRICS_MV_SELECT():
- db = settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE
- # Each row counts toward the clickhouse_logs partition and the logs_ingestion partition it came
- # from, because both topics use random partitioning and the lag checkpoint needs both. A row
- # without the source header has an empty source topic, and the WHERE skips it. The source
- # offset is not known, so it counts as 0.
- return f"""SELECT
- kafka_partition AS _partition,
- kafka_topic AS _topic,
- maxSimpleState(kafka_offset) AS max_offset,
- maxSimpleState(observed_timestamp) AS max_observed_timestamp,
- maxSimpleState(timestamp) AS max_timestamp,
- maxSimpleState(now()) AS max_created_at,
- maxSimpleState(now() - observed_timestamp) AS max_lag
-FROM
-(
- SELECT
- kafka_source.1 AS kafka_topic,
- kafka_source.2 AS kafka_partition,
- kafka_source.3 AS kafka_offset,
- observed_timestamp,
- timestamp
- FROM {db}.{TABLE_NAME}
- ARRAY JOIN [(_topic, _partition, _offset), (_source_topic, _source_partition, 0)] AS kafka_source
- WHERE kafka_topic != ''
-)
-GROUP BY kafka_partition, kafka_topic"""
-
-
def KAFKA_LOGS_AVRO_KAFKA_METRICS_MV():
db = settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE
return f"""
@@ -481,7 +444,16 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS {db}.kafka_logs_avro_kafka_metrics_mv TO
`max_created_at` SimpleAggregateFunction(max, DateTime),
`max_lag` SimpleAggregateFunction(max, Decimal(18, 6))
)
-AS {KAFKA_LOGS_AVRO_KAFKA_METRICS_MV_SELECT()}
+AS SELECT
+ _partition,
+ _topic,
+ maxSimpleState(_offset) AS max_offset,
+ maxSimpleState(observed_timestamp) AS max_observed_timestamp,
+ maxSimpleState(timestamp) AS max_timestamp,
+ maxSimpleState(now()) AS max_created_at,
+ maxSimpleState(now() - observed_timestamp) AS max_lag
+FROM {db}.{TABLE_NAME}
+GROUP BY _partition, _topic
"""
diff --git a/posthog/clickhouse/migrations/0343_logs_source_partition.py b/posthog/clickhouse/migrations/0343_logs_source_partition.py
deleted file mode 100644
index d812c8f45eea..000000000000
--- a/posthog/clickhouse/migrations/0343_logs_source_partition.py
+++ /dev/null
@@ -1,49 +0,0 @@
-from django.conf import settings
-
-from posthog.clickhouse.client.connection import NodeRole
-from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions
-from posthog.clickhouse.logs import KAFKA_LOGS34_AVRO_MV, KAFKA_LOGS_AVRO_KAFKA_METRICS_MV_SELECT
-
-DB = settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE
-
-# Records the logs_ingestion partition of each log row, so the live logs checkpoint can track
-# progress for both topics that a row passes through. The Node consumer sends the partition in the
-# `source_topic` and `source_partition` headers.
-#
-# The columns go on every table that the row passes through, before the MVs that write or read
-# them. Adding a column to a Distributed table changes only its metadata.
-#
-# The Kafka MV gets new output columns, so it is dropped and created again. The Kafka table stays,
-# with the same consumer group, so the gap causes lag and no data loss. The metrics MV keeps the
-# same output columns, so MODIFY QUERY is sufficient.
-
-ADD_COLUMNS = "ADD COLUMN IF NOT EXISTS _source_topic String, ADD COLUMN IF NOT EXISTS _source_partition UInt32"
-
-operations = [
- run_sql_with_exceptions(
- f"ALTER TABLE {DB}.logs34 {ADD_COLUMNS}",
- node_roles=[NodeRole.LOGS],
- sharded=False,
- is_alter_on_replicated_table=True,
- ),
- run_sql_with_exceptions(
- f"ALTER TABLE {DB}.logs_distributed {ADD_COLUMNS}",
- node_roles=[NodeRole.LOGS],
- sharded=False,
- is_alter_on_replicated_table=False,
- ),
- run_sql_with_exceptions(
- f"ALTER TABLE {DB}.writable_logs34 {ADD_COLUMNS}",
- node_roles=[NodeRole.INGESTION_EVENTS],
- sharded=False,
- is_alter_on_replicated_table=False,
- ),
- run_sql_with_exceptions(
- f"ALTER TABLE {DB}.kafka_logs_avro_kafka_metrics_mv MODIFY QUERY\n{KAFKA_LOGS_AVRO_KAFKA_METRICS_MV_SELECT()}",
- node_roles=[NodeRole.LOGS],
- sharded=False,
- is_alter_on_replicated_table=False,
- ),
- run_sql_with_exceptions(f"DROP TABLE IF EXISTS {DB}.kafka_logs34_avro_mv", node_roles=[NodeRole.INGESTION_EVENTS]),
- run_sql_with_exceptions(KAFKA_LOGS34_AVRO_MV(to_table="writable_logs34"), node_roles=[NodeRole.INGESTION_EVENTS]),
-]
diff --git a/posthog/clickhouse/migrations/max_migration.txt b/posthog/clickhouse/migrations/max_migration.txt
index 3494eba8fa83..b08a9384384f 100644
--- a/posthog/clickhouse/migrations/max_migration.txt
+++ b/posthog/clickhouse/migrations/max_migration.txt
@@ -1 +1 @@
-0343_logs_source_partition
+0342_metrics4_names_service_name
diff --git a/posthog/clickhouse/test/__snapshots__/test_schema.ambr b/posthog/clickhouse/test/__snapshots__/test_schema.ambr
index e7fe54c1f19d..c83b485814dc 100644
--- a/posthog/clickhouse/test/__snapshots__/test_schema.ambr
+++ b/posthog/clickhouse/test/__snapshots__/test_schema.ambr
@@ -3857,8 +3857,6 @@
`_record_count` UInt64,
`pattern` String,
`pattern_version` UInt8,
- `_source_topic` String,
- `_source_partition` UInt32,
INDEX idx_severity_text_set severity_text TYPE set(10) GRANULARITY 1,
INDEX idx_attributes_str_keys mapKeys(attributes_map_str) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_attributes_str_values mapValues(attributes_map_str) TYPE bloom_filter(0.001) GRANULARITY 1,
@@ -12075,8 +12073,6 @@
`_record_count` UInt64,
`pattern` String,
`pattern_version` UInt8,
- `_source_topic` String,
- `_source_partition` UInt32,
INDEX idx_severity_text_set severity_text TYPE set(10) GRANULARITY 1,
INDEX idx_attributes_str_keys mapKeys(attributes_map_str) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_attributes_str_values mapValues(attributes_map_str) TYPE bloom_filter(0.001) GRANULARITY 1,
diff --git a/posthog/clickhouse/test/test_schema.py b/posthog/clickhouse/test/test_schema.py
index 2a2715f907ba..0bd6f7492cf8 100644
--- a/posthog/clickhouse/test/test_schema.py
+++ b/posthog/clickhouse/test/test_schema.py
@@ -13,7 +13,7 @@ from posthog.hogql.database.schema.flag_evaluations import FLAG_EVALUATIONS_CLIC
from posthog.clickhouse.client import sync_execute
from posthog.clickhouse.kafka_engine import CONSUMER_GROUP_EVENTS_JSON_NATIVE_JSON, KAFKA_COLUMNS_WITH_PARTITION
-from posthog.clickhouse.logs import KAFKA_LOGS_AVRO_KAFKA_METRICS_MV_SELECT, LOGS34_TO_VOLUME_BUCKETS_MV_SELECT
+from posthog.clickhouse.logs import LOGS34_TO_VOLUME_BUCKETS_MV_SELECT
from posthog.clickhouse.schema import (
CREATE_KAFKA_TABLE_QUERIES,
CREATE_MERGETREE_TABLE_QUERIES,
@@ -137,36 +137,6 @@ def test_logs_volume_bucket_retention_covers_raw_expiry(
)
[email protected]("clickhouse_database")
-def test_logs_kafka_metrics_counts_rows_toward_source_partition() -> None:
- select = KAFKA_LOGS_AVRO_KAFKA_METRICS_MV_SELECT().replace(
- f"FROM {django_settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE}.logs34", "FROM metrics_input"
- )
- rows = sync_execute(
- """
- WITH metrics_input AS (
- SELECT
- source_row.1 AS _topic,
- toUInt32(source_row.2) AS _partition,
- toUInt64(source_row.3) AS _offset,
- source_row.4 AS _source_topic,
- toUInt32(source_row.5) AS _source_partition,
- toDateTime64('2026-01-02 12:00:00', 6, 'UTC') AS observed_timestamp,
- observed_timestamp AS timestamp
- FROM (
- SELECT arrayJoin([
- ('clickhouse_logs', 3, 10, 'logs_ingestion', 7),
- ('clickhouse_logs', 5, 11, '', 0)
- ]) AS source_row
- )
- )
- SELECT _topic, _partition, max_offset FROM ("""
- + select
- + ") ORDER BY _topic, _partition",
- )
- assert rows == [("clickhouse_logs", 3, 10), ("clickhouse_logs", 5, 11), ("logs_ingestion", 7, 0)]
-
-
def _column_definition_lines(block: str) -> Iterator[str]:
for raw_line in block.splitlines():
line = raw_line.strip().lstrip(",").strip()