Skip to content

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

feat(metrics): drop uuid and the minute projection from metrics2 (#97343)

Frank Hamand6027422f5a89
diff --git a/posthog/clickhouse/hcl/golden/dev/logs.hcl b/posthog/clickhouse/hcl/golden/dev/logs.hcl
index 6d2357e95d11..71c8b95e1a2e 100644
--- a/posthog/clickhouse/hcl/golden/dev/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/dev/logs.hcl
@@ -1558,9 +1558,6 @@ SQL
index_granularity_bytes = "104857600"
ttl_only_drop_parts = "1"
}
- column "uuid" {
- type = "String"
- }
column "team_id" {
type = "Int32"
}
@@ -1674,27 +1671,6 @@ SQL
type = "minmax"
granularity = 1
}
- projection "projection_series_minute" {
- query = <<SQL
-SELECT
- team_id,
- metric_name,
- service_name,
- metric_type,
- resource_fingerprint,
- series_fingerprint,
- toStartOfMinute(timestamp) AS minute,
- count() AS sample_count,
- sum(value) AS total_value,
- min(value) AS min_value,
- max(value) AS max_value,
- argMin(value, timestamp) AS first_value,
- argMax(value, timestamp) AS last_value
-GROUP BY
- team_id, metric_name, service_name, metric_type, resource_fingerprint, series_fingerprint, minute
-SQL
-
- }
projection "projection_series_activity" {
query = <<SQL
SELECT
@@ -1805,9 +1781,6 @@ SQL
}
table "metrics_distributed" {
- column "uuid" {
- type = "String"
- }
column "team_id" {
type = "Int32"
}
@@ -3552,7 +3525,6 @@ SQL
to_table = "posthog.metrics2"
query = <<SQL
SELECT
- uuid,
team_id,
metric_name,
series_fingerprint,
@@ -3580,9 +3552,6 @@ SELECT
FROM posthog.metrics2_input
SQL
- column "uuid" {
- type = "String"
- }
column "team_id" {
type = "Int32"
}
diff --git a/posthog/clickhouse/hcl/golden/local-multi/logs.hcl b/posthog/clickhouse/hcl/golden/local-multi/logs.hcl
index ebb5c102eb2d..952dfc6db32b 100644
--- a/posthog/clickhouse/hcl/golden/local-multi/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/local-multi/logs.hcl
@@ -2125,9 +2125,6 @@ SQL
index_granularity_bytes = "104857600"
ttl_only_drop_parts = "1"
}
- column "uuid" {
- type = "String"
- }
column "team_id" {
type = "Int32"
}
@@ -2241,27 +2238,6 @@ SQL
type = "minmax"
granularity = 1
}
- projection "projection_series_minute" {
- query = <<SQL
-SELECT
- team_id,
- metric_name,
- service_name,
- metric_type,
- resource_fingerprint,
- series_fingerprint,
- toStartOfMinute(timestamp) AS minute,
- count() AS sample_count,
- sum(value) AS total_value,
- min(value) AS min_value,
- max(value) AS max_value,
- argMin(value, timestamp) AS first_value,
- argMax(value, timestamp) AS last_value
-GROUP BY
- team_id, metric_name, service_name, metric_type, resource_fingerprint, series_fingerprint, minute
-SQL
-
- }
projection "projection_series_activity" {
query = <<SQL
SELECT
@@ -2372,9 +2348,6 @@ SQL
}
table "metrics_distributed" {
- column "uuid" {
- type = "String"
- }
column "team_id" {
type = "Int32"
}
@@ -4513,7 +4486,6 @@ SQL
to_table = "posthog.metrics2"
query = <<SQL
SELECT
- uuid,
team_id,
metric_name,
series_fingerprint,
@@ -4541,9 +4513,6 @@ SELECT
FROM posthog.metrics2_input
SQL
- column "uuid" {
- type = "String"
- }
column "team_id" {
type = "Int32"
}
diff --git a/posthog/clickhouse/hcl/golden/local-single/all.hcl b/posthog/clickhouse/hcl/golden/local-single/all.hcl
index e004ca25b16d..193856a9b8c9 100644
--- a/posthog/clickhouse/hcl/golden/local-single/all.hcl
+++ b/posthog/clickhouse/hcl/golden/local-single/all.hcl
@@ -7008,9 +7008,6 @@ SQL
index_granularity_bytes = "104857600"
ttl_only_drop_parts = "1"
}
- column "uuid" {
- type = "String"
- }
column "team_id" {
type = "Int32"
}
@@ -7124,27 +7121,6 @@ SQL
type = "minmax"
granularity = 1
}
- projection "projection_series_minute" {
- query = <<SQL
-SELECT
- team_id,
- metric_name,
- service_name,
- metric_type,
- resource_fingerprint,
- series_fingerprint,
- toStartOfMinute(timestamp) AS minute,
- count() AS sample_count,
- sum(value) AS total_value,
- min(value) AS min_value,
- max(value) AS max_value,
- argMin(value, timestamp) AS first_value,
- argMax(value, timestamp) AS last_value
-GROUP BY
- team_id, metric_name, service_name, metric_type, resource_fingerprint, series_fingerprint, minute
-SQL
-
- }
projection "projection_series_activity" {
query = <<SQL
SELECT
@@ -7255,9 +7231,6 @@ SQL
}
table "metrics_distributed" {
- column "uuid" {
- type = "String"
- }
column "team_id" {
type = "Int32"
}
@@ -21723,7 +21696,6 @@ SQL
to_table = "posthog.metrics2"
query = <<SQL
SELECT
- uuid,
team_id,
metric_name,
series_fingerprint,
@@ -21751,9 +21723,6 @@ SELECT
FROM posthog.metrics2_input
SQL
- column "uuid" {
- type = "String"
- }
column "team_id" {
type = "Int32"
}
diff --git a/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl b/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl
index e046dd6dfa12..17c7a7b3a1b8 100644
--- a/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl
@@ -1711,9 +1711,6 @@ SQL
index_granularity_bytes = "104857600"
ttl_only_drop_parts = "1"
}
- column "uuid" {
- type = "String"
- }
column "team_id" {
type = "Int32"
}
@@ -1827,27 +1824,6 @@ SQL
type = "minmax"
granularity = 1
}
- projection "projection_series_minute" {
- query = <<SQL
-SELECT
- team_id,
- metric_name,
- service_name,
- metric_type,
- resource_fingerprint,
- series_fingerprint,
- toStartOfMinute(timestamp) AS minute,
- count() AS sample_count,
- sum(value) AS total_value,
- min(value) AS min_value,
- max(value) AS max_value,
- argMin(value, timestamp) AS first_value,
- argMax(value, timestamp) AS last_value
-GROUP BY
- team_id, metric_name, service_name, metric_type, resource_fingerprint, series_fingerprint, minute
-SQL
-
- }
projection "projection_series_activity" {
query = <<SQL
SELECT
@@ -1958,9 +1934,6 @@ SQL
}
table "metrics_distributed" {
- column "uuid" {
- type = "String"
- }
column "team_id" {
type = "Int32"
}
@@ -4095,7 +4068,6 @@ SQL
to_table = "posthog.metrics2"
query = <<SQL
SELECT
- uuid,
team_id,
metric_name,
series_fingerprint,
@@ -4123,9 +4095,6 @@ SELECT
FROM posthog.metrics2_input
SQL
- column "uuid" {
- type = "String"
- }
column "team_id" {
type = "Int32"
}
diff --git a/posthog/clickhouse/hcl/golden/prod-us/logs.hcl b/posthog/clickhouse/hcl/golden/prod-us/logs.hcl
index da94d9532082..636e11aa724f 100644
--- a/posthog/clickhouse/hcl/golden/prod-us/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/prod-us/logs.hcl
@@ -1711,9 +1711,6 @@ SQL
index_granularity_bytes = "104857600"
ttl_only_drop_parts = "1"
}
- column "uuid" {
- type = "String"
- }
column "team_id" {
type = "Int32"
}
@@ -1827,27 +1824,6 @@ SQL
type = "minmax"
granularity = 1
}
- projection "projection_series_minute" {
- query = <<SQL
-SELECT
- team_id,
- metric_name,
- service_name,
- metric_type,
- resource_fingerprint,
- series_fingerprint,
- toStartOfMinute(timestamp) AS minute,
- count() AS sample_count,
- sum(value) AS total_value,
- min(value) AS min_value,
- max(value) AS max_value,
- argMin(value, timestamp) AS first_value,
- argMax(value, timestamp) AS last_value
-GROUP BY
- team_id, metric_name, service_name, metric_type, resource_fingerprint, series_fingerprint, minute
-SQL
-
- }
projection "projection_series_activity" {
query = <<SQL
SELECT
@@ -1958,9 +1934,6 @@ SQL
}
table "metrics_distributed" {
- column "uuid" {
- type = "String"
- }
column "team_id" {
type = "Int32"
}
@@ -4077,7 +4050,6 @@ SQL
to_table = "posthog.metrics2"
query = <<SQL
SELECT
- uuid,
team_id,
metric_name,
series_fingerprint,
@@ -4105,9 +4077,6 @@ SELECT
FROM posthog.metrics2_input
SQL
- column "uuid" {
- type = "String"
- }
column "team_id" {
type = "Int32"
}
diff --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.sql
index b2742dde15db..27c4344af7cb 100644
--- 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.sql
@@ -1,5 +1,4 @@
SELECT
- uuid,
team_id,
metric_name,
series_fingerprint,
diff --git a/posthog/clickhouse/hcl/roles/logs/metrics/tables.hcl b/posthog/clickhouse/hcl/roles/logs/metrics/tables.hcl
index 93377d826f41..bfeba8337c38 100644
--- a/posthog/clickhouse/hcl/roles/logs/metrics/tables.hcl
+++ b/posthog/clickhouse/hcl/roles/logs/metrics/tables.hcl
@@ -647,9 +647,6 @@ SQL
index_granularity_bytes = "104857600"
ttl_only_drop_parts = "1"
}
- column "uuid" {
- type = "String"
- }
column "team_id" {
type = "Int32"
}
@@ -763,27 +760,6 @@ SQL
type = "minmax"
granularity = 1
}
- projection "projection_series_minute" {
- query = <<SQL
-SELECT
- team_id,
- metric_name,
- service_name,
- metric_type,
- resource_fingerprint,
- series_fingerprint,
- toStartOfMinute(timestamp) AS minute,
- count() AS sample_count,
- sum(value) AS total_value,
- min(value) AS min_value,
- max(value) AS max_value,
- argMin(value, timestamp) AS first_value,
- argMax(value, timestamp) AS last_value
-GROUP BY
- team_id, metric_name, service_name, metric_type, resource_fingerprint, series_fingerprint, minute
-SQL
-
- }
projection "projection_series_activity" {
query = <<SQL
SELECT
@@ -941,9 +917,6 @@ SQL
}
}
table "metrics_distributed" {
- column "uuid" {
- type = "String"
- }
column "team_id" {
type = "Int32"
}
@@ -1124,9 +1097,6 @@ SQL
materialized_view "metrics2_input_to_metrics" {
to_table = "posthog.metrics2"
query = file("sql/metrics2_input_to_metrics.sql")
- column "uuid" {
- type = "String"
- }
column "team_id" {
type = "Int32"
}
diff --git a/posthog/clickhouse/hcl/sql/dev/logs.sql b/posthog/clickhouse/hcl/sql/dev/logs.sql
index 875696ebfbf3..b3b00925577b 100644
--- a/posthog/clickhouse/hcl/sql/dev/logs.sql
+++ b/posthog/clickhouse/hcl/sql/dev/logs.sql
@@ -382,7 +382,6 @@ GROUP BY
team_id, time_bucket, toStartOfMinute(timestamp), service_name, metric_name, metric_type, resource_fingerprint)
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/logs/{shard}/posthog.metrics1', '{replica}') ORDER BY (team_id, time_bucket, service_name, metric_name, resource_fingerprint, timestamp) PARTITION BY toDate(timestamp) SETTINGS index_granularity = 8192, index_granularity_bytes = 104857600, ttl_only_drop_parts = 1;
CREATE TABLE posthog.metrics2 (
- uuid String,
team_id Int32,
metric_name LowCardinality(String),
time_bucket DateTime MATERIALIZED toStartOfHour(timestamp),
@@ -414,22 +413,6 @@ CREATE TABLE posthog.metrics2 (
INDEX idx_trace_id_bf trace_id TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_resource_fingerprint resource_fingerprint TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_observed_minmax observed_timestamp TYPE minmax GRANULARITY 1,
- PROJECTION projection_series_minute (SELECT
- team_id,
- metric_name,
- service_name,
- metric_type,
- resource_fingerprint,
- series_fingerprint,
- toStartOfMinute(timestamp) AS minute,
- count() AS sample_count,
- sum(value) AS total_value,
- min(value) AS min_value,
- max(value) AS max_value,
- argMin(value, timestamp) AS first_value,
- argMax(value, timestamp) AS last_value
-GROUP BY
- team_id, metric_name, service_name, metric_type, resource_fingerprint, series_fingerprint, minute),
PROJECTION projection_series_activity (SELECT
team_id,
service_name,
@@ -473,7 +456,6 @@ CREATE TABLE posthog.metrics2_input (
_offset UInt64
) ENGINE = Null();
CREATE TABLE posthog.metrics_distributed (
- uuid String,
team_id Int32,
metric_name LowCardinality(String),
time_bucket DateTime MATERIALIZED toStartOfHour(timestamp),
@@ -1051,8 +1033,7 @@ CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_series TO posthog.metr
original_expiry_timestamp
FROM posthog.metrics2_input
WHERE has_labels;
-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metrics TO posthog.metrics2 (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, _partition UInt32, _topic String, _offset UInt64) AS SELECT
- uuid,
+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,
diff --git a/posthog/clickhouse/hcl/sql/local-multi/logs.sql b/posthog/clickhouse/hcl/sql/local-multi/logs.sql
index 76caa19076bf..5d9f25132f85 100644
--- a/posthog/clickhouse/hcl/sql/local-multi/logs.sql
+++ b/posthog/clickhouse/hcl/sql/local-multi/logs.sql
@@ -495,7 +495,6 @@ GROUP BY
team_id, time_bucket, toStartOfMinute(timestamp), service_name, metric_name, metric_type, resource_fingerprint)
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.metrics1', '{replica}') ORDER BY (team_id, time_bucket, service_name, metric_name, resource_fingerprint, timestamp) PARTITION BY toDate(timestamp) SETTINGS index_granularity = 8192, index_granularity_bytes = 104857600, ttl_only_drop_parts = 1;
CREATE TABLE posthog.metrics2 (
- uuid String,
team_id Int32,
metric_name LowCardinality(String),
time_bucket DateTime MATERIALIZED toStartOfHour(timestamp),
@@ -527,22 +526,6 @@ CREATE TABLE posthog.metrics2 (
INDEX idx_trace_id_bf trace_id TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_resource_fingerprint resource_fingerprint TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_observed_minmax observed_timestamp TYPE minmax GRANULARITY 1,
- PROJECTION projection_series_minute (SELECT
- team_id,
- metric_name,
- service_name,
- metric_type,
- resource_fingerprint,
- series_fingerprint,
- toStartOfMinute(timestamp) AS minute,
- count() AS sample_count,
- sum(value) AS total_value,
- min(value) AS min_value,
- max(value) AS max_value,
- argMin(value, timestamp) AS first_value,
- argMax(value, timestamp) AS last_value
-GROUP BY
- team_id, metric_name, service_name, metric_type, resource_fingerprint, series_fingerprint, minute),
PROJECTION projection_series_activity (SELECT
team_id,
service_name,
@@ -586,7 +569,6 @@ CREATE TABLE posthog.metrics2_input (
_offset UInt64
) ENGINE = Null();
CREATE TABLE posthog.metrics_distributed (
- uuid String,
team_id Int32,
metric_name LowCardinality(String),
time_bucket DateTime MATERIALIZED toStartOfHour(timestamp),
@@ -1292,8 +1274,7 @@ CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_series TO posthog.metr
original_expiry_timestamp
FROM posthog.metrics2_input
WHERE has_labels;
-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metrics TO posthog.metrics2 (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, _partition UInt32, _topic String, _offset UInt64) AS SELECT
- uuid,
+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,
diff --git a/posthog/clickhouse/hcl/sql/local-single/all.sql b/posthog/clickhouse/hcl/sql/local-single/all.sql
index 9e1c2dab1832..6782a7aa72e2 100644
--- a/posthog/clickhouse/hcl/sql/local-single/all.sql
+++ b/posthog/clickhouse/hcl/sql/local-single/all.sql
@@ -1386,7 +1386,6 @@ GROUP BY
team_id, time_bucket, toStartOfMinute(timestamp), service_name, metric_name, metric_type, resource_fingerprint)
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.metrics1', '{replica}') ORDER BY (team_id, time_bucket, service_name, metric_name, resource_fingerprint, timestamp) PARTITION BY toDate(timestamp) SETTINGS index_granularity = 8192, index_granularity_bytes = 104857600, ttl_only_drop_parts = 1;
CREATE TABLE posthog.metrics2 (
- uuid String,
team_id Int32,
metric_name LowCardinality(String),
time_bucket DateTime MATERIALIZED toStartOfHour(timestamp),
@@ -1418,22 +1417,6 @@ CREATE TABLE posthog.metrics2 (
INDEX idx_trace_id_bf trace_id TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_resource_fingerprint resource_fingerprint TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_observed_minmax observed_timestamp TYPE minmax GRANULARITY 1,
- PROJECTION projection_series_minute (SELECT
- team_id,
- metric_name,
- service_name,
- metric_type,
- resource_fingerprint,
- series_fingerprint,
- toStartOfMinute(timestamp) AS minute,
- count() AS sample_count,
- sum(value) AS total_value,
- min(value) AS min_value,
- max(value) AS max_value,
- argMin(value, timestamp) AS first_value,
- argMax(value, timestamp) AS last_value
-GROUP BY
- team_id, metric_name, service_name, metric_type, resource_fingerprint, series_fingerprint, minute),
PROJECTION projection_series_activity (SELECT
team_id,
service_name,
@@ -1477,7 +1460,6 @@ CREATE TABLE posthog.metrics2_input (
_offset UInt64
) ENGINE = Null();
CREATE TABLE posthog.metrics_distributed (
- uuid String,
team_id Int32,
metric_name LowCardinality(String),
time_bucket DateTime MATERIALIZED toStartOfHour(timestamp),
@@ -5168,8 +5150,7 @@ CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_series TO posthog.metr
original_expiry_timestamp
FROM posthog.metrics2_input
WHERE has_labels;
-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metrics TO posthog.metrics2 (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, _partition UInt32, _topic String, _offset UInt64) AS SELECT
- uuid,
+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,
diff --git a/posthog/clickhouse/hcl/sql/prod-eu/logs.sql b/posthog/clickhouse/hcl/sql/prod-eu/logs.sql
index 559aae1ff213..dae7279b0561 100644
--- a/posthog/clickhouse/hcl/sql/prod-eu/logs.sql
+++ b/posthog/clickhouse/hcl/sql/prod-eu/logs.sql
@@ -427,7 +427,6 @@ GROUP BY
team_id, time_bucket, toStartOfMinute(timestamp), service_name, metric_name, metric_type, resource_fingerprint)
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/logs/{shard}/posthog.metrics1', '{replica}') ORDER BY (team_id, time_bucket, service_name, metric_name, resource_fingerprint, timestamp) PARTITION BY toDate(timestamp) SETTINGS index_granularity = 8192, index_granularity_bytes = 104857600, ttl_only_drop_parts = 1;
CREATE TABLE posthog.metrics2 (
- uuid String,
team_id Int32,
metric_name LowCardinality(String),
time_bucket DateTime MATERIALIZED toStartOfHour(timestamp),
@@ -459,22 +458,6 @@ CREATE TABLE posthog.metrics2 (
INDEX idx_trace_id_bf trace_id TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_resource_fingerprint resource_fingerprint TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_observed_minmax observed_timestamp TYPE minmax GRANULARITY 1,
- PROJECTION projection_series_minute (SELECT
- team_id,
- metric_name,
- service_name,
- metric_type,
- resource_fingerprint,
- series_fingerprint,
- toStartOfMinute(timestamp) AS minute,
- count() AS sample_count,
- sum(value) AS total_value,
- min(value) AS min_value,
- max(value) AS max_value,
- argMin(value, timestamp) AS first_value,
- argMax(value, timestamp) AS last_value
-GROUP BY
- team_id, metric_name, service_name, metric_type, resource_fingerprint, series_fingerprint, minute),
PROJECTION projection_series_activity (SELECT
team_id,
service_name,
@@ -518,7 +501,6 @@ CREATE TABLE posthog.metrics2_input (
_offset UInt64
) ENGINE = Null();
CREATE TABLE posthog.metrics_distributed (
- uuid String,
team_id Int32,
metric_name LowCardinality(String),
time_bucket DateTime MATERIALIZED toStartOfHour(timestamp),
@@ -1212,8 +1194,7 @@ CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_series TO posthog.metr
original_expiry_timestamp
FROM posthog.metrics2_input
WHERE has_labels;
-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metrics TO posthog.metrics2 (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, _partition UInt32, _topic String, _offset UInt64) AS SELECT
- uuid,
+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,
diff --git a/posthog/clickhouse/hcl/sql/prod-us/logs.sql b/posthog/clickhouse/hcl/sql/prod-us/logs.sql
index 86d8461ff917..41ebfd664b51 100644
--- a/posthog/clickhouse/hcl/sql/prod-us/logs.sql
+++ b/posthog/clickhouse/hcl/sql/prod-us/logs.sql
@@ -427,7 +427,6 @@ GROUP BY
team_id, time_bucket, toStartOfMinute(timestamp), service_name, metric_name, metric_type, resource_fingerprint)
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/logs/{shard}/posthog.metrics1', '{replica}') ORDER BY (team_id, time_bucket, service_name, metric_name, resource_fingerprint, timestamp) PARTITION BY toDate(timestamp) SETTINGS index_granularity = 8192, index_granularity_bytes = 104857600, ttl_only_drop_parts = 1;
CREATE TABLE posthog.metrics2 (
- uuid String,
team_id Int32,
metric_name LowCardinality(String),
time_bucket DateTime MATERIALIZED toStartOfHour(timestamp),
@@ -459,22 +458,6 @@ CREATE TABLE posthog.metrics2 (
INDEX idx_trace_id_bf trace_id TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_resource_fingerprint resource_fingerprint TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_observed_minmax observed_timestamp TYPE minmax GRANULARITY 1,
- PROJECTION projection_series_minute (SELECT
- team_id,
- metric_name,
- service_name,
- metric_type,
- resource_fingerprint,
- series_fingerprint,
- toStartOfMinute(timestamp) AS minute,
- count() AS sample_count,
- sum(value) AS total_value,
- min(value) AS min_value,
- max(value) AS max_value,
- argMin(value, timestamp) AS first_value,
- argMax(value, timestamp) AS last_value
-GROUP BY
- team_id, metric_name, service_name, metric_type, resource_fingerprint, series_fingerprint, minute),
PROJECTION projection_series_activity (SELECT
team_id,
service_name,
@@ -518,7 +501,6 @@ CREATE TABLE posthog.metrics2_input (
_offset UInt64
) ENGINE = Null();
CREATE TABLE posthog.metrics_distributed (
- uuid String,
team_id Int32,
metric_name LowCardinality(String),
time_bucket DateTime MATERIALIZED toStartOfHour(timestamp),
@@ -1206,8 +1188,7 @@ CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metric_series TO posthog.metr
original_expiry_timestamp
FROM posthog.metrics2_input
WHERE has_labels;
-CREATE MATERIALIZED VIEW posthog.metrics2_input_to_metrics TO posthog.metrics2 (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, _partition UInt32, _topic String, _offset UInt64) AS SELECT
- uuid,
+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,
diff --git a/posthog/clickhouse/metrics/metrics2.py b/posthog/clickhouse/metrics/metrics2.py
index 6bef000f7ec0..26c4dc0daa0e 100644
--- a/posthog/clickhouse/metrics/metrics2.py
+++ b/posthog/clickhouse/metrics/metrics2.py
@@ -107,7 +107,6 @@ def METRICS2_TABLE_SQL() -> str:
return f"""
CREATE TABLE IF NOT EXISTS {_db()}.{METRICS2_TABLE_NAME}
(
- `uuid` String,
`team_id` Int32,
`metric_name` LowCardinality(String),
`time_bucket` DateTime MATERIALIZED toStartOfHour(timestamp),
@@ -139,31 +138,6 @@ CREATE TABLE IF NOT EXISTS {_db()}.{METRICS2_TABLE_NAME}
INDEX idx_trace_id_bf trace_id TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_resource_fingerprint resource_fingerprint TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_observed_minmax observed_timestamp TYPE minmax GRANULARITY 1,
- PROJECTION projection_series_minute
- (
- SELECT
- team_id,
- metric_name,
- service_name,
- metric_type,
- resource_fingerprint,
- series_fingerprint,
- toStartOfMinute(timestamp) AS minute,
- count() AS sample_count,
- sum(value) AS total_value,
- min(value) AS min_value,
- max(value) AS max_value,
- argMin(value, timestamp) AS first_value,
- argMax(value, timestamp) AS last_value
- GROUP BY
- team_id,
- metric_name,
- service_name,
- metric_type,
- resource_fingerprint,
- series_fingerprint,
- minute
- ),
PROJECTION projection_series_activity
(
SELECT
@@ -318,12 +292,9 @@ SETTINGS
"""
-def METRICS2_INPUT_TO_METRICS_MV() -> str:
+def METRICS2_INPUT_TO_METRICS_MV_SELECT() -> str:
db = _db()
- return f"""
-CREATE MATERIALIZED VIEW IF NOT EXISTS {db}.{METRICS2_INPUT_TABLE_NAME}_to_metrics TO {db}.{METRICS2_TABLE_NAME}
-AS SELECT
- uuid,
+ return f"""SELECT
team_id,
metric_name,
series_fingerprint,
@@ -352,6 +323,32 @@ FROM {db}.{METRICS2_INPUT_TABLE_NAME}
"""
+def METRICS2_INPUT_TO_METRICS_MV() -> str:
+ db = _db()
+ return f"""
+CREATE MATERIALIZED VIEW IF NOT EXISTS {db}.{METRICS2_INPUT_TABLE_NAME}_to_metrics TO {db}.{METRICS2_TABLE_NAME}
+AS {METRICS2_INPUT_TO_METRICS_MV_SELECT()}"""
+
+
+def METRICS2_INPUT_TO_METRICS_MV_MODIFY_QUERY() -> str:
+ db = _db()
+ return (
+ f"ALTER TABLE {db}.{METRICS2_INPUT_TABLE_NAME}_to_metrics MODIFY QUERY\n{METRICS2_INPUT_TO_METRICS_MV_SELECT()}"
+ )
+
+
+def METRICS2_DROP_SERIES_MINUTE_PROJECTION_SQL() -> str:
+ return f"ALTER TABLE {_db()}.{METRICS2_TABLE_NAME} DROP PROJECTION IF EXISTS projection_series_minute"
+
+
+def METRICS2_DROP_UUID_COLUMN_SQL() -> str:
+ return f"ALTER TABLE {_db()}.{METRICS2_TABLE_NAME} DROP COLUMN IF EXISTS uuid"
+
+
+def METRICS_DISTRIBUTED_DROP_UUID_COLUMN_SQL() -> str:
+ return f"ALTER TABLE {_db()}.{METRICS_DISTRIBUTED_TABLE_NAME} DROP COLUMN IF EXISTS uuid"
+
+
def METRICS2_INPUT_TO_METRIC_SERIES_MV() -> str:
db = _db()
return f"""
diff --git a/posthog/clickhouse/migrations/0316_metrics2_drop_uuid_and_minute_projection.py b/posthog/clickhouse/migrations/0316_metrics2_drop_uuid_and_minute_projection.py
new file mode 100644
index 000000000000..2fd7185fcf17
--- /dev/null
+++ b/posthog/clickhouse/migrations/0316_metrics2_drop_uuid_and_minute_projection.py
@@ -0,0 +1,41 @@
+from posthog.clickhouse.client.connection import NodeRole
+from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions
+from posthog.clickhouse.metrics.metrics2 import (
+ METRICS2_DROP_SERIES_MINUTE_PROJECTION_SQL,
+ METRICS2_DROP_UUID_COLUMN_SQL,
+ METRICS2_INPUT_TO_METRICS_MV_MODIFY_QUERY,
+ METRICS_DISTRIBUTED_DROP_UUID_COLUMN_SQL,
+)
+
+# The MV must stop writing `uuid` before the column goes. A DROP COLUMN while the MV
+# still selects `uuid` fails every insert from metrics2_input, which stalls the whole
+# kafka_metrics_avro2 consumer, not only metrics2.
+#
+# metrics_distributed reads metrics2, so it must lose `uuid` first. A distributed table
+# that declares a column its remote no longer has fails every read through it.
+operations = [
+ run_sql_with_exceptions(
+ METRICS2_DROP_SERIES_MINUTE_PROJECTION_SQL(),
+ node_roles=[NodeRole.LOGS],
+ sharded=False,
+ is_alter_on_replicated_table=True,
+ ),
+ run_sql_with_exceptions(
+ METRICS2_INPUT_TO_METRICS_MV_MODIFY_QUERY(),
+ node_roles=[NodeRole.LOGS],
+ sharded=False,
+ is_alter_on_replicated_table=False,
+ ),
+ run_sql_with_exceptions(
+ METRICS_DISTRIBUTED_DROP_UUID_COLUMN_SQL(),
+ node_roles=[NodeRole.LOGS],
+ sharded=False,
+ is_alter_on_replicated_table=False,
+ ),
+ run_sql_with_exceptions(
+ METRICS2_DROP_UUID_COLUMN_SQL(),
+ node_roles=[NodeRole.LOGS],
+ sharded=False,
+ is_alter_on_replicated_table=True,
+ ),
+]
diff --git a/posthog/clickhouse/migrations/max_migration.txt b/posthog/clickhouse/migrations/max_migration.txt
index ee68f2c2ca4f..561cee7b9c11 100644
--- a/posthog/clickhouse/migrations/max_migration.txt
+++ b/posthog/clickhouse/migrations/max_migration.txt
@@ -1 +1 @@
-0315_add_snapshot_mode_to_session_replay_events
+0316_metrics2_drop_uuid_and_minute_projection
diff --git a/posthog/clickhouse/test/__snapshots__/test_schema.ambr b/posthog/clickhouse/test/__snapshots__/test_schema.ambr
index 1f02e75ec651..25b75707de4c 100644
--- a/posthog/clickhouse/test/__snapshots__/test_schema.ambr
+++ b/posthog/clickhouse/test/__snapshots__/test_schema.ambr
@@ -4389,7 +4389,6 @@
CREATE TABLE IF NOT EXISTS posthog_test.metrics2
(
- `uuid` String,
`team_id` Int32,
`metric_name` LowCardinality(String),
`time_bucket` DateTime MATERIALIZED toStartOfHour(timestamp),
@@ -4421,31 +4420,6 @@
INDEX idx_trace_id_bf trace_id TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_resource_fingerprint resource_fingerprint TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_observed_minmax observed_timestamp TYPE minmax GRANULARITY 1,
- PROJECTION projection_series_minute
- (
- SELECT
- team_id,
- metric_name,
- service_name,
- metric_type,
- resource_fingerprint,
- series_fingerprint,
- toStartOfMinute(timestamp) AS minute,
- count() AS sample_count,
- sum(value) AS total_value,
- min(value) AS min_value,
- max(value) AS max_value,
- argMin(value, timestamp) AS first_value,
- argMax(value, timestamp) AS last_value
- GROUP BY
- team_id,
- metric_name,
- service_name,
- metric_type,
- resource_fingerprint,
- series_fingerprint,
- minute
- ),
PROJECTION projection_series_activity
(
SELECT
@@ -4592,7 +4566,6 @@
CREATE MATERIALIZED VIEW IF NOT EXISTS posthog_test.metrics2_input_to_metrics TO posthog_test.metrics2
AS SELECT
- uuid,
team_id,
metric_name,
series_fingerprint,
@@ -11433,7 +11406,6 @@
CREATE TABLE IF NOT EXISTS posthog_test.metrics2
(
- `uuid` String,
`team_id` Int32,
`metric_name` LowCardinality(String),
`time_bucket` DateTime MATERIALIZED toStartOfHour(timestamp),
@@ -11465,31 +11437,6 @@
INDEX idx_trace_id_bf trace_id TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_resource_fingerprint resource_fingerprint TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_observed_minmax observed_timestamp TYPE minmax GRANULARITY 1,
- PROJECTION projection_series_minute
- (
- SELECT
- team_id,
- metric_name,
- service_name,
- metric_type,
- resource_fingerprint,
- series_fingerprint,
- toStartOfMinute(timestamp) AS minute,
- count() AS sample_count,
- sum(value) AS total_value,
- min(value) AS min_value,
- max(value) AS max_value,
- argMin(value, timestamp) AS first_value,
- argMax(value, timestamp) AS last_value
- GROUP BY
- team_id,
- metric_name,
- service_name,
- metric_type,
- resource_fingerprint,
- series_fingerprint,
- minute
- ),
PROJECTION projection_series_activity
(
SELECT