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): validate cross-cluster HCL proxies via chschema manifest (#69270)

Paweł Szczur74a05e13cf28
diff --git a/.github/workflows/ci-clickhouse-hcl-schema.yml b/.github/workflows/ci-clickhouse-hcl-schema.yml
index 4368da275061..2a6956a76ce8 100644
--- a/.github/workflows/ci-clickhouse-hcl-schema.yml
+++ b/.github/workflows/ci-clickhouse-hcl-schema.yml
@@ -28,21 +28,17 @@ permissions:
packages: read
env:
- # Pin to a concrete chschema build (not :latest) for reproducibility. sha-bf84186
- # has `introspect -exclude` (#79) for the live gate, retains file()/heredoc query
- # refs (#68/#69) so a query authored as file("sql/x.sql") compares equal to its
- # golden and the modifier-aware diff (#59), and fixes the layer-order drop of
- # dictionaries/views (#80). Override via repo variable.
- HCLEXP_IMAGE: ${{ vars.HCLEXP_IMAGE || 'ghcr.io/posthog/chschema:sha-bf84186' }}
+ # Pinned chschema build (not :latest) for reproducibility. Override via repo variable.
+ HCLEXP_IMAGE: ${{ vars.HCLEXP_IMAGE || 'ghcr.io/posthog/chschema:sha-0409212' }}
jobs:
- ops-hcl-guard:
- name: Validate + diff OPS HCL against golden dumps
+ hcl-guard:
+ name: Validate + diff HCL against golden dumps
runs-on: ubuntu-24.04
timeout-minutes: 10
# Informational only while the declarative-HCL pilot stabilizes: the guard
# runs and reports drift, but a failure must not block PRs. Remove once the
- # OPS/LOGS managed set is trusted and we want it enforced.
+ # managed set is trusted and we want it enforced.
continue-on-error: true
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
diff --git a/.github/workflows/ci-clickhouse-multinode-migrations.yml b/.github/workflows/ci-clickhouse-multinode-migrations.yml
index b74a58a7a2b1..43e6697239d9 100644
--- a/.github/workflows/ci-clickhouse-multinode-migrations.yml
+++ b/.github/workflows/ci-clickhouse-multinode-migrations.yml
@@ -57,7 +57,7 @@ jobs:
PRIME_POSTGRES_FROM: schema.sql.gz
# Pinned chschema build used by the live-schema convergence gate
# (verify-live.sh). Keep in sync with posthog/clickhouse/hcl/bin/hclexp.
- HCLEXP_IMAGE: ${{ vars.HCLEXP_IMAGE || 'ghcr.io/posthog/chschema:sha-bf84186' }}
+ HCLEXP_IMAGE: ${{ vars.HCLEXP_IMAGE || 'ghcr.io/posthog/chschema:sha-0409212' }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
diff --git a/posthog/clickhouse/hcl/.gitignore b/posthog/clickhouse/hcl/.gitignore
new file mode 100644
index 000000000000..d57d71faca49
--- /dev/null
+++ b/posthog/clickhouse/hcl/.gitignore
@@ -0,0 +1,2 @@
+# transient manifest render written by check.sh (see render_manifest)
+.hcl-manifest.*
diff --git a/posthog/clickhouse/hcl/README.md b/posthog/clickhouse/hcl/README.md
index 2d9950d66cc4..6d0fc2708dff 100644
--- a/posthog/clickhouse/hcl/README.md
+++ b/posthog/clickhouse/hcl/README.md
@@ -18,6 +18,7 @@ declared once in the manifest — there is no object→roles side-table.
hcl/
bin/hclexp # wrapper: $HCLEXP_BIN local binary, or pinned container image
nodes # composition manifest: (env, role) -> ordered layer list ← placement
+ clusters # cluster_name -> composing roles; rendered into the manifest check.sh feeds `validate -manifest` to resolve cross-cluster proxies
roles/shared/ # objects on every role (query_log_archive path + custom_metrics_* sub-views + ops_query_log_archive_mv)
roles/ops/shared/ # OPS objects on every OPS env
roles/ops/prod/ # OPS objects on both prod envs only (the metrics suite)
@@ -77,9 +78,13 @@ partial/newer schema than the cloud logs nodes, so `local logs` composes a self-
only in the ops nodes → `[OPS]`; one under `roles/logs/` → `[LOGS]`.
Per-node `{shard}` / `{replica}` stay as ClickHouse macros, so replicas collapse to one definition.
-Some objects reference tables outside the composed set by design (custom_metrics → `system`, the
-qla MV → `system.query_log`, distributed proxies → other clusters) and are listed in `SKIP` in
-`check.sh` so `validate` doesn't flag them.
+A cross-cluster Distributed proxy references a table on another cluster's composition; `check.sh`
+renders `nodes` + `clusters` into an HCL manifest and runs `validate -manifest -env <env>`, so those
+remotes resolve against their target cluster (existence + column agreement) rather than being
+skipped. `system.*` remotes are always resolvable. The `posthog` data cluster is `local`-only here
+(prod goldens live in posthog-cloud-infra), so `check.sh` passes it via `-cluster` flags — composed
+for `local`, `@absent` elsewhere. A tiny `known_drift_skip` covers real proxy/storage drift pending
+a fix.
## Making a change (edit HCL → migration)
@@ -92,7 +97,7 @@ HCL=posthog/clickhouse/hcl
$HCL/bin/hclexp -help
# it is equivalent to:
docker run --rm -v "$PWD:/work" -v "${TMPDIR:-/tmp}:${TMPDIR:-/tmp}" -w /work \
- ghcr.io/posthog/chschema:sha-bf84186 -help
+ ghcr.io/posthog/chschema:sha-0409212 -help
```
(For faster local iteration you can build the binary — `go build -o hclexp ./cmd/hclexp` in
diff --git a/posthog/clickhouse/hcl/bin/hclexp b/posthog/clickhouse/hcl/bin/hclexp
index 79cf4644d7dd..a2c0694e13d4 100755
--- a/posthog/clickhouse/hcl/bin/hclexp
+++ b/posthog/clickhouse/hcl/bin/hclexp
@@ -10,13 +10,9 @@
# (`go build -o hclexp ./cmd/hclexp` in the sibling repo) for faster iteration.
set -euo pipefail
-# Pinned to a concrete build (not :latest) for reproducibility. sha-bf84186 has
-# `introspect -exclude` (chschema #79), which the live convergence gate
-# (dump-live.sh) requires; it retains file()/heredoc query refs (#68/#69),
-# structured JSON diff (#66), and the modifier-aware diff (#59), and fixes the
-# layer-order drop of dictionaries/views (#80) and captures the ReplacingMergeTree is_deleted column (#108).
+# Pinned to a concrete build (not :latest) for reproducibility.
# Override via $HCLEXP_IMAGE; bump when intentionally upgrading hclexp.
-HCLEXP_IMAGE="${HCLEXP_IMAGE:-ghcr.io/posthog/chschema:sha-bf84186}"
+HCLEXP_IMAGE="${HCLEXP_IMAGE:-ghcr.io/posthog/chschema:sha-0409212}"
if [[ -n "${HCLEXP_BIN:-}" ]]; then
exec "$HCLEXP_BIN" "$@"
diff --git a/posthog/clickhouse/hcl/check.sh b/posthog/clickhouse/hcl/check.sh
index 0fb35f367ad1..75566e4bdab9 100755
--- a/posthog/clickhouse/hcl/check.sh
+++ b/posthog/clickhouse/hcl/check.sh
@@ -1,15 +1,15 @@
#!/usr/bin/env bash
-# Fidelity + reference guard for the declarative OPS ClickHouse schema.
+# Fidelity + reference guard for the declarative ClickHouse schema.
#
-# Reads the node composition manifest (./nodes) and, for each (env, role):
-# 1. `hclexp validate`s the composed layer stack (cross-object refs resolve),
-# skipping refs that intentionally point outside the composed set (the
-# `system` database, the main events cluster, and the OPS-only data table
-# that the shared distributed tables read from).
-# 2. `hclexp diff`s the stack against golden/<env>-<role>.hcl, asserting zero drift.
-# The golden is the resolved composition (run ops/gen-golden.sh to refresh it), so
-# this catches a stale golden — a layer edited without regenerating. Reality-fidelity
-# (HCL vs the real cluster) is the post-deploy introspection's job, not this guard.
+# Reads the node composition manifest (./nodes) and:
+# 1. `hclexp validate`s every role, once per env, via an HCL manifest rendered
+# from ./nodes + ./clusters (`-manifest`/`-env`). Cross-cluster Distributed
+# proxies resolve against their target cluster's composition, so the remote's
+# existence AND its columns are checked (not blanket-skipped). `system.*`
+# remotes are always resolvable; a short known_drift_skip covers real
+# proxy/storage drift pending a fix.
+# 2. `hclexp diff`s each (env, role) stack against golden/<env>-<role>.hcl,
+# asserting zero drift.
#
# Run from the repo root. Uses ./posthog/clickhouse/hcl/bin/hclexp. Exits non-zero
# on any drift or unexpected validation error.
@@ -19,48 +19,92 @@ HCL=posthog/clickhouse/hcl
HCLEXP="$HCL/bin/hclexp"
GOLDEN="$HCL/golden"
MANIFEST="$HCL/nodes"
+CLUSTERS="$HCL/clusters"
-# Per-role validate skips. A Distributed table whose remote lives on another cluster
-# can't be resolved from a role's own composition — skip validation for exactly those
-# objects, PER ROLE, so one role never masks a proxy that should resolve locally (a
-# global list would, and would grow unbounded). Each list is the minimal set `hclexp
-# validate` flags for that role across all its envs; add to a role only what that role
-# actually proxies cross-cluster. Building blocks:
-# _shared : out-of-band objects roles/shared models — the custom_metrics_* views and
-# ops_query_log_archive_mv, whose sources are system.* / the OPS cluster.
-# _qla : the query_log_archive read proxies over OPS's sharded_query_log_archive.
-_shared='custom_metrics_backups,custom_metrics_dictionaries,custom_metrics_part_counts,custom_metrics_replication_queue,custom_metrics_server_crash,custom_metrics_table_sizes,ops_query_log_archive_mv'
-_qla='query_log_archive,writable_query_log_archive'
-
-skip_for() {
+# Objects cross-cluster validation flags that we intentionally skip — NOT
+# resolution gaps (those resolve via ./clusters). Keyed by env (validate runs per
+# env). Keep shrinking; each entry needs a note explaining why it's here.
+# query_log_archive_old_ops (prod-us): legacy proxy into ops.query_log_archive_old,
+# a retired table already gone from the live prod-us cluster (per the
+# PostHog/clickhouse-schema dump) and intentionally unmanaged on ops (see
+# roles/ops/prod-eu/ops.hcl). The dead proxy still exists on the live node so
+# it stays in the golden; skip until ops drops it from the cluster.
+known_drift_skip() {
case "$1" in
- ops) echo "custom_metrics,${_shared},events_main,events_recent" ;;
- logs) echo "custom_metrics,${_shared},${_qla}" ;;
- ai_events|aux|batch_exports) echo "${_shared},${_qla}" ;;
- sessions) echo "${_shared},${_qla},events,writable_events_recent" ;;
- sessionsv3) echo "${_shared},${_qla},events,query_log_archive_old_ops" ;;
- # DATA is the hub: it hosts Distributed read proxies into every satellite cluster
- # (aux web/marketing preaggregated, ai_events, sessions), none of whose sharded
- # remotes live on the data node.
- data) echo "${_shared},${_qla},ai_events,conversion_goal_attributed_preaggregated,distributed_system_processes,error_tracking_fingerprint_issue_state,experiment_metric_events_preaggregated,hog_invocation_results,ingestion_warnings_v2_distributed,marketing_conversions_preaggregated,marketing_costs_preaggregated,marketing_touchpoints_preaggregated,message_assets,property_values_distributed,session_replay_features,usage_report_events_preagg,web_bot_definition,web_bounces_dimensional_preaggregated,web_goals_preaggregated,web_overview_preaggregated,web_stats_dimensional_preaggregated,web_stats_frustration_preaggregated,web_stats_paths_preaggregated,web_stats_paths_preaggregated_pathkey,web_stats_preaggregated,web_vitals_paths_preaggregated" ;;
- *) echo "" ;;
+ prod-us) echo "query_log_archive_old_ops" ;;
+ *) echo "" ;;
esac
}
+# csv_items CSV -> the comma list as space-separated words (no spaces in values).
+csv_items() { printf '%s' "$1" | tr ',' ' '; }
+
+# emit_hcl_list CSV -> the values as an HCL string list body: "a", "b", "c".
+emit_hcl_list() {
+ local first=1 x
+ for x in $(csv_items "$1"); do
+ [ "$first" = 1 ] && first=0 || printf ', '
+ printf '"%s"' "$x"
+ done
+}
+
+# render_manifest FILE -> the HCL manifest `hclexp validate -manifest` consumes:
+# a role block per role (env -> layer stack, from ./nodes) plus a cluster block per
+# ./clusters cluster (roles it unions + its aliases). Env-independent — `validate
+# -env` selects each role's stack, and a cluster whose roles don't compose in the
+# selected env resolves @absent on its own (chschema #127). `nodes` stays the
+# single source of composition truth; nothing is duplicated in git.
+render_manifest() {
+ local out="$1" cname roles aliases
+ awk '
+ !/^#/ && NF>=3 {
+ role=$2; env=$1; layers="";
+ for (i=3;i<=NF;i++) layers = layers (layers==""?"":", ") "\"" $i "\"";
+ body[role] = body[role] " env \"" env "\" { layers = [" layers "] }\n";
+ if (!(role in seen)) { order[++n]=role; seen[role]=1 }
+ }
+ END { for (i=1;i<=n;i++) printf "role \"%s\" {\n%s}\n", order[i], body[order[i]] }
+ ' "$MANIFEST" > "$out"
+ while read -r cname roles aliases; do
+ [ -n "${cname:-}" ] || continue
+ { printf 'cluster "%s" {\n roles = [' "$cname"; emit_hcl_list "$roles"; printf ']\n'
+ [ -n "${aliases:-}" ] && { printf ' aliases = ['; emit_hcl_list "$aliases"; printf ']\n'; }
+ printf '}\n'
+ } >> "$out"
+ done < <(grep -vE '^[[:space:]]*#|^[[:space:]]*$' "$CLUSTERS")
+}
+
rc=0
+# Write the rendered manifest UNDER the repo dir, not $TMPDIR: bin/hclexp runs
+# hclexp in a container that bind-mounts only $PWD (-> /work), so a /tmp path is
+# invisible inside it. A repo-relative path resolves under -w /work like the
+# golden/layer paths do. chmod it world-readable: the chschema image runs as
+# `nonroot`, but mktemp creates 0600, so the container user couldn't read it.
+manifest_hcl="$(mktemp "$HCL/.hcl-manifest.XXXXXX")"
+trap 'rm -f "$manifest_hcl"' EXIT
+render_manifest "$manifest_hcl"
+chmod 644 "$manifest_hcl"
+
+# 1. Cross-cluster reference + column validation, once per env (validates every
+# role that composes in that env via the manifest). Cross-cluster proxies
+# resolve against ./clusters; a cluster not composed in the env resolves @absent.
+for env in $(awk '!/^#/ && NF>=3 {print $1}' "$MANIFEST" | awk '!seen[$0]++'); do
+ echo "== $env: validate (all roles) =="
+ if ! "$HCLEXP" validate -manifest "$manifest_hcl" -env "$env" -layer-root "$HCL" \
+ -skip-validation "$(known_drift_skip "$env")" >/dev/null; then
+ echo "FAIL: validate $env"; rc=1
+ fi
+done
+
+# 2. Golden drift, per (env, role): the committed golden is the resolved
+# composition; this catches a layer edited without regenerating.
while read -r env role layers; do
[ -z "${env:-}" ] && continue
case "$env" in \#*) continue ;; esac
- # Build comma-separated layer dirs rooted at the ops dir.
stack=""
for l in $layers; do stack="${stack:+$stack,}$HCL/$l"; done
- echo "== $env/$role: validate =="
- if ! "$HCLEXP" validate -layer "$stack" -skip-validation "$(skip_for "$role")" >/dev/null; then
- echo "FAIL: validate $env/$role"; rc=1
- fi
-
golden="$GOLDEN/$env-$role.hcl"
if [ -f "$golden" ]; then
echo "== $env/$role: diff vs golden =="
diff --git a/posthog/clickhouse/hcl/clusters b/posthog/clickhouse/hcl/clusters
new file mode 100644
index 000000000000..023b2ea18fb6
--- /dev/null
+++ b/posthog/clickhouse/hcl/clusters
@@ -0,0 +1,26 @@
+# Stable cluster mapping — rendered into the HCL manifest check.sh feeds
+# `hclexp validate -manifest`, so cross-cluster Distributed proxies resolve
+# against their target cluster's composition (remote existence + column
+# agreement) instead of -skip-validation.
+#
+# Format: <cluster_name> <roles> [<aliases>]
+# <roles> comma-separated node roles whose compositions union into the
+# cluster's schema (resolved per -env from ./nodes). Each must be a
+# role in ./nodes.
+# <aliases> optional comma-separated remote_servers aliases sharing the
+# cluster's schema.
+#
+# Env-independent: `hclexp validate -env <env>` selects each role's stack, and a
+# cluster whose roles aren't composed in that env resolves @absent on its own
+# (chschema #127). So the `posthog` data cluster — modeled here only for `local`,
+# prod goldens in posthog-cloud-infra — is validated for `local` and absent for the
+# cloud envs, from this one declaration, no per-env handling.
+#
+# `system.*` remotes are always resolvable and need no entry.
+
+ops ops
+logs logs
+aux aux
+ai_events ai_events
+batch_exports batch_exports
+posthog data posthog_writable,posthog_primary_replica,posthog_single_shard
diff --git a/posthog/clickhouse/hcl/dump-live.sh b/posthog/clickhouse/hcl/dump-live.sh
index 452f2755576a..b213642c7b0c 100755
--- a/posthog/clickhouse/hcl/dump-live.sh
+++ b/posthog/clickhouse/hcl/dump-live.sh
@@ -44,7 +44,7 @@ ROLES=(
)
# Pin to the same chschema build as bin/hclexp; override via repo variable.
-HCLEXP_IMAGE="${HCLEXP_IMAGE:-ghcr.io/posthog/chschema:sha-bf84186}"
+HCLEXP_IMAGE="${HCLEXP_IMAGE:-ghcr.io/posthog/chschema:sha-0409212}"
# hclexp that can reach ClickHouse on the host's published ports. Prefer a local
# binary; otherwise a container sharing the host network namespace so localhost
diff --git a/posthog/clickhouse/hcl/golden/local-logs.hcl b/posthog/clickhouse/hcl/golden/local-logs.hcl
index 8ecd54aa5065..5411edbb93b1 100644
--- a/posthog/clickhouse/hcl/golden/local-logs.hcl
+++ b/posthog/clickhouse/hcl/golden/local-logs.hcl
@@ -612,6 +612,21 @@ database "posthog" {
type = "minmax"
granularity = 1
}
+ projection "projection_aggregate_counts" {
+ query = <<SQL
+SELECT
+ team_id,
+ time_bucket,
+ toStartOfMinute(timestamp),
+ service_name,
+ severity_text,
+ resource_fingerprint,
+ count() AS event_count
+GROUP BY
+ team_id, time_bucket, toStartOfMinute(timestamp), service_name, severity_text, resource_fingerprint
+SQL
+
+ }
engine "replicated_merge_tree" {
zoo_path = "/clickhouse/tables/noshard/posthog.logs32"
replica_name = "{replica}-{shard}"
@@ -773,6 +788,21 @@ database "posthog" {
type = "minmax"
granularity = 1
}
+ projection "projection_aggregate_counts" {
+ query = <<SQL
+SELECT
+ team_id,
+ time_bucket,
+ toStartOfMinute(timestamp),
+ service_name,
+ severity_text,
+ resource_fingerprint,
+ count() AS event_count
+GROUP BY
+ team_id, time_bucket, toStartOfMinute(timestamp), service_name, severity_text, resource_fingerprint
+SQL
+
+ }
engine "replicated_merge_tree" {
zoo_path = "/clickhouse/tables/noshard/posthog.logs34"
replica_name = "{replica}-{shard}"
diff --git a/posthog/clickhouse/hcl/roles/logs/local/tables.hcl b/posthog/clickhouse/hcl/roles/logs/local/tables.hcl
index 5ea28b2eefdf..2ad7a23c40b9 100644
--- a/posthog/clickhouse/hcl/roles/logs/local/tables.hcl
+++ b/posthog/clickhouse/hcl/roles/logs/local/tables.hcl
@@ -606,6 +606,21 @@ database "posthog" {
type = "minmax"
granularity = 1
}
+ projection "projection_aggregate_counts" {
+ query = <<SQL
+SELECT
+ team_id,
+ time_bucket,
+ toStartOfMinute(timestamp),
+ service_name,
+ severity_text,
+ resource_fingerprint,
+ count() AS event_count
+GROUP BY
+ team_id, time_bucket, toStartOfMinute(timestamp), service_name, severity_text, resource_fingerprint
+SQL
+
+ }
engine "replicated_merge_tree" {
zoo_path = "/clickhouse/tables/noshard/posthog.logs32"
replica_name = "{replica}-{shard}"
@@ -766,6 +781,21 @@ database "posthog" {
type = "minmax"
granularity = 1
}
+ projection "projection_aggregate_counts" {
+ query = <<SQL
+SELECT
+ team_id,
+ time_bucket,
+ toStartOfMinute(timestamp),
+ service_name,
+ severity_text,
+ resource_fingerprint,
+ count() AS event_count
+GROUP BY
+ team_id, time_bucket, toStartOfMinute(timestamp), service_name, severity_text, resource_fingerprint
+SQL
+
+ }
engine "replicated_merge_tree" {
zoo_path = "/clickhouse/tables/noshard/posthog.logs34"
replica_name = "{replica}-{shard}"
diff --git a/posthog/clickhouse/hcl/sql/local-logs.sql b/posthog/clickhouse/hcl/sql/local-logs.sql
index fb8f59c633fc..99381dceed13 100644
--- a/posthog/clickhouse/hcl/sql/local-logs.sql
+++ b/posthog/clickhouse/hcl/sql/local-logs.sql
@@ -113,7 +113,17 @@ CREATE TABLE posthog.logs32 (
INDEX idx_body_ngram3 lower(body) TYPE ngrambf_v1(3, 25000, 2, 0) GRANULARITY 1,
INDEX idx_uuid_bloom uuid TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_observed_minmax observed_timestamp TYPE minmax GRANULARITY 1,
- INDEX idx_timestamp_minmax timestamp TYPE minmax GRANULARITY 1
+ INDEX idx_timestamp_minmax timestamp TYPE minmax GRANULARITY 1,
+ PROJECTION projection_aggregate_counts (SELECT
+ team_id,
+ time_bucket,
+ toStartOfMinute(timestamp),
+ service_name,
+ severity_text,
+ resource_fingerprint,
+ count() AS event_count
+GROUP BY
+ team_id, time_bucket, toStartOfMinute(timestamp), service_name, severity_text, resource_fingerprint)
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.logs32', '{replica}-{shard}') ORDER BY (team_id, time_bucket, service_name, resource_fingerprint, severity_text, timestamp) PARTITION BY toDate(original_expiry_timestamp) SETTINGS add_minmax_index_for_numeric_columns = 1, allow_experimental_reverse_key = 1, allow_remote_fs_zero_copy_replication = 1, index_granularity = 8192, index_granularity_bytes = 104857600, storage_policy = 'default', ttl_only_drop_parts = 1;
CREATE TABLE posthog.logs34 (
time_bucket DateTime MATERIALIZED toStartOfDay(timestamp),
@@ -154,7 +164,17 @@ CREATE TABLE posthog.logs34 (
INDEX idx_body_ngram3 lower(body) TYPE ngrambf_v1(3, 25000, 2, 0) GRANULARITY 1,
INDEX idx_uuid_bloom uuid TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_observed_minmax observed_timestamp TYPE minmax GRANULARITY 1,
- INDEX idx_timestamp_minmax timestamp TYPE minmax GRANULARITY 1
+ INDEX idx_timestamp_minmax timestamp TYPE minmax GRANULARITY 1,
+ PROJECTION projection_aggregate_counts (SELECT
+ team_id,
+ time_bucket,
+ toStartOfMinute(timestamp),
+ service_name,
+ severity_text,
+ resource_fingerprint,
+ count() AS event_count
+GROUP BY
+ team_id, time_bucket, toStartOfMinute(timestamp), service_name, severity_text, resource_fingerprint)
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/noshard/posthog.logs34', '{replica}-{shard}') ORDER BY (team_id, time_bucket, service_name, resource_fingerprint, severity_text, timestamp) PARTITION BY toDate(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS add_minmax_index_for_numeric_columns = 1, allow_experimental_reverse_key = 1, index_granularity = 8192, index_granularity_bytes = 104857600, map_serialization_version = 'with_buckets', ttl_only_drop_parts = 1;
CREATE TABLE posthog.logs_billing_metrics (
team_id Int32,