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.

chore(clickhouse): codify trace_spans s3_tiered storage policy in hcl (#107005)

Tommy Gilmore6a0ea4f357c8
diff --git a/posthog/clickhouse/hcl/golden/dev/logs.hcl b/posthog/clickhouse/hcl/golden/dev/logs.hcl
index f290b1645f3f..1290b8a93e7c 100644
--- a/posthog/clickhouse/hcl/golden/dev/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/dev/logs.hcl
@@ -2917,6 +2917,7 @@ SQL
index_granularity = "8192"
index_granularity_bytes = "104857600"
map_serialization_version = "with_buckets"
+ storage_policy = "s3_tiered"
ttl_only_drop_parts = "1"
}
column "time_bucket" {
diff --git a/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl b/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl
index cd1f7cd2a790..e84b3bac383c 100644
--- a/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl
@@ -3077,6 +3077,7 @@ SQL
index_granularity = "8192"
index_granularity_bytes = "104857600"
map_serialization_version = "with_buckets"
+ storage_policy = "s3_tiered"
ttl_only_drop_parts = "1"
}
column "time_bucket" {
diff --git a/posthog/clickhouse/hcl/golden/prod-us/logs.hcl b/posthog/clickhouse/hcl/golden/prod-us/logs.hcl
index a8d4e60d7826..fabf61186665 100644
--- a/posthog/clickhouse/hcl/golden/prod-us/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/prod-us/logs.hcl
@@ -3077,6 +3077,7 @@ SQL
index_granularity = "8192"
index_granularity_bytes = "104857600"
map_serialization_version = "with_buckets"
+ storage_policy = "s3_tiered"
ttl_only_drop_parts = "1"
}
column "time_bucket" {
diff --git a/posthog/clickhouse/hcl/roles/logs/dev/patches.hcl b/posthog/clickhouse/hcl/roles/logs/dev/patches.hcl
index ca2c815fa95a..2f2844adc8e6 100644
--- a/posthog/clickhouse/hcl/roles/logs/dev/patches.hcl
+++ b/posthog/clickhouse/hcl/roles/logs/dev/patches.hcl
@@ -38,6 +38,9 @@ database "posthog" {
}
patch_table "trace_spans" {
+ settings = {
+ storage_policy = "s3_tiered"
+ }
projection "projection_aggregate_counts" {
query = <<SQL
SELECT
diff --git a/posthog/clickhouse/hcl/roles/logs/prod/patches.hcl b/posthog/clickhouse/hcl/roles/logs/prod/patches.hcl
index 894ff95923db..a0b867294815 100644
--- a/posthog/clickhouse/hcl/roles/logs/prod/patches.hcl
+++ b/posthog/clickhouse/hcl/roles/logs/prod/patches.hcl
@@ -37,6 +37,9 @@ database "posthog" {
# cut alongside it; local and dev carry the is_root_span cut under the original
# name instead.
patch_table "trace_spans" {
+ settings = {
+ storage_policy = "s3_tiered"
+ }
projection "projection_aggregate_counts" {
query = <<SQL
SELECT
diff --git a/posthog/clickhouse/hcl/sql/dev/logs.sql b/posthog/clickhouse/hcl/sql/dev/logs.sql
index b5270572d056..daa2d054d187 100644
--- a/posthog/clickhouse/hcl/sql/dev/logs.sql
+++ b/posthog/clickhouse/hcl/sql/dev/logs.sql
@@ -820,7 +820,7 @@ GROUP BY
team_id, time_bucket, toStartOfMinute(timestamp), service_name, resource_fingerprint, is_root_span),
PROJECTION projection_index_trace_id (SELECT _part_offset
ORDER BY trace_id)
-) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.trace_spans', '{replica}-{shard}') ORDER BY (team_id, time_bucket, service_name, resource_fingerprint, status_code, name, timestamp) PARTITION BY toDate(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS allow_part_offset_column_in_projections = 1, index_granularity = 8192, index_granularity_bytes = 104857600, map_serialization_version = 'with_buckets', ttl_only_drop_parts = 1;
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.trace_spans', '{replica}-{shard}') ORDER BY (team_id, time_bucket, service_name, resource_fingerprint, status_code, name, timestamp) PARTITION BY toDate(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS allow_part_offset_column_in_projections = 1, index_granularity = 8192, index_granularity_bytes = 104857600, map_serialization_version = 'with_buckets', storage_policy = 's3_tiered', ttl_only_drop_parts = 1;
CREATE TABLE posthog.trace_spans_distributed (
time_bucket DateTime MATERIALIZED toStartOfInterval(timestamp, toIntervalHour(4)),
original_expiry_timestamp DateTime64(6),
diff --git a/posthog/clickhouse/hcl/sql/prod-eu/logs.sql b/posthog/clickhouse/hcl/sql/prod-eu/logs.sql
index 5c7adadd19d8..3721d56c12c1 100644
--- a/posthog/clickhouse/hcl/sql/prod-eu/logs.sql
+++ b/posthog/clickhouse/hcl/sql/prod-eu/logs.sql
@@ -875,7 +875,7 @@ ORDER BY trace_id) WITH SETTINGS (index_granularity = 512),
count() AS event_count
GROUP BY
team_id, time_bucket, toStartOfMinute(timestamp), service_name, is_root_span, resource_fingerprint)
-) ENGINE = ReplicatedMergeTree('/clickhouse/tables/logs/{shard}/posthog.trace_spans', '{replica}') ORDER BY (team_id, time_bucket, service_name, resource_fingerprint, status_code, name, timestamp) PARTITION BY toDate(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS allow_part_offset_column_in_projections = 1, index_granularity = 8192, index_granularity_bytes = 104857600, map_serialization_version = 'with_buckets', ttl_only_drop_parts = 1;
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/logs/{shard}/posthog.trace_spans', '{replica}') ORDER BY (team_id, time_bucket, service_name, resource_fingerprint, status_code, name, timestamp) PARTITION BY toDate(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS allow_part_offset_column_in_projections = 1, index_granularity = 8192, index_granularity_bytes = 104857600, map_serialization_version = 'with_buckets', storage_policy = 's3_tiered', ttl_only_drop_parts = 1;
CREATE TABLE posthog.trace_spans_distributed (
time_bucket DateTime MATERIALIZED toStartOfInterval(timestamp, toIntervalHour(4)),
original_expiry_timestamp DateTime64(6),
diff --git a/posthog/clickhouse/hcl/sql/prod-us/logs.sql b/posthog/clickhouse/hcl/sql/prod-us/logs.sql
index e07f856308b1..6eb61e681359 100644
--- a/posthog/clickhouse/hcl/sql/prod-us/logs.sql
+++ b/posthog/clickhouse/hcl/sql/prod-us/logs.sql
@@ -875,7 +875,7 @@ ORDER BY trace_id) WITH SETTINGS (index_granularity = 512),
count() AS event_count
GROUP BY
team_id, time_bucket, toStartOfMinute(timestamp), service_name, is_root_span, resource_fingerprint)
-) ENGINE = ReplicatedMergeTree('/clickhouse/tables/logs/{shard}/posthog.trace_spans', '{replica}') ORDER BY (team_id, time_bucket, service_name, resource_fingerprint, status_code, name, timestamp) PARTITION BY toDate(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS allow_part_offset_column_in_projections = 1, index_granularity = 8192, index_granularity_bytes = 104857600, map_serialization_version = 'with_buckets', ttl_only_drop_parts = 1;
+) ENGINE = ReplicatedMergeTree('/clickhouse/tables/logs/{shard}/posthog.trace_spans', '{replica}') ORDER BY (team_id, time_bucket, service_name, resource_fingerprint, status_code, name, timestamp) PARTITION BY toDate(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS allow_part_offset_column_in_projections = 1, index_granularity = 8192, index_granularity_bytes = 104857600, map_serialization_version = 'with_buckets', storage_policy = 's3_tiered', ttl_only_drop_parts = 1;
CREATE TABLE posthog.trace_spans_distributed (
time_bucket DateTime MATERIALIZED toStartOfInterval(timestamp, toIntervalHour(4)),
original_expiry_timestamp DateTime64(6),