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): declarative HCL source-of-truth for OPS cluster (#64091)

Paweł Szczur9220c2358e0e
diff --git a/.github/workflows/ci-clickhouse-hcl-schema.yml b/.github/workflows/ci-clickhouse-hcl-schema.yml
new file mode 100644
index 000000000000..3191c0410553
--- /dev/null
+++ b/.github/workflows/ci-clickhouse-hcl-schema.yml
@@ -0,0 +1,55 @@
+name: ClickHouse HCL Schema Guard
+
+# Deterministic, offline guard for the declarative ClickHouse HCL schema
+# (posthog/clickhouse/hcl/). For each environment it validates that cross-object
+# references resolve and that the layered source still reproduces the vendored
+# golden cluster dump with zero drift. No live cluster is contacted.
+
+on:
+ push:
+ branches:
+ - master
+ paths:
+ - 'posthog/clickhouse/hcl/**'
+ - '.github/workflows/ci-clickhouse-hcl-schema.yml'
+ pull_request:
+ paths:
+ - 'posthog/clickhouse/hcl/**'
+ - '.github/workflows/ci-clickhouse-hcl-schema.yml'
+ merge_group:
+ workflow_dispatch:
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}
+
+permissions:
+ contents: read
+ packages: read
+
+env:
+ # Pin to a concrete chschema build (not :latest) for reproducibility. sha-f9490b7
+ # has the modifier-aware diff (chschema #59) so the guard compares ALIAS/
+ # MATERIALIZED/DEFAULT columns. Override via repo variable.
+ HCLEXP_IMAGE: ${{ vars.HCLEXP_IMAGE || 'ghcr.io/posthog/chschema:sha-f9490b7' }}
+
+jobs:
+ ops-hcl-guard:
+ name: Validate + diff OPS HCL against golden dumps
+ runs-on: ubuntu-24.04
+ timeout-minutes: 10
+ steps:
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
+
+ - name: Log in to ghcr.io
+ uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
+ with:
+ registry: ghcr.io
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Pull hclexp image
+ run: docker pull "$HCLEXP_IMAGE"
+
+ - name: OPS schema guard (validate + drift)
+ run: bash posthog/clickhouse/hcl/ops/check.sh
diff --git a/posthog/clickhouse/hcl/README.md b/posthog/clickhouse/hcl/README.md
new file mode 100644
index 000000000000..f66ce6735083
--- /dev/null
+++ b/posthog/clickhouse/hcl/README.md
@@ -0,0 +1,121 @@
+# Declarative ClickHouse schema (HCL)
+
+Source of truth for satellite ClickHouse clusters, managed declaratively with
+[`hclexp`](../../../../python-clickhouse-schema) instead of sequential Python
+migrations. Schemas are written in HCL, layered for multi-environment setups,
+resolved into a flat desired state, and diffed against live clusters (or
+captured dumps) to produce migration DDL.
+
+Currently covers the **OPS** cluster. LOGS is next.
+
+## Layout
+
+```text
+hcl/
+ bin/hclexp # wrapper: local binary or pinned container image
+ ops/
+ base/ops.hcl # query_log_archive data path + ops tables/views (all envs)
+ base/custom_metrics.hcl # custom_metrics Prometheus-style views (all envs)
+ prod/ops.hcl # metrics suite — prod-us + prod-eu only
+ env/
+ local/ops.hcl # local dev — composes base as-is (no local-only objects yet)
+ dev/ops.hcl # prom_metrics experiment (cloud dev only)
+ prod-us/ops.hcl # events distributed proxies, sharded_tophog (tophog_new)
+ prod-eu/ops.hcl # sharded_tophog (tophog) — query_log_archive_old intentionally unmanaged
+ golden/ # vendored per-env cluster dumps — the drift baseline
+ check.sh # validate + diff layers vs golden for every env
+ diff.sh # preview DDL your uncommitted edits produce, per env
+```
+
+`base/` is a single layer directory; `hclexp` loads every `*.hcl` in it, so
+`base/ops.hcl` and `base/custom_metrics.hcl` are always composed together.
+
+Each environment is the ordered composition of layers:
+
+| Environment | Layer stack | Golden |
+| ----------- | ------------------------------- | ------------------------------- |
+| local | `base` + `env/local` | — (created from HCL; see below) |
+| dev | `base` + `env/dev` | `golden/dev-ops.hcl` |
+| prod-us | `base` + `prod` + `env/prod-us` | `golden/prod-us-ops.hcl` |
+| prod-eu | `base` + `prod` + `env/prod-eu` | `golden/prod-eu-ops.hcl` |
+
+`local` composes the same shared `base` as cloud (so `custom_metrics` and the
+`query_log_archive` data path exist locally too); it just has none of the cloud
+env extras. It has no external cluster dump, so `check.sh` validates it but does
+not diff it against a golden — the live round-trip is exercised by the
+local-apply tooling instead.
+
+Per-node `{shard}` / `{replica}` stay as ClickHouse macros, so the 1a/1b (1c/1d)
+replicas of a cluster collapse to a single definition.
+
+## The OPS cluster, in brief
+
+Only `sharded_query_log_archive` (ReplicatedMergeTree, single shard) physically
+lives on OPS. Every node role across the fleet also gets three companion objects
+that reference it — modeled in `base/ops.hcl`:
+
+- `query_log_archive` — Distributed **read** → `ops.sharded_query_log_archive`
+- `writable_query_log_archive` — Distributed **write** → `ops.sharded_query_log_archive`
+- `ops_query_log_archive_mv` — MV reading each node's `system.query_log` and
+ writing through `writable_query_log_archive`.
+
+Some objects reference tables **outside** the OPS schema by design and are
+excluded from `validate` (see `SKIP` in `check.sh`): the `custom_metrics*` views
+read the `system` database, the MV reads `system.query_log`, and
+`events_main` / `events_recent` are Distributed proxies to the main events
+cluster.
+
+## Local apply notes
+
+The `custom_metrics*` views read system tables (`system.part_log`,
+`system.parts`, `system.backup_log`, `system.crash_log`, …). On a fresh local
+ClickHouse some of these are created lazily (e.g. `system.part_log` appears only
+after merge activity), so applying the views may fail with `UNKNOWN_TABLE` until
+those system tables exist. This is an environment dependency, not a schema
+issue; on the real clusters the system tables are always present.
+
+(The earlier `CREATE VIEW` regeneration bug for views with a column list +
+`SELECT *` — [PostHog/chschema#41](https://github.com/PostHog/chschema/issues/41)
+— is fixed in `hclexp`; rebuild or pull the latest before running the tooling.)
+
+## Common commands
+
+Run from the repo root. Point `HCLEXP_BIN` at a built binary for fast local
+iteration; CI uses the container image via the same wrapper.
+
+```bash
+HCLEXP=posthog/clickhouse/hcl/bin/hclexp
+
+# Fidelity + reference guard for every OPS environment (CI entry point)
+bash posthog/clickhouse/hcl/ops/check.sh
+
+# Preview the migration DDL your uncommitted edits would produce, per env
+# (committed = reference, working tree = desired). Optional ref / env args.
+bash posthog/clickhouse/hcl/ops/diff.sh
+
+# Resolve a layer stack to canonical HCL
+$HCLEXP load -layer posthog/clickhouse/hcl/ops/base,posthog/clickhouse/hcl/ops/env/dev -out /tmp/ops-dev.hcl
+
+# Migration DDL to bring a live cluster up to the HCL source of truth
+$HCLEXP diff \
+ -left posthog/clickhouse/hcl/ops/base,posthog/clickhouse/hcl/ops/prod,posthog/clickhouse/hcl/ops/env/prod-us \
+ -right 'clickhouse://user:pass@host:9440/posthog?secure=true' \
+ -sql
+```
+
+`diff -sql` may flag in-place-impossible changes `-- UNSAFE`. Those are review-gated
+and must never be auto-applied to production — `query_log_archive` is a
+fleet-wide, sensitive table.
+
+## Updating the schema
+
+1. Edit the relevant layer file(s).
+2. When prod changes upstream, re-dump the cluster (see the
+ `../../../../python-clickhouse-schema` `dump-cluster` command) and refresh the
+ matching `ops/golden/*-ops.hcl` baseline in the same change.
+3. Run `check.sh` — it must report `no differences` for every environment.
+4. Generate the migration DDL with `diff -sql` and apply it through the normal
+ operational path.
+
+The `golden/*-ops.hcl` files are captured cluster dumps, kept in lockstep with
+the layered source so `check.sh` is a deterministic, offline CI guard.
diff --git a/posthog/clickhouse/hcl/bin/hclexp b/posthog/clickhouse/hcl/bin/hclexp
new file mode 100755
index 000000000000..aafd503f3baa
--- /dev/null
+++ b/posthog/clickhouse/hcl/bin/hclexp
@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+# Wrapper for the `hclexp` declarative ClickHouse schema tool (../python-clickhouse-schema).
+#
+# Resolution order:
+# 1. $HCLEXP_BIN — explicit path to a local hclexp binary
+# 2. `hclexp` on $PATH
+# 3. the pinned container image (CI default)
+#
+# CI uses the container image; locals can point HCLEXP_BIN at a built binary
+# (`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-f9490b7
+# includes the modifier-aware diff fix (chschema #59), required so check.sh
+# compares ALIAS/MATERIALIZED/DEFAULT columns. Override via $HCLEXP_IMAGE; bump
+# when intentionally upgrading hclexp.
+HCLEXP_IMAGE="${HCLEXP_IMAGE:-ghcr.io/posthog/chschema:sha-f9490b7}"
+
+if [[ -n "${HCLEXP_BIN:-}" ]]; then
+ exec "$HCLEXP_BIN" "$@"
+fi
+
+if command -v hclexp >/dev/null 2>&1; then
+ exec hclexp "$@"
+fi
+
+# Mount the repo so layer-dir and dump-file paths resolve inside the container.
+exec docker run --rm -v "$PWD:/work" -w /work "$HCLEXP_IMAGE" "$@"
diff --git a/posthog/clickhouse/hcl/ops/base/custom_metrics.hcl b/posthog/clickhouse/hcl/ops/base/custom_metrics.hcl
new file mode 100644
index 000000000000..a128274903f2
--- /dev/null
+++ b/posthog/clickhouse/hcl/ops/base/custom_metrics.hcl
@@ -0,0 +1,29 @@
+# OPS custom_metrics views — Prometheus-style metric views over system.* (all envs)
+#
+# Declarative source of truth for the OPS ClickHouse cluster.
+database "posthog" {
+ view "custom_metrics" {
+ query = "SELECT * REPLACE(toFloat64(value) AS value) FROM posthog.custom_metrics_test UNION ALL SELECT * REPLACE(toFloat64(value) AS value) FROM posthog.custom_metrics_replication_queue UNION ALL SELECT * REPLACE(toFloat64(value) AS value) FROM posthog.custom_metrics_server_crash UNION ALL SELECT * FROM posthog.custom_metrics_table_sizes UNION ALL SELECT * REPLACE(toFloat64(value) AS value) FROM posthog.custom_metrics_part_counts UNION ALL SELECT * REPLACE(toFloat64(value) AS value) FROM posthog.custom_metrics_dictionaries UNION ALL SELECT 'ClickHouseCustomMetric_S3DiskBytesUsed' AS name, map('instance', hostname(), 'disk', disk_name) AS labels, toFloat64(sum(bytes_on_disk)) AS value, 'Bytes currently used by ClickHouse parts on S3-backed disks on this node' AS help, 'gauge' AS type FROM system.parts WHERE disk_name IN ('s3disk', 'cache') GROUP BY disk_name UNION ALL SELECT 'ClickHouseCustomMetric_MergeFailures15m' AS name, map('instance', hostname()) AS labels, toFloat64(count()) AS value, 'Number of failed merge operations in the last 15 minutes' AS help, 'gauge' AS type FROM system.part_log WHERE (event_time >= (now() - toIntervalMinute(15))) AND (event_type = 'MergeParts') AND (error > 0) AND (merge_reason != 'NotAMerge') AND (error != 40) UNION ALL SELECT 'ClickHouseCustomMetric_MergeRetriesMaxPerTable15m' AS name, map('instance', hostname()) AS labels, toFloat64(max(cnt)) AS value, 'Max failed merge retries for any single table in the last 15 minutes' AS help, 'gauge' AS type FROM (SELECT count() AS cnt FROM system.part_log WHERE (event_time >= (now() - toIntervalMinute(15))) AND (event_type = 'MergeParts') AND (error > 0) AND (merge_reason != 'NotAMerge') AND (error != 40) GROUP BY database, `table`, partition_id)"
+ }
+ view "custom_metrics_backups" {
+ query = "WITH ['ClickHouseCustomMetric_BackupFailed', 'ClickHouseCustomMetric_BackupSuccess', 'ClickHouseCustomMetric_BackupCancelled', 'ClickHouseCustomMetric_BackupAttempts'] AS names, [toInt64(countIf(status = 'BACKUP_FAILED')), toInt64(countIf(status = 'BACKUP_CREATED')), toInt64(countIf(status = 'BACKUP_CANCELLED')), toInt64(countIf(status = 'CREATING_BACKUP'))] AS values, ['Number of failed backups', 'Number of successful backups', 'Number of cancelled backups', 'Number of backup attempts'] AS descriptions, ['gauge', 'gauge', 'gauge', 'gauge'] AS types, arrayJoin(arrayZip(names, values, descriptions, types)) AS tpl SELECT tpl.1 AS name, map('instance', hostname()) AS labels, tpl.2 AS value, tpl.3 AS help, tpl.4 AS type FROM system.backup_log WHERE event_date = today() GROUP BY event_date"
+ }
+ view "custom_metrics_dictionaries" {
+ query = "SELECT 'ClickHouseCustomMetric_DictionariesFailed' AS name, map('instance', hostname(), 'database', d.database, 'dictionary', d.dict_name, 'uuid', toString(d.uuid), 'status', toString(d.status)) AS labels, toUInt64(1) AS value, 'Dictionary is in FAILED or FAILED_AND_RELOADING status' AS help, 'gauge' AS type FROM (SELECT name AS dict_name, database, uuid, status FROM system.dictionaries WHERE status IN ('FAILED', 'FAILED_AND_RELOADING')) AS d"
+ }
+ view "custom_metrics_part_counts" {
+ query = "SELECT 'ClickHouseCustomMetric_MaxPartCountPerPartition' AS name, map('instance', hostname(), 'database', database, 'table', `table`, 'partition', partition) AS labels, part_count AS value, 'Maximum number of active parts for any partition in a PostHog table' AS help, 'gauge' AS type FROM (SELECT database, `table`, partition, count() AS part_count FROM system.parts WHERE active AND (database = 'posthog') GROUP BY database, `table`, partition ORDER BY database ASC, `table` ASC, part_count DESC, partition ASC LIMIT 1 BY database, `table`)"
+ }
+ view "custom_metrics_replication_queue" {
+ query = "WITH ['ClickHouseCustomMetric_ReplicationQueueStuckEntries', 'ClickHouseCustomMetric_ReplicationQueueMaxPostponedEntrySeconds', 'ClickHouseCustomMetric_ReplicationQueueMaxErrorEntrySeconds'] AS names, [toInt64(countIf(create_time < (now() - toIntervalDay(15)))), maxIf(dateDiff('seconds', create_time, last_postpone_time), last_postpone_time != '1970-01-01'), maxIf(dateDiff('seconds', create_time, last_exception_time), (last_exception_time != '1970-01-01') AND (last_exception_time > (now() - toIntervalMinute(5))))] AS values, ['Number of entries that have been in the replication queue for more than 15 days', 'Maximum number of seconds that an entry has been postponed', 'Maximum number of seconds that an entry has been in error'] AS descriptions, ['gauge', 'gauge', 'gauge'] AS types, arrayJoin(arrayZip(names, values, descriptions, types)) AS tpl SELECT tpl.1 AS name, map('table', `table`, 'instance', hostname()) AS labels, tpl.2 AS value, tpl.3 AS help, tpl.4 AS type FROM system.replication_queue GROUP BY `table` HAVING value > 0"
+ }
+ view "custom_metrics_server_crash" {
+ query = "SELECT 'ClickHouseCustomMetric_ServerCrash' AS name, map('instance', hostname()) AS labels, count() AS value, 'Number of server crashes for current date' AS help, 'gauge' AS type FROM system.crash_log WHERE event_date = today() GROUP BY hostname()"
+ }
+ view "custom_metrics_table_sizes" {
+ query = "SELECT 'ClickHouseCustomMetric_TableTotalBytes' AS name, map('instance', hostname(), 'database', database, 'table', `table`) AS labels, CAST(total_bytes, 'Float64') AS value, 'Size of a database table on a given node (need a sum for sharded)' AS help, 'gauge' AS type FROM system.tables WHERE (database NOT IN ('INFORMATION_SCHEMA', 'information_schema')) AND (total_bytes IS NOT NULL)"
+ }
+ view "custom_metrics_test" {
+ query = "SELECT 'ClickHouseCustomMetric_Test' AS name, map('instance', hostname()) AS labels, 1 AS value, 'Test to check that the metric endpoint is working' AS help, 'gauge' AS type"
+ }
+}
diff --git a/posthog/clickhouse/hcl/ops/base/ops.hcl b/posthog/clickhouse/hcl/ops/base/ops.hcl
new file mode 100644
index 000000000000..27ca3ef84248
--- /dev/null
+++ b/posthog/clickhouse/hcl/ops/base/ops.hcl
@@ -0,0 +1,1065 @@
+# OPS base layer — query_log_archive data path + ops-owned tables/views (all envs)
+#
+# Declarative source of truth for the OPS ClickHouse cluster.
+database "posthog" {
+ table "events_team_daily_stats" {
+ order_by = ["analysis_date", "team_id", "event"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "analysis_date" {
+ type = "Date"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "event_count" {
+ type = "UInt64"
+ }
+ column "total_event_bytes" {
+ type = "UInt64"
+ }
+ column "min_event_bytes" {
+ type = "UInt64"
+ }
+ column "max_event_bytes" {
+ type = "UInt64"
+ }
+ column "avg_event_bytes" {
+ type = "Float64"
+ }
+ column "p50_event_bytes" {
+ type = "Float64"
+ }
+ column "p90_event_bytes" {
+ type = "Float64"
+ }
+ column "p95_event_bytes" {
+ type = "Float64"
+ }
+ column "p99_event_bytes" {
+ type = "Float64"
+ }
+ column "event_size_histogram" {
+ type = "Array(Tuple(Float64, Float64, UInt64))"
+ }
+ column "computed_at" {
+ type = "DateTime"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.events_team_daily_stats"
+ replica_name = "{replica}"
+ }
+ }
+ table "query_log_archive" {
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ column "exception_name" {
+ type = "String"
+ alias = "errorCodeToName(exception_code)"
+ }
+ column "ProfileEvents_RealTimeMicroseconds" {
+ type = "Int64"
+ alias = "ProfileEvents['RealTimeMicroseconds']"
+ }
+ column "ProfileEvents_OSCPUVirtualTimeMicroseconds" {
+ type = "Int64"
+ alias = "ProfileEvents['OSCPUVirtualTimeMicroseconds']"
+ }
+ column "ProfileEvents_S3Clients" {
+ type = "Int64"
+ alias = "ProfileEvents['S3Clients']"
+ }
+ column "ProfileEvents_S3DeleteObjects" {
+ type = "Int64"
+ alias = "ProfileEvents['S3DeleteObjects']"
+ }
+ column "ProfileEvents_S3CopyObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CopyObject']"
+ }
+ column "ProfileEvents_S3ListObjects" {
+ type = "Int64"
+ alias = "ProfileEvents['S3ListObjects']"
+ }
+ column "ProfileEvents_S3HeadObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3HeadObject']"
+ }
+ column "ProfileEvents_S3GetObjectAttributes" {
+ type = "Int64"
+ alias = "ProfileEvents['S3GetObjectAttributes']"
+ }
+ column "ProfileEvents_S3CreateMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CreateMultipartUpload']"
+ }
+ column "ProfileEvents_S3UploadPartCopy" {
+ type = "Int64"
+ alias = "ProfileEvents['S3UploadPartCopy']"
+ }
+ column "ProfileEvents_S3UploadPart" {
+ type = "Int64"
+ alias = "ProfileEvents['S3UploadPart']"
+ }
+ column "ProfileEvents_S3AbortMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3AbortMultipartUpload']"
+ }
+ column "ProfileEvents_S3CompleteMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CompleteMultipartUpload']"
+ }
+ column "ProfileEvents_S3PutObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3PutObject']"
+ }
+ column "ProfileEvents_S3GetObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3GetObject']"
+ }
+ column "ProfileEvents_ReadBufferFromS3Bytes" {
+ type = "Int64"
+ alias = "ProfileEvents['ReadBufferFromS3Bytes']"
+ }
+ column "ProfileEvents_WriteBufferFromS3Bytes" {
+ type = "Int64"
+ alias = "ProfileEvents['WriteBufferFromS3Bytes']"
+ }
+ column "lc_workflow" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.workflow"
+ }
+ column "lc_kind" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.kind"
+ }
+ column "lc_id" {
+ type = "String"
+ alias = "CAST(log_comment.id, 'String')"
+ }
+ column "lc_route_id" {
+ type = "String"
+ alias = "CAST(log_comment.route_id, 'String')"
+ }
+ column "lc_access_method" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.access_method"
+ }
+ column "lc_api_key_label" {
+ type = "String"
+ alias = "CAST(log_comment.api_key_label, 'String')"
+ }
+ column "lc_api_key_mask" {
+ type = "String"
+ alias = "CAST(log_comment.api_key_mask, 'String')"
+ }
+ column "lc_query_type" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.query_type"
+ }
+ column "lc_product" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.product"
+ }
+ column "lc_chargeable" {
+ type = "Bool"
+ alias = "log_comment.chargeable"
+ }
+ column "lc_name" {
+ type = "String"
+ alias = "CAST(log_comment.name, 'String')"
+ }
+ column "lc_request_name" {
+ type = "String"
+ alias = "CAST(log_comment.request_name, 'String')"
+ }
+ column "lc_client_query_id" {
+ type = "String"
+ alias = "CAST(log_comment.client_query_id, 'String')"
+ }
+ column "lc_org_id" {
+ type = "String"
+ alias = "CAST(log_comment.org_id, 'String')"
+ }
+ column "lc_user_id" {
+ type = "Int64"
+ alias = "log_comment.user_id"
+ }
+ column "lc_is_impersonated" {
+ type = "Bool"
+ alias = "log_comment.is_impersonated"
+ }
+ column "lc_session_id" {
+ type = "String"
+ alias = "CAST(log_comment.session_id, 'String')"
+ }
+ column "lc_dashboard_id" {
+ type = "Int64"
+ alias = "log_comment.dashboard_id"
+ }
+ column "lc_insight_id" {
+ type = "Int64"
+ alias = "log_comment.insight_id"
+ }
+ column "lc_cohort_id" {
+ type = "Int64"
+ alias = "log_comment.cohort_id"
+ }
+ column "lc_batch_export_id" {
+ type = "String"
+ alias = "CAST(log_comment.batch_export_id, 'String')"
+ }
+ column "lc_experiment_id" {
+ type = "Int64"
+ alias = "log_comment.experiment_id"
+ }
+ column "lc_experiment_feature_flag_key" {
+ type = "String"
+ alias = "CAST(log_comment.experiment_feature_flag_key, 'String')"
+ }
+ column "lc_alert_config_id" {
+ type = "String"
+ alias = "CAST(log_comment.alert_config_id, 'String')"
+ }
+ column "lc_feature" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.feature"
+ }
+ column "lc_table_id" {
+ type = "String"
+ alias = "CAST(log_comment.table_id, 'String')"
+ }
+ column "lc_warehouse_query" {
+ type = "Bool"
+ alias = "log_comment.warehouse_query"
+ }
+ column "lc_person_on_events_mode" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.person_on_events_mode"
+ }
+ column "lc_service_name" {
+ type = "String"
+ alias = "CAST(log_comment.service_name, 'String')"
+ }
+ column "lc_workload" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.workload"
+ }
+ column "lc_query__kind" {
+ type = "LowCardinality(String)"
+ alias = "if(JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'kind'), JSONExtractString(toString(log_comment), 'query', 'kind'))"
+ }
+ column "lc_query__query" {
+ type = "String"
+ alias = "multiIf(NOT is_initial_query, '', JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'query'), JSONExtractString(toString(log_comment), 'query', 'query'))"
+ }
+ column "lc_query" {
+ type = "String"
+ alias = "if(is_initial_query, JSONExtractRaw(toString(log_comment), 'query'), '')"
+ }
+ column "lc_temporal__workflow_namespace" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_namespace`, 'String')"
+ }
+ column "lc_temporal__workflow_type" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_type`, 'String')"
+ }
+ column "lc_temporal__workflow_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_id`, 'String')"
+ }
+ column "lc_temporal__workflow_run_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_run_id`, 'String')"
+ }
+ column "lc_temporal__activity_type" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.activity_type`, 'String')"
+ }
+ column "lc_temporal__activity_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.activity_id`, 'String')"
+ }
+ column "lc_temporal__attempt" {
+ type = "Int64"
+ alias = "log_comment.`temporal.attempt`"
+ }
+ column "lc_dagster__job_name" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.job_name`, 'String')"
+ }
+ column "lc_dagster__run_id" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.run_id`, 'String')"
+ }
+ column "lc_dagster__owner" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.tags.owner`, 'String')"
+ }
+ column "lc_modifiers" {
+ type = "String"
+ alias = "if(is_initial_query, JSONExtractRaw(toString(log_comment), 'modifiers'), '')"
+ }
+ engine "distributed" {
+ cluster_name = "ops"
+ remote_database = "posthog"
+ remote_table = "sharded_query_log_archive"
+ }
+ }
+ table "query_log_archive_buffer" {
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ engine "buffer" {
+ database = "posthog"
+ table = "sharded_query_log_archive"
+ num_layers = 16
+ min_time = 10
+ max_time = 60
+ min_rows = 10000
+ max_rows = 1000000
+ min_bytes = 10000000
+ max_bytes = 100000000
+ }
+ }
+ table "sharded_query_log_archive" {
+ order_by = ["team_id", "event_date", "event_time", "query_id"]
+ partition_by = "toYYYYMM(event_date)"
+ settings = {
+ index_granularity = "8192"
+ object_serialization_version = "v3"
+ object_shared_data_serialization_version = "map_with_buckets"
+ }
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ column "exception_name" {
+ type = "String"
+ alias = "errorCodeToName(exception_code)"
+ }
+ column "ProfileEvents_RealTimeMicroseconds" {
+ type = "Int64"
+ alias = "ProfileEvents['RealTimeMicroseconds']"
+ }
+ column "ProfileEvents_OSCPUVirtualTimeMicroseconds" {
+ type = "Int64"
+ alias = "ProfileEvents['OSCPUVirtualTimeMicroseconds']"
+ }
+ column "ProfileEvents_S3Clients" {
+ type = "Int64"
+ alias = "ProfileEvents['S3Clients']"
+ }
+ column "ProfileEvents_S3DeleteObjects" {
+ type = "Int64"
+ alias = "ProfileEvents['S3DeleteObjects']"
+ }
+ column "ProfileEvents_S3CopyObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CopyObject']"
+ }
+ column "ProfileEvents_S3ListObjects" {
+ type = "Int64"
+ alias = "ProfileEvents['S3ListObjects']"
+ }
+ column "ProfileEvents_S3HeadObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3HeadObject']"
+ }
+ column "ProfileEvents_S3GetObjectAttributes" {
+ type = "Int64"
+ alias = "ProfileEvents['S3GetObjectAttributes']"
+ }
+ column "ProfileEvents_S3CreateMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CreateMultipartUpload']"
+ }
+ column "ProfileEvents_S3UploadPartCopy" {
+ type = "Int64"
+ alias = "ProfileEvents['S3UploadPartCopy']"
+ }
+ column "ProfileEvents_S3UploadPart" {
+ type = "Int64"
+ alias = "ProfileEvents['S3UploadPart']"
+ }
+ column "ProfileEvents_S3AbortMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3AbortMultipartUpload']"
+ }
+ column "ProfileEvents_S3CompleteMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CompleteMultipartUpload']"
+ }
+ column "ProfileEvents_S3PutObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3PutObject']"
+ }
+ column "ProfileEvents_S3GetObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3GetObject']"
+ }
+ column "ProfileEvents_ReadBufferFromS3Bytes" {
+ type = "Int64"
+ alias = "ProfileEvents['ReadBufferFromS3Bytes']"
+ }
+ column "ProfileEvents_WriteBufferFromS3Bytes" {
+ type = "Int64"
+ alias = "ProfileEvents['WriteBufferFromS3Bytes']"
+ }
+ column "lc_workflow" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.workflow"
+ }
+ column "lc_kind" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.kind"
+ }
+ column "lc_id" {
+ type = "String"
+ alias = "CAST(log_comment.id, 'String')"
+ }
+ column "lc_route_id" {
+ type = "String"
+ alias = "CAST(log_comment.route_id, 'String')"
+ }
+ column "lc_access_method" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.access_method"
+ }
+ column "lc_api_key_label" {
+ type = "String"
+ alias = "CAST(log_comment.api_key_label, 'String')"
+ }
+ column "lc_api_key_mask" {
+ type = "String"
+ alias = "CAST(log_comment.api_key_mask, 'String')"
+ }
+ column "lc_query_type" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.query_type"
+ }
+ column "lc_product" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.product"
+ }
+ column "lc_chargeable" {
+ type = "Bool"
+ alias = "log_comment.chargeable"
+ }
+ column "lc_name" {
+ type = "String"
+ alias = "CAST(log_comment.name, 'String')"
+ }
+ column "lc_request_name" {
+ type = "String"
+ alias = "CAST(log_comment.request_name, 'String')"
+ }
+ column "lc_client_query_id" {
+ type = "String"
+ alias = "CAST(log_comment.client_query_id, 'String')"
+ }
+ column "lc_org_id" {
+ type = "String"
+ alias = "CAST(log_comment.org_id, 'String')"
+ }
+ column "lc_user_id" {
+ type = "Int64"
+ alias = "log_comment.user_id"
+ }
+ column "lc_is_impersonated" {
+ type = "Bool"
+ alias = "log_comment.is_impersonated"
+ }
+ column "lc_session_id" {
+ type = "String"
+ alias = "CAST(log_comment.session_id, 'String')"
+ }
+ column "lc_dashboard_id" {
+ type = "Int64"
+ alias = "log_comment.dashboard_id"
+ }
+ column "lc_insight_id" {
+ type = "Int64"
+ alias = "log_comment.insight_id"
+ }
+ column "lc_cohort_id" {
+ type = "Int64"
+ alias = "log_comment.cohort_id"
+ }
+ column "lc_batch_export_id" {
+ type = "String"
+ alias = "CAST(log_comment.batch_export_id, 'String')"
+ }
+ column "lc_experiment_id" {
+ type = "Int64"
+ alias = "log_comment.experiment_id"
+ }
+ column "lc_experiment_feature_flag_key" {
+ type = "String"
+ alias = "CAST(log_comment.experiment_feature_flag_key, 'String')"
+ }
+ column "lc_alert_config_id" {
+ type = "String"
+ alias = "CAST(log_comment.alert_config_id, 'String')"
+ }
+ column "lc_feature" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.feature"
+ }
+ column "lc_table_id" {
+ type = "String"
+ alias = "CAST(log_comment.table_id, 'String')"
+ }
+ column "lc_warehouse_query" {
+ type = "Bool"
+ alias = "log_comment.warehouse_query"
+ }
+ column "lc_person_on_events_mode" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.person_on_events_mode"
+ }
+ column "lc_service_name" {
+ type = "String"
+ alias = "CAST(log_comment.service_name, 'String')"
+ }
+ column "lc_workload" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.workload"
+ }
+ column "lc_query__kind" {
+ type = "LowCardinality(String)"
+ alias = "if(JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'kind'), JSONExtractString(toString(log_comment), 'query', 'kind'))"
+ }
+ column "lc_query__query" {
+ type = "String"
+ alias = "multiIf(NOT is_initial_query, '', JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'query'), JSONExtractString(toString(log_comment), 'query', 'query'))"
+ }
+ column "lc_query" {
+ type = "String"
+ alias = "if(is_initial_query, JSONExtractRaw(toString(log_comment), 'query'), '')"
+ }
+ column "lc_temporal__workflow_namespace" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_namespace`, 'String')"
+ }
+ column "lc_temporal__workflow_type" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_type`, 'String')"
+ }
+ column "lc_temporal__workflow_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_id`, 'String')"
+ }
+ column "lc_temporal__workflow_run_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_run_id`, 'String')"
+ }
+ column "lc_temporal__activity_type" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.activity_type`, 'String')"
+ }
+ column "lc_temporal__activity_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.activity_id`, 'String')"
+ }
+ column "lc_temporal__attempt" {
+ type = "Int64"
+ alias = "log_comment.`temporal.attempt`"
+ }
+ column "lc_dagster__job_name" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.job_name`, 'String')"
+ }
+ column "lc_dagster__run_id" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.run_id`, 'String')"
+ }
+ column "lc_dagster__owner" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.tags.owner`, 'String')"
+ }
+ column "lc_modifiers" {
+ type = "String"
+ alias = "if(is_initial_query, JSONExtractRaw(toString(log_comment), 'modifiers'), '')"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.sharded_query_log_archive"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+ table "writable_query_log_archive" {
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "ops"
+ remote_database = "posthog"
+ remote_table = "query_log_archive_buffer"
+ }
+ }
+ materialized_view "ops_query_log_archive_mv" {
+ to_table = "posthog.writable_query_log_archive"
+ query = "SELECT hostname, user, query_id, initial_query_id, is_initial_query, type, event_date, event_time, event_time_microseconds, query_start_time, query_start_time_microseconds, query_duration_ms, read_rows, read_bytes, written_rows, written_bytes, result_rows, result_bytes, memory_usage, peak_threads_usage, current_database, query, formatted_query, normalized_query_hash, query_kind, exception_code, exception, stack_trace, JSONExtractInt(log_comment, 'team_id') AS team_id, if(isValidJSON(log_comment), log_comment, '{}') AS log_comment, ProfileEvents FROM system.query_log WHERE type != 'QueryStart'"
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "String"
+ }
+ column "ProfileEvents" {
+ type = "Map(LowCardinality(String), UInt64)"
+ }
+ }
+ view "daily_aggregated_query_log_archive" {
+ query = "SELECT event_date AS day, team_id, user, current_database, query_kind, lc_kind, lc_access_method, lc_query_type, lc_product, lc_name, lc_feature, lc_query__kind, lc_api_key_label, count() AS query_count, sum(read_bytes) AS read_bytes, sum(read_rows) AS read_rows, sum(query_duration_ms) AS query_duration_ms, sum(ProfileEvents_OSCPUVirtualTimeMicroseconds) AS cpu_microseconds, countIf(exception_code != 0) AS error_count, countIf(exception_code IN (159, 160, 241)) AS timeout_oom_count FROM posthog.sharded_query_log_archive WHERE is_initial_query AND (event_date < today()) GROUP BY day, team_id, user, current_database, query_kind, lc_kind, lc_access_method, lc_query_type, lc_product, lc_name, lc_feature, lc_query__kind, lc_api_key_label"
+ }
+}
diff --git a/posthog/clickhouse/hcl/ops/check.sh b/posthog/clickhouse/hcl/ops/check.sh
new file mode 100755
index 000000000000..eeea04682eba
--- /dev/null
+++ b/posthog/clickhouse/hcl/ops/check.sh
@@ -0,0 +1,71 @@
+#!/usr/bin/env bash
+# Fidelity + reference guard for the declarative OPS ClickHouse schema.
+#
+# For each environment it:
+# 1. `hclexp validate`s the resolved layer stack (cross-object references resolve),
+# skipping references that intentionally point outside the OPS schema
+# (the `system` database and the main events cluster).
+# 2. `hclexp diff`s the resolved layer stack against the vendored golden dump,
+# asserting zero drift — i.e. the layered source still reproduces the
+# last captured cluster state exactly.
+#
+# Run from the repo root. Uses ./posthog/clickhouse/hcl/bin/hclexp (container or
+# local binary). Exits non-zero on any drift or unexpected validation error.
+set -euo pipefail
+
+HCL=posthog/clickhouse/hcl
+HCLEXP="$HCL/bin/hclexp"
+BASE="$HCL/ops/base"
+PROD="$HCL/ops/prod"
+GOLDEN="$HCL/ops/golden"
+
+# Objects whose source/target tables live outside the OPS schema by design:
+# - custom_metrics* views read from the `system` database
+# - ops_query_log_archive_mv reads from system.query_log
+# - events_main / events_recent are Distributed proxies to the main events cluster
+SKIP='custom_metrics,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,events_main,events_recent'
+
+# env -> layer stack (kept portable for bash 3.2; no associative arrays)
+# Every environment composes the shared base layer (query_log_archive data path
+# + custom_metrics views). `local` adds nothing on top; cloud envs add the
+# metrics suite (prod) and per-env objects.
+stack_for() {
+ case "$1" in
+ local) echo "$BASE,$HCL/ops/env/local" ;;
+ dev) echo "$BASE,$HCL/ops/env/dev" ;;
+ prod-us) echo "$BASE,$PROD,$HCL/ops/env/prod-us" ;;
+ prod-eu) echo "$BASE,$PROD,$HCL/ops/env/prod-eu" ;;
+ esac
+}
+
+# Cloud envs are diffed against a vendored golden dump captured from the live
+# cluster. `local` has no external cluster dump (it is created from this HCL),
+# so it is validated only — the live round-trip is exercised by the local-apply
+# tooling, not this offline guard.
+has_golden() { [[ "$1" != "local" ]]; }
+
+rc=0
+for env in local dev prod-us prod-eu; do
+ layers="$(stack_for "$env")"
+
+ echo "== $env: validate =="
+ if ! "$HCLEXP" validate -layer "$layers" -skip-validation "$SKIP" >/dev/null; then
+ echo "FAIL: validate $env"; rc=1
+ fi
+
+ if has_golden "$env"; then
+ echo "== $env: diff vs golden =="
+ err="$(mktemp)"
+ out="$("$HCLEXP" diff -left "$layers" -right "$GOLDEN/$env-ops.hcl" 2>"$err")"
+ if [[ "$out" != "no differences" ]]; then
+ # On a tool failure (image not pulled, missing golden, bad arg) $out is
+ # empty — surface stderr so "FAIL: drift" is never an empty mystery.
+ echo "FAIL: drift in $env"; echo "$out"; cat "$err"; rc=1
+ else
+ echo "no differences"
+ fi
+ rm -f "$err"
+ fi
+done
+
+exit $rc
diff --git a/posthog/clickhouse/hcl/ops/diff.sh b/posthog/clickhouse/hcl/ops/diff.sh
new file mode 100755
index 000000000000..be4ec1fffa94
--- /dev/null
+++ b/posthog/clickhouse/hcl/ops/diff.sh
@@ -0,0 +1,72 @@
+#!/usr/bin/env bash
+# Preview the migration DDL your uncommitted HCL edits would produce, per env.
+#
+# For each OPS environment it resolves the layer stack twice — at the committed
+# state (left = reference) and at your working tree (right = desired) — and runs
+# hclexp diff -left <committed> -right <working> -sql
+# so the emitted statements are the migration to go committed -> changed.
+#
+# This is review-time companion to check.sh (which guards layers vs golden):
+# check.sh asks "does the source still reproduce the captured cluster?"; this
+# asks "what does my change actually do?". Read-only — never touches a cluster,
+# never applies. UNSAFE (recreate) changes are flagged by hclexp.
+#
+# Usage (from repo root):
+# posthog/clickhouse/hcl/ops/diff.sh # working tree vs HEAD, all envs
+# posthog/clickhouse/hcl/ops/diff.sh prod-us # one env
+# posthog/clickhouse/hcl/ops/diff.sh <ref> # working tree vs an arbitrary ref
+# posthog/clickhouse/hcl/ops/diff.sh <ref> prod-eu # both
+set -euo pipefail
+
+HCL=posthog/clickhouse/hcl
+HCLEXP="$HCL/bin/hclexp"
+BASE="$HCL/ops/base"
+PROD="$HCL/ops/prod"
+
+# env -> layer stack (kept in sync with check.sh; portable for bash 3.2).
+stack_for() {
+ case "$1" in
+ local) echo "$BASE,$HCL/ops/env/local" ;;
+ dev) echo "$BASE,$HCL/ops/env/dev" ;;
+ prod-us) echo "$BASE,$PROD,$HCL/ops/env/prod-us" ;;
+ prod-eu) echo "$BASE,$PROD,$HCL/ops/env/prod-eu" ;;
+ esac
+}
+
+REF="HEAD"
+ENVS="local dev prod-us prod-eu"
+for arg in "$@"; do
+ case "$arg" in
+ local|dev|prod-us|prod-eu) ENVS="$arg" ;;
+ *) REF="$arg" ;;
+ esac
+done
+
+# Short-circuit when nothing under the OPS HCL changed vs the reference.
+if git diff --quiet "$REF" -- "$HCL/ops" 2>/dev/null; then
+ echo "no HCL changes under $HCL/ops (vs $REF)"
+ exit 0
+fi
+
+# Materialize the committed tree so the left side resolves the *reference* layers.
+TMP="$(mktemp -d)"
+trap 'rm -rf "$TMP"' EXIT
+git archive "$REF" "$HCL/ops" | tar -x -C "$TMP"
+
+rc=0
+for env in $ENVS; do
+ working="$(stack_for "$env")"
+ # Same stack, rooted in the committed snapshot.
+ committed="$(stack_for "$env" | sed "s#$HCL/ops#$TMP/$HCL/ops#g")"
+
+ echo "=============================================================="
+ echo "# $env (committed@$REF -> working tree)"
+ echo "=============================================================="
+ if ! "$HCLEXP" diff -left "$committed" -right "$working" -sql; then
+ echo "WARN: hclexp diff failed for $env" >&2
+ rc=1
+ fi
+ echo
+done
+
+exit $rc
diff --git a/posthog/clickhouse/hcl/ops/env/dev/ops.hcl b/posthog/clickhouse/hcl/ops/env/dev/ops.hcl
new file mode 100644
index 000000000000..34766296bd46
--- /dev/null
+++ b/posthog/clickhouse/hcl/ops/env/dev/ops.hcl
@@ -0,0 +1,256 @@
+# OPS dev env layer — prom_metrics experiment (dev only)
+#
+# Generated/maintained as the declarative source of truth for the OPS ClickHouse cluster.
+# Resolve with: hclexp load -layer <base>,<...>
+database "posthog" {
+ table "prom_metrics" {
+ column "id" {
+ type = "UUID"
+ default = "reinterpretAsUUID(sipHash128(metric_name, all_tags))"
+ }
+ column "timestamp" {
+ type = "DateTime64(3)"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "tags" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "all_tags" {
+ type = "Map(String, String)"
+ }
+ column "min_time" {
+ type = "Nullable(DateTime64(3))"
+ }
+ column "max_time" {
+ type = "Nullable(DateTime64(3))"
+ }
+ column "metric_family_name" {
+ type = "String"
+ }
+ column "type" {
+ type = "String"
+ }
+ column "unit" {
+ type = "String"
+ }
+ column "help" {
+ type = "String"
+ }
+ engine "time_series" {
+ samples {
+ target = "posthog.prom_metrics_data"
+ }
+ tags {
+ target = "posthog.prom_metrics_tags"
+ }
+ metrics {
+ target = "posthog.prom_metrics_metrics"
+ }
+ }
+ }
+ table "prom_metrics_data" {
+ order_by = ["id", "timestamp"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "timestamp" {
+ type = "DateTime64(3)"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.prom_metrics/data"
+ replica_name = "{replica}"
+ }
+ }
+ table "prom_metrics_metrics" {
+ order_by = ["metric_family_name"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "metric_family_name" {
+ type = "String"
+ }
+ column "type" {
+ type = "String"
+ }
+ column "unit" {
+ type = "String"
+ }
+ column "help" {
+ type = "String"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.prom_metrics/metrics"
+ replica_name = "{replica}"
+ }
+ }
+ table "prom_metrics_tags" {
+ primary_key = ["metric_name"]
+ order_by = ["metric_name", "id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UUID"
+ default = "reinterpretAsUUID(sipHash128(metric_name, all_tags))"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "tags" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "all_tags" {
+ type = "Map(String, String)"
+ }
+ column "min_time" {
+ type = "SimpleAggregateFunction(min, Nullable(DateTime64(3)))"
+ }
+ column "max_time" {
+ type = "SimpleAggregateFunction(max, Nullable(DateTime64(3)))"
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.prom_metrics/tags"
+ replica_name = "{replica}"
+ }
+ }
+ table "writable_prom_metrics" {
+ column "id" {
+ type = "UUID"
+ default = "reinterpretAsUUID(sipHash128(metric_name, all_tags))"
+ }
+ column "timestamp" {
+ type = "DateTime64(3)"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "tags" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "all_tags" {
+ type = "Map(String, String)"
+ }
+ column "min_time" {
+ type = "Nullable(DateTime64(3))"
+ }
+ column "max_time" {
+ type = "Nullable(DateTime64(3))"
+ }
+ column "metric_family_name" {
+ type = "String"
+ }
+ column "type" {
+ type = "String"
+ }
+ column "unit" {
+ type = "String"
+ }
+ column "help" {
+ type = "String"
+ }
+ engine "time_series" {
+ samples {
+ target = "posthog.writable_prom_metrics_data"
+ }
+ tags {
+ target = "posthog.writable_prom_metrics_tags"
+ }
+ metrics {
+ target = "posthog.writable_prom_metrics_metrics"
+ }
+ }
+ }
+ table "writable_prom_metrics_data" {
+ column "id" {
+ type = "UUID"
+ }
+ column "timestamp" {
+ type = "DateTime64(3)"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ engine "buffer" {
+ database = "posthog"
+ table = "prom_metrics_data"
+ num_layers = 1
+ min_time = 2
+ max_time = 5
+ min_rows = 1
+ max_rows = 1000000
+ min_bytes = 1
+ max_bytes = 100000000
+ }
+ }
+ table "writable_prom_metrics_metrics" {
+ column "metric_family_name" {
+ type = "String"
+ }
+ column "type" {
+ type = "String"
+ }
+ column "unit" {
+ type = "String"
+ }
+ column "help" {
+ type = "String"
+ }
+ engine "buffer" {
+ database = "posthog"
+ table = "prom_metrics_metrics"
+ num_layers = 1
+ min_time = 2
+ max_time = 5
+ min_rows = 1
+ max_rows = 1000000
+ min_bytes = 1
+ max_bytes = 100000000
+ }
+ }
+ table "writable_prom_metrics_tags" {
+ column "id" {
+ type = "UUID"
+ default = "reinterpretAsUUID(sipHash128(metric_name, all_tags))"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "tags" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "all_tags" {
+ type = "Map(String, String)"
+ }
+ column "min_time" {
+ type = "SimpleAggregateFunction(min, Nullable(DateTime64(3)))"
+ }
+ column "max_time" {
+ type = "SimpleAggregateFunction(max, Nullable(DateTime64(3)))"
+ }
+ engine "buffer" {
+ database = "posthog"
+ table = "prom_metrics_tags"
+ num_layers = 1
+ min_time = 2
+ max_time = 5
+ min_rows = 1
+ max_rows = 1000000
+ min_bytes = 1
+ max_bytes = 100000000
+ }
+ }
+}
diff --git a/posthog/clickhouse/hcl/ops/env/local/ops.hcl b/posthog/clickhouse/hcl/ops/env/local/ops.hcl
new file mode 100644
index 000000000000..188814ff74b7
--- /dev/null
+++ b/posthog/clickhouse/hcl/ops/env/local/ops.hcl
@@ -0,0 +1,9 @@
+# OPS local-dev layer.
+#
+# Local dev composes the shared base layer as-is (query_log_archive data path +
+# custom_metrics views). It has none of the cloud env extras (no prom_metrics,
+# metrics suite, tophog, or events distributed proxies), so this layer adds
+# nothing today — it exists as the explicit home for any future local-only
+# override. Resolve local with: -layer .../ops/base,.../ops/env/local
+database "posthog" {
+}
diff --git a/posthog/clickhouse/hcl/ops/env/prod-eu/ops.hcl b/posthog/clickhouse/hcl/ops/env/prod-eu/ops.hcl
new file mode 100644
index 000000000000..f06c2c155774
--- /dev/null
+++ b/posthog/clickhouse/hcl/ops/env/prod-eu/ops.hcl
@@ -0,0 +1,102 @@
+# OPS prod-eu env layer — sharded_tophog (tophog zoo_path)
+#
+# query_log_archive_old (legacy/transitional) is intentionally unmanaged — not
+# authored here and trimmed from the golden, so it is left untouched on the cluster.
+#
+# Generated/maintained as the declarative source of truth for the OPS ClickHouse cluster.
+# Resolve with: hclexp load -layer <base>,<...>
+
+database "posthog" {
+ table "events_main" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "elements_chain" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "person_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "person_properties" {
+ type = "String"
+ }
+ column "group0_properties" {
+ type = "String"
+ }
+ column "group1_properties" {
+ type = "String"
+ }
+ column "group2_properties" {
+ type = "String"
+ }
+ column "group3_properties" {
+ type = "String"
+ }
+ column "group4_properties" {
+ type = "String"
+ }
+ column "group0_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group1_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group2_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group3_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group4_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "person_mode" {
+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+ # Shape inherited from sharded_tophog_base (prod layer); prod-eu writes to the
+ # tophog keeper path.
+ table "sharded_tophog" {
+ extend = "sharded_tophog_base"
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/ops/{shard}/posthog.tophog"
+ replica_name = "{replica}"
+ }
+ }
+}
diff --git a/posthog/clickhouse/hcl/ops/env/prod-us/ops.hcl b/posthog/clickhouse/hcl/ops/env/prod-us/ops.hcl
new file mode 100644
index 000000000000..da659cbd0568
--- /dev/null
+++ b/posthog/clickhouse/hcl/ops/env/prod-us/ops.hcl
@@ -0,0 +1,190 @@
+# OPS prod-us env layer — events distributed proxies, sharded_tophog (tophog_new zoo_path)
+#
+# Generated/maintained as the declarative source of truth for the OPS ClickHouse cluster.
+# Resolve with: hclexp load -layer <base>,<...>
+
+database "posthog" {
+ # prod-us-only experiment: an extra ProfileEvents2 JSON column on the base
+ # sharded_query_log_archive table. Additive patch so the shared base stays
+ # region-agnostic; drop this once the experiment ends or rolls out to prod-eu.
+ patch_table "sharded_query_log_archive" {
+ column "ProfileEvents2" {
+ type = "JSON(max_dynamic_paths=0, OSCPUVirtualTimeMicroseconds UInt64, ReadBufferFromS3Bytes UInt64, RealTimeMicroseconds UInt64, S3AbortMultipartUpload UInt64, S3Clients UInt64, S3CompleteMultipartUpload UInt64, S3CopyObject UInt64, S3CreateMultipartUpload UInt64, S3DeleteObjects UInt64, S3GetObject UInt64, S3GetObjectAttributes UInt64, S3HeadObject UInt64, S3ListObjects UInt64, S3PutObject UInt64, S3UploadPart UInt64, S3UploadPartCopy UInt64, WriteBufferFromS3Bytes UInt64)"
+ }
+ }
+ table "events_main" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "elements_chain" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "person_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "person_properties" {
+ type = "String"
+ }
+ column "group0_properties" {
+ type = "String"
+ }
+ column "group1_properties" {
+ type = "String"
+ }
+ column "group2_properties" {
+ type = "String"
+ }
+ column "group3_properties" {
+ type = "String"
+ }
+ column "group4_properties" {
+ type = "String"
+ }
+ column "group0_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group1_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group2_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group3_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group4_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "person_mode" {
+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+ table "events_recent" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "elements_chain" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "person_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "person_properties" {
+ type = "String"
+ }
+ column "group0_properties" {
+ type = "String"
+ }
+ column "group1_properties" {
+ type = "String"
+ }
+ column "group2_properties" {
+ type = "String"
+ }
+ column "group3_properties" {
+ type = "String"
+ }
+ column "group4_properties" {
+ type = "String"
+ }
+ column "group0_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group1_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group2_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group3_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group4_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "person_mode" {
+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ engine "distributed" {
+ cluster_name = "batch_exports"
+ remote_database = "posthog"
+ remote_table = "sharded_events_recent"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+ # Shape inherited from sharded_tophog_base (prod layer); prod-us writes to the
+ # tophog_new keeper path.
+ table "sharded_tophog" {
+ extend = "sharded_tophog_base"
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/ops/{shard}/posthog.tophog_new"
+ replica_name = "{replica}"
+ }
+ }
+}
diff --git a/posthog/clickhouse/hcl/ops/golden/dev-ops.hcl b/posthog/clickhouse/hcl/ops/golden/dev-ops.hcl
new file mode 100644
index 000000000000..e7e5ff528a7a
--- /dev/null
+++ b/posthog/clickhouse/hcl/ops/golden/dev-ops.hcl
@@ -0,0 +1,1368 @@
+node "dev-us-iad-ch-1a-ops" {
+ macros = {
+ cluster = "ops"
+ hostClusterRole = "ops"
+ hostClusterType = "offline"
+ replica = "a"
+ shard = "1"
+ }
+}
+
+database "posthog" {
+ table "events_team_daily_stats" {
+ order_by = ["analysis_date", "team_id", "event"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "analysis_date" {
+ type = "Date"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "event_count" {
+ type = "UInt64"
+ }
+ column "total_event_bytes" {
+ type = "UInt64"
+ }
+ column "min_event_bytes" {
+ type = "UInt64"
+ }
+ column "max_event_bytes" {
+ type = "UInt64"
+ }
+ column "avg_event_bytes" {
+ type = "Float64"
+ }
+ column "p50_event_bytes" {
+ type = "Float64"
+ }
+ column "p90_event_bytes" {
+ type = "Float64"
+ }
+ column "p95_event_bytes" {
+ type = "Float64"
+ }
+ column "p99_event_bytes" {
+ type = "Float64"
+ }
+ column "event_size_histogram" {
+ type = "Array(Tuple(Float64, Float64, UInt64))"
+ }
+ column "computed_at" {
+ type = "DateTime"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.events_team_daily_stats"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "prom_metrics" {
+ column "id" {
+ type = "UUID"
+ default = "reinterpretAsUUID(sipHash128(metric_name, all_tags))"
+ }
+ column "timestamp" {
+ type = "DateTime64(3)"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "tags" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "all_tags" {
+ type = "Map(String, String)"
+ }
+ column "min_time" {
+ type = "Nullable(DateTime64(3))"
+ }
+ column "max_time" {
+ type = "Nullable(DateTime64(3))"
+ }
+ column "metric_family_name" {
+ type = "String"
+ }
+ column "type" {
+ type = "String"
+ }
+ column "unit" {
+ type = "String"
+ }
+ column "help" {
+ type = "String"
+ }
+ engine "time_series" {
+ samples {
+ target = "posthog.prom_metrics_data"
+ }
+ tags {
+ target = "posthog.prom_metrics_tags"
+ }
+ metrics {
+ target = "posthog.prom_metrics_metrics"
+ }
+ }
+ }
+
+ table "prom_metrics_data" {
+ order_by = ["id", "timestamp"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UUID"
+ }
+ column "timestamp" {
+ type = "DateTime64(3)"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.prom_metrics/data"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "prom_metrics_metrics" {
+ order_by = ["metric_family_name"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "metric_family_name" {
+ type = "String"
+ }
+ column "type" {
+ type = "String"
+ }
+ column "unit" {
+ type = "String"
+ }
+ column "help" {
+ type = "String"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.prom_metrics/metrics"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "prom_metrics_tags" {
+ primary_key = ["metric_name"]
+ order_by = ["metric_name", "id"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "id" {
+ type = "UUID"
+ default = "reinterpretAsUUID(sipHash128(metric_name, all_tags))"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "tags" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "all_tags" {
+ type = "Map(String, String)"
+ }
+ column "min_time" {
+ type = "SimpleAggregateFunction(min, Nullable(DateTime64(3)))"
+ }
+ column "max_time" {
+ type = "SimpleAggregateFunction(max, Nullable(DateTime64(3)))"
+ }
+ engine "replicated_aggregating_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.prom_metrics/tags"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "query_log_archive" {
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ column "exception_name" {
+ type = "String"
+ alias = "errorCodeToName(exception_code)"
+ }
+ column "ProfileEvents_RealTimeMicroseconds" {
+ type = "Int64"
+ alias = "ProfileEvents['RealTimeMicroseconds']"
+ }
+ column "ProfileEvents_OSCPUVirtualTimeMicroseconds" {
+ type = "Int64"
+ alias = "ProfileEvents['OSCPUVirtualTimeMicroseconds']"
+ }
+ column "ProfileEvents_S3Clients" {
+ type = "Int64"
+ alias = "ProfileEvents['S3Clients']"
+ }
+ column "ProfileEvents_S3DeleteObjects" {
+ type = "Int64"
+ alias = "ProfileEvents['S3DeleteObjects']"
+ }
+ column "ProfileEvents_S3CopyObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CopyObject']"
+ }
+ column "ProfileEvents_S3ListObjects" {
+ type = "Int64"
+ alias = "ProfileEvents['S3ListObjects']"
+ }
+ column "ProfileEvents_S3HeadObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3HeadObject']"
+ }
+ column "ProfileEvents_S3GetObjectAttributes" {
+ type = "Int64"
+ alias = "ProfileEvents['S3GetObjectAttributes']"
+ }
+ column "ProfileEvents_S3CreateMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CreateMultipartUpload']"
+ }
+ column "ProfileEvents_S3UploadPartCopy" {
+ type = "Int64"
+ alias = "ProfileEvents['S3UploadPartCopy']"
+ }
+ column "ProfileEvents_S3UploadPart" {
+ type = "Int64"
+ alias = "ProfileEvents['S3UploadPart']"
+ }
+ column "ProfileEvents_S3AbortMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3AbortMultipartUpload']"
+ }
+ column "ProfileEvents_S3CompleteMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CompleteMultipartUpload']"
+ }
+ column "ProfileEvents_S3PutObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3PutObject']"
+ }
+ column "ProfileEvents_S3GetObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3GetObject']"
+ }
+ column "ProfileEvents_ReadBufferFromS3Bytes" {
+ type = "Int64"
+ alias = "ProfileEvents['ReadBufferFromS3Bytes']"
+ }
+ column "ProfileEvents_WriteBufferFromS3Bytes" {
+ type = "Int64"
+ alias = "ProfileEvents['WriteBufferFromS3Bytes']"
+ }
+ column "lc_workflow" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.workflow"
+ }
+ column "lc_kind" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.kind"
+ }
+ column "lc_id" {
+ type = "String"
+ alias = "CAST(log_comment.id, 'String')"
+ }
+ column "lc_route_id" {
+ type = "String"
+ alias = "CAST(log_comment.route_id, 'String')"
+ }
+ column "lc_access_method" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.access_method"
+ }
+ column "lc_api_key_label" {
+ type = "String"
+ alias = "CAST(log_comment.api_key_label, 'String')"
+ }
+ column "lc_api_key_mask" {
+ type = "String"
+ alias = "CAST(log_comment.api_key_mask, 'String')"
+ }
+ column "lc_query_type" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.query_type"
+ }
+ column "lc_product" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.product"
+ }
+ column "lc_chargeable" {
+ type = "Bool"
+ alias = "log_comment.chargeable"
+ }
+ column "lc_name" {
+ type = "String"
+ alias = "CAST(log_comment.name, 'String')"
+ }
+ column "lc_request_name" {
+ type = "String"
+ alias = "CAST(log_comment.request_name, 'String')"
+ }
+ column "lc_client_query_id" {
+ type = "String"
+ alias = "CAST(log_comment.client_query_id, 'String')"
+ }
+ column "lc_org_id" {
+ type = "String"
+ alias = "CAST(log_comment.org_id, 'String')"
+ }
+ column "lc_user_id" {
+ type = "Int64"
+ alias = "log_comment.user_id"
+ }
+ column "lc_is_impersonated" {
+ type = "Bool"
+ alias = "log_comment.is_impersonated"
+ }
+ column "lc_session_id" {
+ type = "String"
+ alias = "CAST(log_comment.session_id, 'String')"
+ }
+ column "lc_dashboard_id" {
+ type = "Int64"
+ alias = "log_comment.dashboard_id"
+ }
+ column "lc_insight_id" {
+ type = "Int64"
+ alias = "log_comment.insight_id"
+ }
+ column "lc_cohort_id" {
+ type = "Int64"
+ alias = "log_comment.cohort_id"
+ }
+ column "lc_batch_export_id" {
+ type = "String"
+ alias = "CAST(log_comment.batch_export_id, 'String')"
+ }
+ column "lc_experiment_id" {
+ type = "Int64"
+ alias = "log_comment.experiment_id"
+ }
+ column "lc_experiment_feature_flag_key" {
+ type = "String"
+ alias = "CAST(log_comment.experiment_feature_flag_key, 'String')"
+ }
+ column "lc_alert_config_id" {
+ type = "String"
+ alias = "CAST(log_comment.alert_config_id, 'String')"
+ }
+ column "lc_feature" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.feature"
+ }
+ column "lc_table_id" {
+ type = "String"
+ alias = "CAST(log_comment.table_id, 'String')"
+ }
+ column "lc_warehouse_query" {
+ type = "Bool"
+ alias = "log_comment.warehouse_query"
+ }
+ column "lc_person_on_events_mode" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.person_on_events_mode"
+ }
+ column "lc_service_name" {
+ type = "String"
+ alias = "CAST(log_comment.service_name, 'String')"
+ }
+ column "lc_workload" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.workload"
+ }
+ column "lc_query__kind" {
+ type = "LowCardinality(String)"
+ alias = "if(JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'kind'), JSONExtractString(toString(log_comment), 'query', 'kind'))"
+ }
+ column "lc_query__query" {
+ type = "String"
+ alias = "multiIf(NOT is_initial_query, '', JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'query'), JSONExtractString(toString(log_comment), 'query', 'query'))"
+ }
+ column "lc_query" {
+ type = "String"
+ alias = "if(is_initial_query, JSONExtractRaw(toString(log_comment), 'query'), '')"
+ }
+ column "lc_temporal__workflow_namespace" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_namespace`, 'String')"
+ }
+ column "lc_temporal__workflow_type" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_type`, 'String')"
+ }
+ column "lc_temporal__workflow_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_id`, 'String')"
+ }
+ column "lc_temporal__workflow_run_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_run_id`, 'String')"
+ }
+ column "lc_temporal__activity_type" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.activity_type`, 'String')"
+ }
+ column "lc_temporal__activity_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.activity_id`, 'String')"
+ }
+ column "lc_temporal__attempt" {
+ type = "Int64"
+ alias = "log_comment.`temporal.attempt`"
+ }
+ column "lc_dagster__job_name" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.job_name`, 'String')"
+ }
+ column "lc_dagster__run_id" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.run_id`, 'String')"
+ }
+ column "lc_dagster__owner" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.tags.owner`, 'String')"
+ }
+ column "lc_modifiers" {
+ type = "String"
+ alias = "if(is_initial_query, JSONExtractRaw(toString(log_comment), 'modifiers'), '')"
+ }
+ engine "distributed" {
+ cluster_name = "ops"
+ remote_database = "posthog"
+ remote_table = "sharded_query_log_archive"
+ }
+ }
+
+ table "query_log_archive_buffer" {
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ engine "buffer" {
+ database = "posthog"
+ table = "sharded_query_log_archive"
+ num_layers = 16
+ min_time = 10
+ max_time = 60
+ min_rows = 10000
+ max_rows = 1000000
+ min_bytes = 10000000
+ max_bytes = 100000000
+ }
+ }
+
+ table "sharded_query_log_archive" {
+ order_by = ["team_id", "event_date", "event_time", "query_id"]
+ partition_by = "toYYYYMM(event_date)"
+ settings = {
+ index_granularity = "8192"
+ object_serialization_version = "v3"
+ object_shared_data_serialization_version = "map_with_buckets"
+ }
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ column "exception_name" {
+ type = "String"
+ alias = "errorCodeToName(exception_code)"
+ }
+ column "ProfileEvents_RealTimeMicroseconds" {
+ type = "Int64"
+ alias = "ProfileEvents['RealTimeMicroseconds']"
+ }
+ column "ProfileEvents_OSCPUVirtualTimeMicroseconds" {
+ type = "Int64"
+ alias = "ProfileEvents['OSCPUVirtualTimeMicroseconds']"
+ }
+ column "ProfileEvents_S3Clients" {
+ type = "Int64"
+ alias = "ProfileEvents['S3Clients']"
+ }
+ column "ProfileEvents_S3DeleteObjects" {
+ type = "Int64"
+ alias = "ProfileEvents['S3DeleteObjects']"
+ }
+ column "ProfileEvents_S3CopyObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CopyObject']"
+ }
+ column "ProfileEvents_S3ListObjects" {
+ type = "Int64"
+ alias = "ProfileEvents['S3ListObjects']"
+ }
+ column "ProfileEvents_S3HeadObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3HeadObject']"
+ }
+ column "ProfileEvents_S3GetObjectAttributes" {
+ type = "Int64"
+ alias = "ProfileEvents['S3GetObjectAttributes']"
+ }
+ column "ProfileEvents_S3CreateMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CreateMultipartUpload']"
+ }
+ column "ProfileEvents_S3UploadPartCopy" {
+ type = "Int64"
+ alias = "ProfileEvents['S3UploadPartCopy']"
+ }
+ column "ProfileEvents_S3UploadPart" {
+ type = "Int64"
+ alias = "ProfileEvents['S3UploadPart']"
+ }
+ column "ProfileEvents_S3AbortMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3AbortMultipartUpload']"
+ }
+ column "ProfileEvents_S3CompleteMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CompleteMultipartUpload']"
+ }
+ column "ProfileEvents_S3PutObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3PutObject']"
+ }
+ column "ProfileEvents_S3GetObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3GetObject']"
+ }
+ column "ProfileEvents_ReadBufferFromS3Bytes" {
+ type = "Int64"
+ alias = "ProfileEvents['ReadBufferFromS3Bytes']"
+ }
+ column "ProfileEvents_WriteBufferFromS3Bytes" {
+ type = "Int64"
+ alias = "ProfileEvents['WriteBufferFromS3Bytes']"
+ }
+ column "lc_workflow" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.workflow"
+ }
+ column "lc_kind" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.kind"
+ }
+ column "lc_id" {
+ type = "String"
+ alias = "CAST(log_comment.id, 'String')"
+ }
+ column "lc_route_id" {
+ type = "String"
+ alias = "CAST(log_comment.route_id, 'String')"
+ }
+ column "lc_access_method" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.access_method"
+ }
+ column "lc_api_key_label" {
+ type = "String"
+ alias = "CAST(log_comment.api_key_label, 'String')"
+ }
+ column "lc_api_key_mask" {
+ type = "String"
+ alias = "CAST(log_comment.api_key_mask, 'String')"
+ }
+ column "lc_query_type" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.query_type"
+ }
+ column "lc_product" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.product"
+ }
+ column "lc_chargeable" {
+ type = "Bool"
+ alias = "log_comment.chargeable"
+ }
+ column "lc_name" {
+ type = "String"
+ alias = "CAST(log_comment.name, 'String')"
+ }
+ column "lc_request_name" {
+ type = "String"
+ alias = "CAST(log_comment.request_name, 'String')"
+ }
+ column "lc_client_query_id" {
+ type = "String"
+ alias = "CAST(log_comment.client_query_id, 'String')"
+ }
+ column "lc_org_id" {
+ type = "String"
+ alias = "CAST(log_comment.org_id, 'String')"
+ }
+ column "lc_user_id" {
+ type = "Int64"
+ alias = "log_comment.user_id"
+ }
+ column "lc_is_impersonated" {
+ type = "Bool"
+ alias = "log_comment.is_impersonated"
+ }
+ column "lc_session_id" {
+ type = "String"
+ alias = "CAST(log_comment.session_id, 'String')"
+ }
+ column "lc_dashboard_id" {
+ type = "Int64"
+ alias = "log_comment.dashboard_id"
+ }
+ column "lc_insight_id" {
+ type = "Int64"
+ alias = "log_comment.insight_id"
+ }
+ column "lc_cohort_id" {
+ type = "Int64"
+ alias = "log_comment.cohort_id"
+ }
+ column "lc_batch_export_id" {
+ type = "String"
+ alias = "CAST(log_comment.batch_export_id, 'String')"
+ }
+ column "lc_experiment_id" {
+ type = "Int64"
+ alias = "log_comment.experiment_id"
+ }
+ column "lc_experiment_feature_flag_key" {
+ type = "String"
+ alias = "CAST(log_comment.experiment_feature_flag_key, 'String')"
+ }
+ column "lc_alert_config_id" {
+ type = "String"
+ alias = "CAST(log_comment.alert_config_id, 'String')"
+ }
+ column "lc_feature" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.feature"
+ }
+ column "lc_table_id" {
+ type = "String"
+ alias = "CAST(log_comment.table_id, 'String')"
+ }
+ column "lc_warehouse_query" {
+ type = "Bool"
+ alias = "log_comment.warehouse_query"
+ }
+ column "lc_person_on_events_mode" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.person_on_events_mode"
+ }
+ column "lc_service_name" {
+ type = "String"
+ alias = "CAST(log_comment.service_name, 'String')"
+ }
+ column "lc_workload" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.workload"
+ }
+ column "lc_query__kind" {
+ type = "LowCardinality(String)"
+ alias = "if(JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'kind'), JSONExtractString(toString(log_comment), 'query', 'kind'))"
+ }
+ column "lc_query__query" {
+ type = "String"
+ alias = "multiIf(NOT is_initial_query, '', JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'query'), JSONExtractString(toString(log_comment), 'query', 'query'))"
+ }
+ column "lc_query" {
+ type = "String"
+ alias = "if(is_initial_query, JSONExtractRaw(toString(log_comment), 'query'), '')"
+ }
+ column "lc_temporal__workflow_namespace" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_namespace`, 'String')"
+ }
+ column "lc_temporal__workflow_type" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_type`, 'String')"
+ }
+ column "lc_temporal__workflow_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_id`, 'String')"
+ }
+ column "lc_temporal__workflow_run_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_run_id`, 'String')"
+ }
+ column "lc_temporal__activity_type" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.activity_type`, 'String')"
+ }
+ column "lc_temporal__activity_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.activity_id`, 'String')"
+ }
+ column "lc_temporal__attempt" {
+ type = "Int64"
+ alias = "log_comment.`temporal.attempt`"
+ }
+ column "lc_dagster__job_name" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.job_name`, 'String')"
+ }
+ column "lc_dagster__run_id" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.run_id`, 'String')"
+ }
+ column "lc_dagster__owner" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.tags.owner`, 'String')"
+ }
+ column "lc_modifiers" {
+ type = "String"
+ alias = "if(is_initial_query, JSONExtractRaw(toString(log_comment), 'modifiers'), '')"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.sharded_query_log_archive"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "writable_prom_metrics" {
+ column "id" {
+ type = "UUID"
+ default = "reinterpretAsUUID(sipHash128(metric_name, all_tags))"
+ }
+ column "timestamp" {
+ type = "DateTime64(3)"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "tags" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "all_tags" {
+ type = "Map(String, String)"
+ }
+ column "min_time" {
+ type = "Nullable(DateTime64(3))"
+ }
+ column "max_time" {
+ type = "Nullable(DateTime64(3))"
+ }
+ column "metric_family_name" {
+ type = "String"
+ }
+ column "type" {
+ type = "String"
+ }
+ column "unit" {
+ type = "String"
+ }
+ column "help" {
+ type = "String"
+ }
+ engine "time_series" {
+ samples {
+ target = "posthog.writable_prom_metrics_data"
+ }
+ tags {
+ target = "posthog.writable_prom_metrics_tags"
+ }
+ metrics {
+ target = "posthog.writable_prom_metrics_metrics"
+ }
+ }
+ }
+
+ table "writable_prom_metrics_data" {
+ column "id" {
+ type = "UUID"
+ }
+ column "timestamp" {
+ type = "DateTime64(3)"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ engine "buffer" {
+ database = "posthog"
+ table = "prom_metrics_data"
+ num_layers = 1
+ min_time = 2
+ max_time = 5
+ min_rows = 1
+ max_rows = 1000000
+ min_bytes = 1
+ max_bytes = 100000000
+ }
+ }
+
+ table "writable_prom_metrics_metrics" {
+ column "metric_family_name" {
+ type = "String"
+ }
+ column "type" {
+ type = "String"
+ }
+ column "unit" {
+ type = "String"
+ }
+ column "help" {
+ type = "String"
+ }
+ engine "buffer" {
+ database = "posthog"
+ table = "prom_metrics_metrics"
+ num_layers = 1
+ min_time = 2
+ max_time = 5
+ min_rows = 1
+ max_rows = 1000000
+ min_bytes = 1
+ max_bytes = 100000000
+ }
+ }
+
+ table "writable_prom_metrics_tags" {
+ column "id" {
+ type = "UUID"
+ default = "reinterpretAsUUID(sipHash128(metric_name, all_tags))"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "tags" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "all_tags" {
+ type = "Map(String, String)"
+ }
+ column "min_time" {
+ type = "SimpleAggregateFunction(min, Nullable(DateTime64(3)))"
+ }
+ column "max_time" {
+ type = "SimpleAggregateFunction(max, Nullable(DateTime64(3)))"
+ }
+ engine "buffer" {
+ database = "posthog"
+ table = "prom_metrics_tags"
+ num_layers = 1
+ min_time = 2
+ max_time = 5
+ min_rows = 1
+ max_rows = 1000000
+ min_bytes = 1
+ max_bytes = 100000000
+ }
+ }
+
+ table "writable_query_log_archive" {
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "ops"
+ remote_database = "posthog"
+ remote_table = "query_log_archive_buffer"
+ }
+ }
+
+ materialized_view "ops_query_log_archive_mv" {
+ to_table = "posthog.writable_query_log_archive"
+ query = "SELECT hostname, user, query_id, initial_query_id, is_initial_query, type, event_date, event_time, event_time_microseconds, query_start_time, query_start_time_microseconds, query_duration_ms, read_rows, read_bytes, written_rows, written_bytes, result_rows, result_bytes, memory_usage, peak_threads_usage, current_database, query, formatted_query, normalized_query_hash, query_kind, exception_code, exception, stack_trace, JSONExtractInt(log_comment, 'team_id') AS team_id, if(isValidJSON(log_comment), log_comment, '{}') AS log_comment, ProfileEvents FROM system.query_log WHERE type != 'QueryStart'"
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "String"
+ }
+ column "ProfileEvents" {
+ type = "Map(LowCardinality(String), UInt64)"
+ }
+ }
+
+ view "custom_metrics" {
+ query = "SELECT * REPLACE(toFloat64(value) AS value) FROM posthog.custom_metrics_test UNION ALL SELECT * REPLACE(toFloat64(value) AS value) FROM posthog.custom_metrics_replication_queue UNION ALL SELECT * REPLACE(toFloat64(value) AS value) FROM posthog.custom_metrics_server_crash UNION ALL SELECT * FROM posthog.custom_metrics_table_sizes UNION ALL SELECT * REPLACE(toFloat64(value) AS value) FROM posthog.custom_metrics_part_counts UNION ALL SELECT * REPLACE(toFloat64(value) AS value) FROM posthog.custom_metrics_dictionaries UNION ALL SELECT 'ClickHouseCustomMetric_S3DiskBytesUsed' AS name, map('instance', hostname(), 'disk', disk_name) AS labels, toFloat64(sum(bytes_on_disk)) AS value, 'Bytes currently used by ClickHouse parts on S3-backed disks on this node' AS help, 'gauge' AS type FROM system.parts WHERE disk_name IN ('s3disk', 'cache') GROUP BY disk_name UNION ALL SELECT 'ClickHouseCustomMetric_MergeFailures15m' AS name, map('instance', hostname()) AS labels, toFloat64(count()) AS value, 'Number of failed merge operations in the last 15 minutes' AS help, 'gauge' AS type FROM system.part_log WHERE (event_time >= (now() - toIntervalMinute(15))) AND (event_type = 'MergeParts') AND (error > 0) AND (merge_reason != 'NotAMerge') AND (error != 40) UNION ALL SELECT 'ClickHouseCustomMetric_MergeRetriesMaxPerTable15m' AS name, map('instance', hostname()) AS labels, toFloat64(max(cnt)) AS value, 'Max failed merge retries for any single table in the last 15 minutes' AS help, 'gauge' AS type FROM (SELECT count() AS cnt FROM system.part_log WHERE (event_time >= (now() - toIntervalMinute(15))) AND (event_type = 'MergeParts') AND (error > 0) AND (merge_reason != 'NotAMerge') AND (error != 40) GROUP BY database, `table`, partition_id)"
+ }
+
+ view "custom_metrics_backups" {
+ query = "WITH ['ClickHouseCustomMetric_BackupFailed', 'ClickHouseCustomMetric_BackupSuccess', 'ClickHouseCustomMetric_BackupCancelled', 'ClickHouseCustomMetric_BackupAttempts'] AS names, [toInt64(countIf(status = 'BACKUP_FAILED')), toInt64(countIf(status = 'BACKUP_CREATED')), toInt64(countIf(status = 'BACKUP_CANCELLED')), toInt64(countIf(status = 'CREATING_BACKUP'))] AS values, ['Number of failed backups', 'Number of successful backups', 'Number of cancelled backups', 'Number of backup attempts'] AS descriptions, ['gauge', 'gauge', 'gauge', 'gauge'] AS types, arrayJoin(arrayZip(names, values, descriptions, types)) AS tpl SELECT tpl.1 AS name, map('instance', hostname()) AS labels, tpl.2 AS value, tpl.3 AS help, tpl.4 AS type FROM system.backup_log WHERE event_date = today() GROUP BY event_date"
+ }
+
+ view "custom_metrics_dictionaries" {
+ query = "SELECT 'ClickHouseCustomMetric_DictionariesFailed' AS name, map('instance', hostname(), 'database', d.database, 'dictionary', d.dict_name, 'uuid', toString(d.uuid), 'status', toString(d.status)) AS labels, toUInt64(1) AS value, 'Dictionary is in FAILED or FAILED_AND_RELOADING status' AS help, 'gauge' AS type FROM (SELECT name AS dict_name, database, uuid, status FROM system.dictionaries WHERE status IN ('FAILED', 'FAILED_AND_RELOADING')) AS d"
+ }
+
+ view "custom_metrics_part_counts" {
+ query = "SELECT 'ClickHouseCustomMetric_MaxPartCountPerPartition' AS name, map('instance', hostname(), 'database', database, 'table', `table`, 'partition', partition) AS labels, part_count AS value, 'Maximum number of active parts for any partition in a PostHog table' AS help, 'gauge' AS type FROM (SELECT database, `table`, partition, count() AS part_count FROM system.parts WHERE active AND (database = 'posthog') GROUP BY database, `table`, partition ORDER BY database ASC, `table` ASC, part_count DESC, partition ASC LIMIT 1 BY database, `table`)"
+ }
+
+ view "custom_metrics_replication_queue" {
+ query = "WITH ['ClickHouseCustomMetric_ReplicationQueueStuckEntries', 'ClickHouseCustomMetric_ReplicationQueueMaxPostponedEntrySeconds', 'ClickHouseCustomMetric_ReplicationQueueMaxErrorEntrySeconds'] AS names, [toInt64(countIf(create_time < (now() - toIntervalDay(15)))), maxIf(dateDiff('seconds', create_time, last_postpone_time), last_postpone_time != '1970-01-01'), maxIf(dateDiff('seconds', create_time, last_exception_time), (last_exception_time != '1970-01-01') AND (last_exception_time > (now() - toIntervalMinute(5))))] AS values, ['Number of entries that have been in the replication queue for more than 15 days', 'Maximum number of seconds that an entry has been postponed', 'Maximum number of seconds that an entry has been in error'] AS descriptions, ['gauge', 'gauge', 'gauge'] AS types, arrayJoin(arrayZip(names, values, descriptions, types)) AS tpl SELECT tpl.1 AS name, map('table', `table`, 'instance', hostname()) AS labels, tpl.2 AS value, tpl.3 AS help, tpl.4 AS type FROM system.replication_queue GROUP BY `table` HAVING value > 0"
+ }
+
+ view "custom_metrics_server_crash" {
+ query = "SELECT 'ClickHouseCustomMetric_ServerCrash' AS name, map('instance', hostname()) AS labels, count() AS value, 'Number of server crashes for current date' AS help, 'gauge' AS type FROM system.crash_log WHERE event_date = today() GROUP BY hostname()"
+ }
+
+ view "custom_metrics_table_sizes" {
+ query = "SELECT 'ClickHouseCustomMetric_TableTotalBytes' AS name, map('instance', hostname(), 'database', database, 'table', `table`) AS labels, CAST(total_bytes, 'Float64') AS value, 'Size of a database table on a given node (need a sum for sharded)' AS help, 'gauge' AS type FROM system.tables WHERE (database NOT IN ('INFORMATION_SCHEMA', 'information_schema')) AND (total_bytes IS NOT NULL)"
+ }
+
+ view "custom_metrics_test" {
+ query = "SELECT 'ClickHouseCustomMetric_Test' AS name, map('instance', hostname()) AS labels, 1 AS value, 'Test to check that the metric endpoint is working' AS help, 'gauge' AS type"
+ }
+
+ view "daily_aggregated_query_log_archive" {
+ query = "SELECT event_date AS day, team_id, user, current_database, query_kind, lc_kind, lc_access_method, lc_query_type, lc_product, lc_name, lc_feature, lc_query__kind, lc_api_key_label, count() AS query_count, sum(read_bytes) AS read_bytes, sum(read_rows) AS read_rows, sum(query_duration_ms) AS query_duration_ms, sum(ProfileEvents_OSCPUVirtualTimeMicroseconds) AS cpu_microseconds, countIf(exception_code != 0) AS error_count, countIf(exception_code IN (159, 160, 241)) AS timeout_oom_count FROM posthog.sharded_query_log_archive WHERE is_initial_query AND (event_date < today()) GROUP BY day, team_id, user, current_database, query_kind, lc_kind, lc_access_method, lc_query_type, lc_product, lc_name, lc_feature, lc_query__kind, lc_api_key_label"
+ }
+}
diff --git a/posthog/clickhouse/hcl/ops/golden/prod-eu-ops.hcl b/posthog/clickhouse/hcl/ops/golden/prod-eu-ops.hcl
new file mode 100644
index 000000000000..0310b5587ea5
--- /dev/null
+++ b/posthog/clickhouse/hcl/ops/golden/prod-eu-ops.hcl
@@ -0,0 +1,1428 @@
+node "prod-eu-fra-ch-1a-ops" {
+ macros = {
+ cluster = "ops"
+ hostClusterRole = "ops"
+ hostClusterType = "offline"
+ replica = "a"
+ shard = "1"
+ }
+}
+
+database "posthog" {
+ table "events_main" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "elements_chain" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "person_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "person_properties" {
+ type = "String"
+ }
+ column "group0_properties" {
+ type = "String"
+ }
+ column "group1_properties" {
+ type = "String"
+ }
+ column "group2_properties" {
+ type = "String"
+ }
+ column "group3_properties" {
+ type = "String"
+ }
+ column "group4_properties" {
+ type = "String"
+ }
+ column "group0_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group1_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group2_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group3_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group4_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "person_mode" {
+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "events_team_daily_stats" {
+ order_by = ["analysis_date", "team_id", "event"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "analysis_date" {
+ type = "Date"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "event_count" {
+ type = "UInt64"
+ }
+ column "total_event_bytes" {
+ type = "UInt64"
+ }
+ column "min_event_bytes" {
+ type = "UInt64"
+ }
+ column "max_event_bytes" {
+ type = "UInt64"
+ }
+ column "avg_event_bytes" {
+ type = "Float64"
+ }
+ column "p50_event_bytes" {
+ type = "Float64"
+ }
+ column "p90_event_bytes" {
+ type = "Float64"
+ }
+ column "p95_event_bytes" {
+ type = "Float64"
+ }
+ column "p99_event_bytes" {
+ type = "Float64"
+ }
+ column "event_size_histogram" {
+ type = "Array(Tuple(Float64, Float64, UInt64))"
+ }
+ column "computed_at" {
+ type = "DateTime"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.events_team_daily_stats"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "metrics_exemplars" {
+ order_by = ["team_id", "id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ settings = {
+ index_granularity = "1024"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ column "labels_json" {
+ type = "String"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.metrics_exemplars"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "metrics_histograms" {
+ order_by = ["team_id", "id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ settings = {
+ index_granularity = "1024"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ column "histogram" {
+ type = "String"
+ }
+ column "version" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.metrics_histograms"
+ replica_name = "{replica}"
+ version_column = "version"
+ }
+ }
+
+ table "metrics_label_index" {
+ order_by = ["team_id", "metric_name", "label_name", "label_value", "id"]
+ settings = {
+ deduplicate_merge_projection_mode = "rebuild"
+ index_granularity = "1024"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "label_name" {
+ type = "LowCardinality(String)"
+ }
+ column "label_value" {
+ type = "String"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.metrics_label_index"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "metrics_metadata" {
+ order_by = ["team_id", "metric_family_name"]
+ settings = {
+ index_granularity = "1024"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "metric_family_name" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ }
+ column "unit" {
+ type = "String"
+ }
+ column "help" {
+ type = "String"
+ }
+ column "updated_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.metrics_metadata"
+ replica_name = "{replica}"
+ version_column = "updated_at"
+ }
+ }
+
+ table "metrics_samples" {
+ order_by = ["team_id", "metric_name", "id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ settings = {
+ index_granularity = "1024"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.metrics_samples"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "metrics_series" {
+ order_by = ["team_id", "metric_name", "id"]
+ settings = {
+ index_granularity = "1024"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "labels_json" {
+ type = "String"
+ }
+ column "min_time" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "max_time" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.metrics_series"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "query_log_archive" {
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ column "exception_name" {
+ type = "String"
+ alias = "errorCodeToName(exception_code)"
+ }
+ column "ProfileEvents_RealTimeMicroseconds" {
+ type = "Int64"
+ alias = "ProfileEvents['RealTimeMicroseconds']"
+ }
+ column "ProfileEvents_OSCPUVirtualTimeMicroseconds" {
+ type = "Int64"
+ alias = "ProfileEvents['OSCPUVirtualTimeMicroseconds']"
+ }
+ column "ProfileEvents_S3Clients" {
+ type = "Int64"
+ alias = "ProfileEvents['S3Clients']"
+ }
+ column "ProfileEvents_S3DeleteObjects" {
+ type = "Int64"
+ alias = "ProfileEvents['S3DeleteObjects']"
+ }
+ column "ProfileEvents_S3CopyObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CopyObject']"
+ }
+ column "ProfileEvents_S3ListObjects" {
+ type = "Int64"
+ alias = "ProfileEvents['S3ListObjects']"
+ }
+ column "ProfileEvents_S3HeadObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3HeadObject']"
+ }
+ column "ProfileEvents_S3GetObjectAttributes" {
+ type = "Int64"
+ alias = "ProfileEvents['S3GetObjectAttributes']"
+ }
+ column "ProfileEvents_S3CreateMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CreateMultipartUpload']"
+ }
+ column "ProfileEvents_S3UploadPartCopy" {
+ type = "Int64"
+ alias = "ProfileEvents['S3UploadPartCopy']"
+ }
+ column "ProfileEvents_S3UploadPart" {
+ type = "Int64"
+ alias = "ProfileEvents['S3UploadPart']"
+ }
+ column "ProfileEvents_S3AbortMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3AbortMultipartUpload']"
+ }
+ column "ProfileEvents_S3CompleteMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CompleteMultipartUpload']"
+ }
+ column "ProfileEvents_S3PutObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3PutObject']"
+ }
+ column "ProfileEvents_S3GetObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3GetObject']"
+ }
+ column "ProfileEvents_ReadBufferFromS3Bytes" {
+ type = "Int64"
+ alias = "ProfileEvents['ReadBufferFromS3Bytes']"
+ }
+ column "ProfileEvents_WriteBufferFromS3Bytes" {
+ type = "Int64"
+ alias = "ProfileEvents['WriteBufferFromS3Bytes']"
+ }
+ column "lc_workflow" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.workflow"
+ }
+ column "lc_kind" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.kind"
+ }
+ column "lc_id" {
+ type = "String"
+ alias = "CAST(log_comment.id, 'String')"
+ }
+ column "lc_route_id" {
+ type = "String"
+ alias = "CAST(log_comment.route_id, 'String')"
+ }
+ column "lc_access_method" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.access_method"
+ }
+ column "lc_api_key_label" {
+ type = "String"
+ alias = "CAST(log_comment.api_key_label, 'String')"
+ }
+ column "lc_api_key_mask" {
+ type = "String"
+ alias = "CAST(log_comment.api_key_mask, 'String')"
+ }
+ column "lc_query_type" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.query_type"
+ }
+ column "lc_product" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.product"
+ }
+ column "lc_chargeable" {
+ type = "Bool"
+ alias = "log_comment.chargeable"
+ }
+ column "lc_name" {
+ type = "String"
+ alias = "CAST(log_comment.name, 'String')"
+ }
+ column "lc_request_name" {
+ type = "String"
+ alias = "CAST(log_comment.request_name, 'String')"
+ }
+ column "lc_client_query_id" {
+ type = "String"
+ alias = "CAST(log_comment.client_query_id, 'String')"
+ }
+ column "lc_org_id" {
+ type = "String"
+ alias = "CAST(log_comment.org_id, 'String')"
+ }
+ column "lc_user_id" {
+ type = "Int64"
+ alias = "log_comment.user_id"
+ }
+ column "lc_is_impersonated" {
+ type = "Bool"
+ alias = "log_comment.is_impersonated"
+ }
+ column "lc_session_id" {
+ type = "String"
+ alias = "CAST(log_comment.session_id, 'String')"
+ }
+ column "lc_dashboard_id" {
+ type = "Int64"
+ alias = "log_comment.dashboard_id"
+ }
+ column "lc_insight_id" {
+ type = "Int64"
+ alias = "log_comment.insight_id"
+ }
+ column "lc_cohort_id" {
+ type = "Int64"
+ alias = "log_comment.cohort_id"
+ }
+ column "lc_batch_export_id" {
+ type = "String"
+ alias = "CAST(log_comment.batch_export_id, 'String')"
+ }
+ column "lc_experiment_id" {
+ type = "Int64"
+ alias = "log_comment.experiment_id"
+ }
+ column "lc_experiment_feature_flag_key" {
+ type = "String"
+ alias = "CAST(log_comment.experiment_feature_flag_key, 'String')"
+ }
+ column "lc_alert_config_id" {
+ type = "String"
+ alias = "CAST(log_comment.alert_config_id, 'String')"
+ }
+ column "lc_feature" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.feature"
+ }
+ column "lc_table_id" {
+ type = "String"
+ alias = "CAST(log_comment.table_id, 'String')"
+ }
+ column "lc_warehouse_query" {
+ type = "Bool"
+ alias = "log_comment.warehouse_query"
+ }
+ column "lc_person_on_events_mode" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.person_on_events_mode"
+ }
+ column "lc_service_name" {
+ type = "String"
+ alias = "CAST(log_comment.service_name, 'String')"
+ }
+ column "lc_workload" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.workload"
+ }
+ column "lc_query__kind" {
+ type = "LowCardinality(String)"
+ alias = "if(JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'kind'), JSONExtractString(toString(log_comment), 'query', 'kind'))"
+ }
+ column "lc_query__query" {
+ type = "String"
+ alias = "multiIf(NOT is_initial_query, '', JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'query'), JSONExtractString(toString(log_comment), 'query', 'query'))"
+ }
+ column "lc_query" {
+ type = "String"
+ alias = "if(is_initial_query, JSONExtractRaw(toString(log_comment), 'query'), '')"
+ }
+ column "lc_temporal__workflow_namespace" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_namespace`, 'String')"
+ }
+ column "lc_temporal__workflow_type" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_type`, 'String')"
+ }
+ column "lc_temporal__workflow_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_id`, 'String')"
+ }
+ column "lc_temporal__workflow_run_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_run_id`, 'String')"
+ }
+ column "lc_temporal__activity_type" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.activity_type`, 'String')"
+ }
+ column "lc_temporal__activity_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.activity_id`, 'String')"
+ }
+ column "lc_temporal__attempt" {
+ type = "Int64"
+ alias = "log_comment.`temporal.attempt`"
+ }
+ column "lc_dagster__job_name" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.job_name`, 'String')"
+ }
+ column "lc_dagster__run_id" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.run_id`, 'String')"
+ }
+ column "lc_dagster__owner" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.tags.owner`, 'String')"
+ }
+ column "lc_modifiers" {
+ type = "String"
+ alias = "if(is_initial_query, JSONExtractRaw(toString(log_comment), 'modifiers'), '')"
+ }
+ engine "distributed" {
+ cluster_name = "ops"
+ remote_database = "posthog"
+ remote_table = "sharded_query_log_archive"
+ }
+ }
+
+ table "query_log_archive_buffer" {
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ engine "buffer" {
+ database = "posthog"
+ table = "sharded_query_log_archive"
+ num_layers = 16
+ min_time = 10
+ max_time = 60
+ min_rows = 10000
+ max_rows = 1000000
+ min_bytes = 10000000
+ max_bytes = 100000000
+ }
+ }
+
+ table "sharded_query_log_archive" {
+ order_by = ["team_id", "event_date", "event_time", "query_id"]
+ partition_by = "toYYYYMM(event_date)"
+ settings = {
+ index_granularity = "8192"
+ object_serialization_version = "v3"
+ object_shared_data_serialization_version = "map_with_buckets"
+ }
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ column "exception_name" {
+ type = "String"
+ alias = "errorCodeToName(exception_code)"
+ }
+ column "ProfileEvents_RealTimeMicroseconds" {
+ type = "Int64"
+ alias = "ProfileEvents['RealTimeMicroseconds']"
+ }
+ column "ProfileEvents_OSCPUVirtualTimeMicroseconds" {
+ type = "Int64"
+ alias = "ProfileEvents['OSCPUVirtualTimeMicroseconds']"
+ }
+ column "ProfileEvents_S3Clients" {
+ type = "Int64"
+ alias = "ProfileEvents['S3Clients']"
+ }
+ column "ProfileEvents_S3DeleteObjects" {
+ type = "Int64"
+ alias = "ProfileEvents['S3DeleteObjects']"
+ }
+ column "ProfileEvents_S3CopyObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CopyObject']"
+ }
+ column "ProfileEvents_S3ListObjects" {
+ type = "Int64"
+ alias = "ProfileEvents['S3ListObjects']"
+ }
+ column "ProfileEvents_S3HeadObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3HeadObject']"
+ }
+ column "ProfileEvents_S3GetObjectAttributes" {
+ type = "Int64"
+ alias = "ProfileEvents['S3GetObjectAttributes']"
+ }
+ column "ProfileEvents_S3CreateMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CreateMultipartUpload']"
+ }
+ column "ProfileEvents_S3UploadPartCopy" {
+ type = "Int64"
+ alias = "ProfileEvents['S3UploadPartCopy']"
+ }
+ column "ProfileEvents_S3UploadPart" {
+ type = "Int64"
+ alias = "ProfileEvents['S3UploadPart']"
+ }
+ column "ProfileEvents_S3AbortMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3AbortMultipartUpload']"
+ }
+ column "ProfileEvents_S3CompleteMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CompleteMultipartUpload']"
+ }
+ column "ProfileEvents_S3PutObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3PutObject']"
+ }
+ column "ProfileEvents_S3GetObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3GetObject']"
+ }
+ column "ProfileEvents_ReadBufferFromS3Bytes" {
+ type = "Int64"
+ alias = "ProfileEvents['ReadBufferFromS3Bytes']"
+ }
+ column "ProfileEvents_WriteBufferFromS3Bytes" {
+ type = "Int64"
+ alias = "ProfileEvents['WriteBufferFromS3Bytes']"
+ }
+ column "lc_workflow" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.workflow"
+ }
+ column "lc_kind" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.kind"
+ }
+ column "lc_id" {
+ type = "String"
+ alias = "CAST(log_comment.id, 'String')"
+ }
+ column "lc_route_id" {
+ type = "String"
+ alias = "CAST(log_comment.route_id, 'String')"
+ }
+ column "lc_access_method" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.access_method"
+ }
+ column "lc_api_key_label" {
+ type = "String"
+ alias = "CAST(log_comment.api_key_label, 'String')"
+ }
+ column "lc_api_key_mask" {
+ type = "String"
+ alias = "CAST(log_comment.api_key_mask, 'String')"
+ }
+ column "lc_query_type" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.query_type"
+ }
+ column "lc_product" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.product"
+ }
+ column "lc_chargeable" {
+ type = "Bool"
+ alias = "log_comment.chargeable"
+ }
+ column "lc_name" {
+ type = "String"
+ alias = "CAST(log_comment.name, 'String')"
+ }
+ column "lc_request_name" {
+ type = "String"
+ alias = "CAST(log_comment.request_name, 'String')"
+ }
+ column "lc_client_query_id" {
+ type = "String"
+ alias = "CAST(log_comment.client_query_id, 'String')"
+ }
+ column "lc_org_id" {
+ type = "String"
+ alias = "CAST(log_comment.org_id, 'String')"
+ }
+ column "lc_user_id" {
+ type = "Int64"
+ alias = "log_comment.user_id"
+ }
+ column "lc_is_impersonated" {
+ type = "Bool"
+ alias = "log_comment.is_impersonated"
+ }
+ column "lc_session_id" {
+ type = "String"
+ alias = "CAST(log_comment.session_id, 'String')"
+ }
+ column "lc_dashboard_id" {
+ type = "Int64"
+ alias = "log_comment.dashboard_id"
+ }
+ column "lc_insight_id" {
+ type = "Int64"
+ alias = "log_comment.insight_id"
+ }
+ column "lc_cohort_id" {
+ type = "Int64"
+ alias = "log_comment.cohort_id"
+ }
+ column "lc_batch_export_id" {
+ type = "String"
+ alias = "CAST(log_comment.batch_export_id, 'String')"
+ }
+ column "lc_experiment_id" {
+ type = "Int64"
+ alias = "log_comment.experiment_id"
+ }
+ column "lc_experiment_feature_flag_key" {
+ type = "String"
+ alias = "CAST(log_comment.experiment_feature_flag_key, 'String')"
+ }
+ column "lc_alert_config_id" {
+ type = "String"
+ alias = "CAST(log_comment.alert_config_id, 'String')"
+ }
+ column "lc_feature" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.feature"
+ }
+ column "lc_table_id" {
+ type = "String"
+ alias = "CAST(log_comment.table_id, 'String')"
+ }
+ column "lc_warehouse_query" {
+ type = "Bool"
+ alias = "log_comment.warehouse_query"
+ }
+ column "lc_person_on_events_mode" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.person_on_events_mode"
+ }
+ column "lc_service_name" {
+ type = "String"
+ alias = "CAST(log_comment.service_name, 'String')"
+ }
+ column "lc_workload" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.workload"
+ }
+ column "lc_query__kind" {
+ type = "LowCardinality(String)"
+ alias = "if(JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'kind'), JSONExtractString(toString(log_comment), 'query', 'kind'))"
+ }
+ column "lc_query__query" {
+ type = "String"
+ alias = "multiIf(NOT is_initial_query, '', JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'query'), JSONExtractString(toString(log_comment), 'query', 'query'))"
+ }
+ column "lc_query" {
+ type = "String"
+ alias = "if(is_initial_query, JSONExtractRaw(toString(log_comment), 'query'), '')"
+ }
+ column "lc_temporal__workflow_namespace" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_namespace`, 'String')"
+ }
+ column "lc_temporal__workflow_type" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_type`, 'String')"
+ }
+ column "lc_temporal__workflow_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_id`, 'String')"
+ }
+ column "lc_temporal__workflow_run_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_run_id`, 'String')"
+ }
+ column "lc_temporal__activity_type" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.activity_type`, 'String')"
+ }
+ column "lc_temporal__activity_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.activity_id`, 'String')"
+ }
+ column "lc_temporal__attempt" {
+ type = "Int64"
+ alias = "log_comment.`temporal.attempt`"
+ }
+ column "lc_dagster__job_name" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.job_name`, 'String')"
+ }
+ column "lc_dagster__run_id" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.run_id`, 'String')"
+ }
+ column "lc_dagster__owner" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.tags.owner`, 'String')"
+ }
+ column "lc_modifiers" {
+ type = "String"
+ alias = "if(is_initial_query, JSONExtractRaw(toString(log_comment), 'modifiers'), '')"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.sharded_query_log_archive"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "sharded_tophog" {
+ order_by = ["pipeline", "lane", "metric", "timestamp", "key"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(30)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "metric" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ default = "'sum'"
+ }
+ column "key" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ column "count" {
+ type = "UInt64"
+ default = "0"
+ }
+ column "pipeline" {
+ type = "LowCardinality(String)"
+ }
+ column "lane" {
+ type = "LowCardinality(String)"
+ }
+ column "labels" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/ops/{shard}/posthog.tophog"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "writable_query_log_archive" {
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "ops"
+ remote_database = "posthog"
+ remote_table = "query_log_archive_buffer"
+ }
+ }
+
+ materialized_view "metrics_label_index_from_series_mv" {
+ to_table = "posthog.metrics_label_index"
+ query = "SELECT team_id, metric_name, tupleElement(label_pair, 1) AS label_name, tupleElement(label_pair, 2) AS label_value, id FROM posthog.metrics_series ARRAY JOIN JSONExtractKeysAndValues(labels_json, 'String') AS label_pair"
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "label_name" {
+ type = "LowCardinality(String)"
+ }
+ column "label_value" {
+ type = "String"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ }
+
+ materialized_view "ops_query_log_archive_mv" {
+ to_table = "posthog.writable_query_log_archive"
+ query = "SELECT hostname, user, query_id, initial_query_id, is_initial_query, type, event_date, event_time, event_time_microseconds, query_start_time, query_start_time_microseconds, query_duration_ms, read_rows, read_bytes, written_rows, written_bytes, result_rows, result_bytes, memory_usage, peak_threads_usage, current_database, query, formatted_query, normalized_query_hash, query_kind, exception_code, exception, stack_trace, JSONExtractInt(log_comment, 'team_id') AS team_id, if(isValidJSON(log_comment), log_comment, '{}') AS log_comment, ProfileEvents FROM system.query_log WHERE type != 'QueryStart'"
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "String"
+ }
+ column "ProfileEvents" {
+ type = "Map(LowCardinality(String), UInt64)"
+ }
+ }
+
+ view "custom_metrics" {
+ query = "SELECT * REPLACE(toFloat64(value) AS value) FROM posthog.custom_metrics_test UNION ALL SELECT * REPLACE(toFloat64(value) AS value) FROM posthog.custom_metrics_replication_queue UNION ALL SELECT * REPLACE(toFloat64(value) AS value) FROM posthog.custom_metrics_server_crash UNION ALL SELECT * FROM posthog.custom_metrics_table_sizes UNION ALL SELECT * REPLACE(toFloat64(value) AS value) FROM posthog.custom_metrics_part_counts UNION ALL SELECT * REPLACE(toFloat64(value) AS value) FROM posthog.custom_metrics_dictionaries UNION ALL SELECT 'ClickHouseCustomMetric_S3DiskBytesUsed' AS name, map('instance', hostname(), 'disk', disk_name) AS labels, toFloat64(sum(bytes_on_disk)) AS value, 'Bytes currently used by ClickHouse parts on S3-backed disks on this node' AS help, 'gauge' AS type FROM system.parts WHERE disk_name IN ('s3disk', 'cache') GROUP BY disk_name UNION ALL SELECT 'ClickHouseCustomMetric_MergeFailures15m' AS name, map('instance', hostname()) AS labels, toFloat64(count()) AS value, 'Number of failed merge operations in the last 15 minutes' AS help, 'gauge' AS type FROM system.part_log WHERE (event_time >= (now() - toIntervalMinute(15))) AND (event_type = 'MergeParts') AND (error > 0) AND (merge_reason != 'NotAMerge') AND (error != 40) UNION ALL SELECT 'ClickHouseCustomMetric_MergeRetriesMaxPerTable15m' AS name, map('instance', hostname()) AS labels, toFloat64(max(cnt)) AS value, 'Max failed merge retries for any single table in the last 15 minutes' AS help, 'gauge' AS type FROM (SELECT count() AS cnt FROM system.part_log WHERE (event_time >= (now() - toIntervalMinute(15))) AND (event_type = 'MergeParts') AND (error > 0) AND (merge_reason != 'NotAMerge') AND (error != 40) GROUP BY database, `table`, partition_id)"
+ }
+
+ view "custom_metrics_backups" {
+ query = "WITH ['ClickHouseCustomMetric_BackupFailed', 'ClickHouseCustomMetric_BackupSuccess', 'ClickHouseCustomMetric_BackupCancelled', 'ClickHouseCustomMetric_BackupAttempts'] AS names, [toInt64(countIf(status = 'BACKUP_FAILED')), toInt64(countIf(status = 'BACKUP_CREATED')), toInt64(countIf(status = 'BACKUP_CANCELLED')), toInt64(countIf(status = 'CREATING_BACKUP'))] AS values, ['Number of failed backups', 'Number of successful backups', 'Number of cancelled backups', 'Number of backup attempts'] AS descriptions, ['gauge', 'gauge', 'gauge', 'gauge'] AS types, arrayJoin(arrayZip(names, values, descriptions, types)) AS tpl SELECT tpl.1 AS name, map('instance', hostname()) AS labels, tpl.2 AS value, tpl.3 AS help, tpl.4 AS type FROM system.backup_log WHERE event_date = today() GROUP BY event_date"
+ }
+
+ view "custom_metrics_dictionaries" {
+ query = "SELECT 'ClickHouseCustomMetric_DictionariesFailed' AS name, map('instance', hostname(), 'database', d.database, 'dictionary', d.dict_name, 'uuid', toString(d.uuid), 'status', toString(d.status)) AS labels, toUInt64(1) AS value, 'Dictionary is in FAILED or FAILED_AND_RELOADING status' AS help, 'gauge' AS type FROM (SELECT name AS dict_name, database, uuid, status FROM system.dictionaries WHERE status IN ('FAILED', 'FAILED_AND_RELOADING')) AS d"
+ }
+
+ view "custom_metrics_part_counts" {
+ query = "SELECT 'ClickHouseCustomMetric_MaxPartCountPerPartition' AS name, map('instance', hostname(), 'database', database, 'table', `table`, 'partition', partition) AS labels, part_count AS value, 'Maximum number of active parts for any partition in a PostHog table' AS help, 'gauge' AS type FROM (SELECT database, `table`, partition, count() AS part_count FROM system.parts WHERE active AND (database = 'posthog') GROUP BY database, `table`, partition ORDER BY database ASC, `table` ASC, part_count DESC, partition ASC LIMIT 1 BY database, `table`)"
+ }
+
+ view "custom_metrics_replication_queue" {
+ query = "WITH ['ClickHouseCustomMetric_ReplicationQueueStuckEntries', 'ClickHouseCustomMetric_ReplicationQueueMaxPostponedEntrySeconds', 'ClickHouseCustomMetric_ReplicationQueueMaxErrorEntrySeconds'] AS names, [toInt64(countIf(create_time < (now() - toIntervalDay(15)))), maxIf(dateDiff('seconds', create_time, last_postpone_time), last_postpone_time != '1970-01-01'), maxIf(dateDiff('seconds', create_time, last_exception_time), (last_exception_time != '1970-01-01') AND (last_exception_time > (now() - toIntervalMinute(5))))] AS values, ['Number of entries that have been in the replication queue for more than 15 days', 'Maximum number of seconds that an entry has been postponed', 'Maximum number of seconds that an entry has been in error'] AS descriptions, ['gauge', 'gauge', 'gauge'] AS types, arrayJoin(arrayZip(names, values, descriptions, types)) AS tpl SELECT tpl.1 AS name, map('table', `table`, 'instance', hostname()) AS labels, tpl.2 AS value, tpl.3 AS help, tpl.4 AS type FROM system.replication_queue GROUP BY `table` HAVING value > 0"
+ }
+
+ view "custom_metrics_server_crash" {
+ query = "SELECT 'ClickHouseCustomMetric_ServerCrash' AS name, map('instance', hostname()) AS labels, count() AS value, 'Number of server crashes for current date' AS help, 'gauge' AS type FROM system.crash_log WHERE event_date = today() GROUP BY hostname()"
+ }
+
+ view "custom_metrics_table_sizes" {
+ query = "SELECT 'ClickHouseCustomMetric_TableTotalBytes' AS name, map('instance', hostname(), 'database', database, 'table', `table`) AS labels, CAST(total_bytes, 'Float64') AS value, 'Size of a database table on a given node (need a sum for sharded)' AS help, 'gauge' AS type FROM system.tables WHERE (database NOT IN ('INFORMATION_SCHEMA', 'information_schema')) AND (total_bytes IS NOT NULL)"
+ }
+
+ view "custom_metrics_test" {
+ query = "SELECT 'ClickHouseCustomMetric_Test' AS name, map('instance', hostname()) AS labels, 1 AS value, 'Test to check that the metric endpoint is working' AS help, 'gauge' AS type"
+ }
+
+ view "daily_aggregated_query_log_archive" {
+ query = "SELECT event_date AS day, team_id, user, current_database, query_kind, lc_kind, lc_access_method, lc_query_type, lc_product, lc_name, lc_feature, lc_query__kind, lc_api_key_label, count() AS query_count, sum(read_bytes) AS read_bytes, sum(read_rows) AS read_rows, sum(query_duration_ms) AS query_duration_ms, sum(ProfileEvents_OSCPUVirtualTimeMicroseconds) AS cpu_microseconds, countIf(exception_code != 0) AS error_count, countIf(exception_code IN (159, 160, 241)) AS timeout_oom_count FROM posthog.sharded_query_log_archive WHERE is_initial_query AND (event_date < today()) GROUP BY day, team_id, user, current_database, query_kind, lc_kind, lc_access_method, lc_query_type, lc_product, lc_name, lc_feature, lc_query__kind, lc_api_key_label"
+ }
+}
diff --git a/posthog/clickhouse/hcl/ops/golden/prod-us-ops.hcl b/posthog/clickhouse/hcl/ops/golden/prod-us-ops.hcl
new file mode 100644
index 000000000000..234bd36f791b
--- /dev/null
+++ b/posthog/clickhouse/hcl/ops/golden/prod-us-ops.hcl
@@ -0,0 +1,1515 @@
+node "prod-us-iad-ch-1c-ops" {
+ macros = {
+ cluster = "ops"
+ hostClusterRole = "ops"
+ hostClusterType = "offline"
+ replica = "c"
+ shard = "1"
+ }
+}
+
+database "posthog" {
+ table "events_main" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "elements_chain" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "person_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "person_properties" {
+ type = "String"
+ }
+ column "group0_properties" {
+ type = "String"
+ }
+ column "group1_properties" {
+ type = "String"
+ }
+ column "group2_properties" {
+ type = "String"
+ }
+ column "group3_properties" {
+ type = "String"
+ }
+ column "group4_properties" {
+ type = "String"
+ }
+ column "group0_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group1_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group2_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group3_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group4_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "person_mode" {
+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ engine "distributed" {
+ cluster_name = "posthog"
+ remote_database = "posthog"
+ remote_table = "sharded_events"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "events_recent" {
+ column "uuid" {
+ type = "UUID"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "properties" {
+ type = "String"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "distinct_id" {
+ type = "String"
+ }
+ column "elements_chain" {
+ type = "String"
+ }
+ column "created_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "person_id" {
+ type = "UUID"
+ }
+ column "person_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "person_properties" {
+ type = "String"
+ }
+ column "group0_properties" {
+ type = "String"
+ }
+ column "group1_properties" {
+ type = "String"
+ }
+ column "group2_properties" {
+ type = "String"
+ }
+ column "group3_properties" {
+ type = "String"
+ }
+ column "group4_properties" {
+ type = "String"
+ }
+ column "group0_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group1_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group2_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group3_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "group4_created_at" {
+ type = "DateTime64(3)"
+ }
+ column "person_mode" {
+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"
+ }
+ column "_timestamp" {
+ type = "DateTime"
+ }
+ column "_offset" {
+ type = "UInt64"
+ }
+ column "inserted_at" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ engine "distributed" {
+ cluster_name = "batch_exports"
+ remote_database = "posthog"
+ remote_table = "sharded_events_recent"
+ sharding_key = "sipHash64(distinct_id)"
+ }
+ }
+
+ table "events_team_daily_stats" {
+ order_by = ["analysis_date", "team_id", "event"]
+ settings = {
+ index_granularity = "8192"
+ }
+ column "analysis_date" {
+ type = "Date"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "event" {
+ type = "String"
+ }
+ column "event_count" {
+ type = "UInt64"
+ }
+ column "total_event_bytes" {
+ type = "UInt64"
+ }
+ column "min_event_bytes" {
+ type = "UInt64"
+ }
+ column "max_event_bytes" {
+ type = "UInt64"
+ }
+ column "avg_event_bytes" {
+ type = "Float64"
+ }
+ column "p50_event_bytes" {
+ type = "Float64"
+ }
+ column "p90_event_bytes" {
+ type = "Float64"
+ }
+ column "p95_event_bytes" {
+ type = "Float64"
+ }
+ column "p99_event_bytes" {
+ type = "Float64"
+ }
+ column "event_size_histogram" {
+ type = "Array(Tuple(Float64, Float64, UInt64))"
+ }
+ column "computed_at" {
+ type = "DateTime"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.events_team_daily_stats"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "metrics_exemplars" {
+ order_by = ["team_id", "id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ settings = {
+ index_granularity = "1024"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ column "labels_json" {
+ type = "String"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.metrics_exemplars"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "metrics_histograms" {
+ order_by = ["team_id", "id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ settings = {
+ index_granularity = "1024"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ column "histogram" {
+ type = "String"
+ }
+ column "version" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.metrics_histograms"
+ replica_name = "{replica}"
+ version_column = "version"
+ }
+ }
+
+ table "metrics_label_index" {
+ order_by = ["team_id", "metric_name", "label_name", "label_value", "id"]
+ settings = {
+ deduplicate_merge_projection_mode = "rebuild"
+ index_granularity = "1024"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "label_name" {
+ type = "LowCardinality(String)"
+ }
+ column "label_value" {
+ type = "String"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.metrics_label_index"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "metrics_metadata" {
+ order_by = ["team_id", "metric_family_name"]
+ settings = {
+ index_granularity = "1024"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "metric_family_name" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ }
+ column "unit" {
+ type = "String"
+ }
+ column "help" {
+ type = "String"
+ }
+ column "updated_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.metrics_metadata"
+ replica_name = "{replica}"
+ version_column = "updated_at"
+ }
+ }
+
+ table "metrics_samples" {
+ order_by = ["team_id", "metric_name", "id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ settings = {
+ index_granularity = "1024"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.metrics_samples"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "metrics_series" {
+ order_by = ["team_id", "metric_name", "id"]
+ settings = {
+ index_granularity = "1024"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "labels_json" {
+ type = "String"
+ }
+ column "min_time" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "max_time" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.metrics_series"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "query_log_archive" {
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ column "exception_name" {
+ type = "String"
+ alias = "errorCodeToName(exception_code)"
+ }
+ column "ProfileEvents_RealTimeMicroseconds" {
+ type = "Int64"
+ alias = "ProfileEvents['RealTimeMicroseconds']"
+ }
+ column "ProfileEvents_OSCPUVirtualTimeMicroseconds" {
+ type = "Int64"
+ alias = "ProfileEvents['OSCPUVirtualTimeMicroseconds']"
+ }
+ column "ProfileEvents_S3Clients" {
+ type = "Int64"
+ alias = "ProfileEvents['S3Clients']"
+ }
+ column "ProfileEvents_S3DeleteObjects" {
+ type = "Int64"
+ alias = "ProfileEvents['S3DeleteObjects']"
+ }
+ column "ProfileEvents_S3CopyObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CopyObject']"
+ }
+ column "ProfileEvents_S3ListObjects" {
+ type = "Int64"
+ alias = "ProfileEvents['S3ListObjects']"
+ }
+ column "ProfileEvents_S3HeadObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3HeadObject']"
+ }
+ column "ProfileEvents_S3GetObjectAttributes" {
+ type = "Int64"
+ alias = "ProfileEvents['S3GetObjectAttributes']"
+ }
+ column "ProfileEvents_S3CreateMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CreateMultipartUpload']"
+ }
+ column "ProfileEvents_S3UploadPartCopy" {
+ type = "Int64"
+ alias = "ProfileEvents['S3UploadPartCopy']"
+ }
+ column "ProfileEvents_S3UploadPart" {
+ type = "Int64"
+ alias = "ProfileEvents['S3UploadPart']"
+ }
+ column "ProfileEvents_S3AbortMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3AbortMultipartUpload']"
+ }
+ column "ProfileEvents_S3CompleteMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CompleteMultipartUpload']"
+ }
+ column "ProfileEvents_S3PutObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3PutObject']"
+ }
+ column "ProfileEvents_S3GetObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3GetObject']"
+ }
+ column "ProfileEvents_ReadBufferFromS3Bytes" {
+ type = "Int64"
+ alias = "ProfileEvents['ReadBufferFromS3Bytes']"
+ }
+ column "ProfileEvents_WriteBufferFromS3Bytes" {
+ type = "Int64"
+ alias = "ProfileEvents['WriteBufferFromS3Bytes']"
+ }
+ column "lc_workflow" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.workflow"
+ }
+ column "lc_kind" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.kind"
+ }
+ column "lc_id" {
+ type = "String"
+ alias = "CAST(log_comment.id, 'String')"
+ }
+ column "lc_route_id" {
+ type = "String"
+ alias = "CAST(log_comment.route_id, 'String')"
+ }
+ column "lc_access_method" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.access_method"
+ }
+ column "lc_api_key_label" {
+ type = "String"
+ alias = "CAST(log_comment.api_key_label, 'String')"
+ }
+ column "lc_api_key_mask" {
+ type = "String"
+ alias = "CAST(log_comment.api_key_mask, 'String')"
+ }
+ column "lc_query_type" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.query_type"
+ }
+ column "lc_product" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.product"
+ }
+ column "lc_chargeable" {
+ type = "Bool"
+ alias = "log_comment.chargeable"
+ }
+ column "lc_name" {
+ type = "String"
+ alias = "CAST(log_comment.name, 'String')"
+ }
+ column "lc_request_name" {
+ type = "String"
+ alias = "CAST(log_comment.request_name, 'String')"
+ }
+ column "lc_client_query_id" {
+ type = "String"
+ alias = "CAST(log_comment.client_query_id, 'String')"
+ }
+ column "lc_org_id" {
+ type = "String"
+ alias = "CAST(log_comment.org_id, 'String')"
+ }
+ column "lc_user_id" {
+ type = "Int64"
+ alias = "log_comment.user_id"
+ }
+ column "lc_is_impersonated" {
+ type = "Bool"
+ alias = "log_comment.is_impersonated"
+ }
+ column "lc_session_id" {
+ type = "String"
+ alias = "CAST(log_comment.session_id, 'String')"
+ }
+ column "lc_dashboard_id" {
+ type = "Int64"
+ alias = "log_comment.dashboard_id"
+ }
+ column "lc_insight_id" {
+ type = "Int64"
+ alias = "log_comment.insight_id"
+ }
+ column "lc_cohort_id" {
+ type = "Int64"
+ alias = "log_comment.cohort_id"
+ }
+ column "lc_batch_export_id" {
+ type = "String"
+ alias = "CAST(log_comment.batch_export_id, 'String')"
+ }
+ column "lc_experiment_id" {
+ type = "Int64"
+ alias = "log_comment.experiment_id"
+ }
+ column "lc_experiment_feature_flag_key" {
+ type = "String"
+ alias = "CAST(log_comment.experiment_feature_flag_key, 'String')"
+ }
+ column "lc_alert_config_id" {
+ type = "String"
+ alias = "CAST(log_comment.alert_config_id, 'String')"
+ }
+ column "lc_feature" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.feature"
+ }
+ column "lc_table_id" {
+ type = "String"
+ alias = "CAST(log_comment.table_id, 'String')"
+ }
+ column "lc_warehouse_query" {
+ type = "Bool"
+ alias = "log_comment.warehouse_query"
+ }
+ column "lc_person_on_events_mode" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.person_on_events_mode"
+ }
+ column "lc_service_name" {
+ type = "String"
+ alias = "CAST(log_comment.service_name, 'String')"
+ }
+ column "lc_workload" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.workload"
+ }
+ column "lc_query__kind" {
+ type = "LowCardinality(String)"
+ alias = "if(JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'kind'), JSONExtractString(toString(log_comment), 'query', 'kind'))"
+ }
+ column "lc_query__query" {
+ type = "String"
+ alias = "multiIf(NOT is_initial_query, '', JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'query'), JSONExtractString(toString(log_comment), 'query', 'query'))"
+ }
+ column "lc_query" {
+ type = "String"
+ alias = "if(is_initial_query, JSONExtractRaw(toString(log_comment), 'query'), '')"
+ }
+ column "lc_temporal__workflow_namespace" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_namespace`, 'String')"
+ }
+ column "lc_temporal__workflow_type" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_type`, 'String')"
+ }
+ column "lc_temporal__workflow_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_id`, 'String')"
+ }
+ column "lc_temporal__workflow_run_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_run_id`, 'String')"
+ }
+ column "lc_temporal__activity_type" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.activity_type`, 'String')"
+ }
+ column "lc_temporal__activity_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.activity_id`, 'String')"
+ }
+ column "lc_temporal__attempt" {
+ type = "Int64"
+ alias = "log_comment.`temporal.attempt`"
+ }
+ column "lc_dagster__job_name" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.job_name`, 'String')"
+ }
+ column "lc_dagster__run_id" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.run_id`, 'String')"
+ }
+ column "lc_dagster__owner" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.tags.owner`, 'String')"
+ }
+ column "lc_modifiers" {
+ type = "String"
+ alias = "if(is_initial_query, JSONExtractRaw(toString(log_comment), 'modifiers'), '')"
+ }
+ engine "distributed" {
+ cluster_name = "ops"
+ remote_database = "posthog"
+ remote_table = "sharded_query_log_archive"
+ }
+ }
+
+ table "query_log_archive_buffer" {
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ engine "buffer" {
+ database = "posthog"
+ table = "sharded_query_log_archive"
+ num_layers = 16
+ min_time = 10
+ max_time = 60
+ min_rows = 10000
+ max_rows = 1000000
+ min_bytes = 10000000
+ max_bytes = 100000000
+ }
+ }
+
+ table "sharded_query_log_archive" {
+ order_by = ["team_id", "event_date", "event_time", "query_id"]
+ partition_by = "toYYYYMM(event_date)"
+ settings = {
+ index_granularity = "8192"
+ object_serialization_version = "v3"
+ object_shared_data_serialization_version = "map_with_buckets"
+ }
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ column "exception_name" {
+ type = "String"
+ alias = "errorCodeToName(exception_code)"
+ }
+ column "ProfileEvents_RealTimeMicroseconds" {
+ type = "Int64"
+ alias = "ProfileEvents['RealTimeMicroseconds']"
+ }
+ column "ProfileEvents_OSCPUVirtualTimeMicroseconds" {
+ type = "Int64"
+ alias = "ProfileEvents['OSCPUVirtualTimeMicroseconds']"
+ }
+ column "ProfileEvents_S3Clients" {
+ type = "Int64"
+ alias = "ProfileEvents['S3Clients']"
+ }
+ column "ProfileEvents_S3DeleteObjects" {
+ type = "Int64"
+ alias = "ProfileEvents['S3DeleteObjects']"
+ }
+ column "ProfileEvents_S3CopyObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CopyObject']"
+ }
+ column "ProfileEvents_S3ListObjects" {
+ type = "Int64"
+ alias = "ProfileEvents['S3ListObjects']"
+ }
+ column "ProfileEvents_S3HeadObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3HeadObject']"
+ }
+ column "ProfileEvents_S3GetObjectAttributes" {
+ type = "Int64"
+ alias = "ProfileEvents['S3GetObjectAttributes']"
+ }
+ column "ProfileEvents_S3CreateMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CreateMultipartUpload']"
+ }
+ column "ProfileEvents_S3UploadPartCopy" {
+ type = "Int64"
+ alias = "ProfileEvents['S3UploadPartCopy']"
+ }
+ column "ProfileEvents_S3UploadPart" {
+ type = "Int64"
+ alias = "ProfileEvents['S3UploadPart']"
+ }
+ column "ProfileEvents_S3AbortMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3AbortMultipartUpload']"
+ }
+ column "ProfileEvents_S3CompleteMultipartUpload" {
+ type = "Int64"
+ alias = "ProfileEvents['S3CompleteMultipartUpload']"
+ }
+ column "ProfileEvents_S3PutObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3PutObject']"
+ }
+ column "ProfileEvents_S3GetObject" {
+ type = "Int64"
+ alias = "ProfileEvents['S3GetObject']"
+ }
+ column "ProfileEvents_ReadBufferFromS3Bytes" {
+ type = "Int64"
+ alias = "ProfileEvents['ReadBufferFromS3Bytes']"
+ }
+ column "ProfileEvents_WriteBufferFromS3Bytes" {
+ type = "Int64"
+ alias = "ProfileEvents['WriteBufferFromS3Bytes']"
+ }
+ column "lc_workflow" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.workflow"
+ }
+ column "lc_kind" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.kind"
+ }
+ column "lc_id" {
+ type = "String"
+ alias = "CAST(log_comment.id, 'String')"
+ }
+ column "lc_route_id" {
+ type = "String"
+ alias = "CAST(log_comment.route_id, 'String')"
+ }
+ column "lc_access_method" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.access_method"
+ }
+ column "lc_api_key_label" {
+ type = "String"
+ alias = "CAST(log_comment.api_key_label, 'String')"
+ }
+ column "lc_api_key_mask" {
+ type = "String"
+ alias = "CAST(log_comment.api_key_mask, 'String')"
+ }
+ column "lc_query_type" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.query_type"
+ }
+ column "lc_product" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.product"
+ }
+ column "lc_chargeable" {
+ type = "Bool"
+ alias = "log_comment.chargeable"
+ }
+ column "lc_name" {
+ type = "String"
+ alias = "CAST(log_comment.name, 'String')"
+ }
+ column "lc_request_name" {
+ type = "String"
+ alias = "CAST(log_comment.request_name, 'String')"
+ }
+ column "lc_client_query_id" {
+ type = "String"
+ alias = "CAST(log_comment.client_query_id, 'String')"
+ }
+ column "lc_org_id" {
+ type = "String"
+ alias = "CAST(log_comment.org_id, 'String')"
+ }
+ column "lc_user_id" {
+ type = "Int64"
+ alias = "log_comment.user_id"
+ }
+ column "lc_is_impersonated" {
+ type = "Bool"
+ alias = "log_comment.is_impersonated"
+ }
+ column "lc_session_id" {
+ type = "String"
+ alias = "CAST(log_comment.session_id, 'String')"
+ }
+ column "lc_dashboard_id" {
+ type = "Int64"
+ alias = "log_comment.dashboard_id"
+ }
+ column "lc_insight_id" {
+ type = "Int64"
+ alias = "log_comment.insight_id"
+ }
+ column "lc_cohort_id" {
+ type = "Int64"
+ alias = "log_comment.cohort_id"
+ }
+ column "lc_batch_export_id" {
+ type = "String"
+ alias = "CAST(log_comment.batch_export_id, 'String')"
+ }
+ column "lc_experiment_id" {
+ type = "Int64"
+ alias = "log_comment.experiment_id"
+ }
+ column "lc_experiment_feature_flag_key" {
+ type = "String"
+ alias = "CAST(log_comment.experiment_feature_flag_key, 'String')"
+ }
+ column "lc_alert_config_id" {
+ type = "String"
+ alias = "CAST(log_comment.alert_config_id, 'String')"
+ }
+ column "lc_feature" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.feature"
+ }
+ column "lc_table_id" {
+ type = "String"
+ alias = "CAST(log_comment.table_id, 'String')"
+ }
+ column "lc_warehouse_query" {
+ type = "Bool"
+ alias = "log_comment.warehouse_query"
+ }
+ column "lc_person_on_events_mode" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.person_on_events_mode"
+ }
+ column "lc_service_name" {
+ type = "String"
+ alias = "CAST(log_comment.service_name, 'String')"
+ }
+ column "lc_workload" {
+ type = "LowCardinality(String)"
+ alias = "log_comment.workload"
+ }
+ column "lc_query__kind" {
+ type = "LowCardinality(String)"
+ alias = "if(JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'kind'), JSONExtractString(toString(log_comment), 'query', 'kind'))"
+ }
+ column "lc_query__query" {
+ type = "String"
+ alias = "multiIf(NOT is_initial_query, '', JSONHas(toString(log_comment), 'query', 'source'), JSONExtractString(toString(log_comment), 'query', 'source', 'query'), JSONExtractString(toString(log_comment), 'query', 'query'))"
+ }
+ column "lc_query" {
+ type = "String"
+ alias = "if(is_initial_query, JSONExtractRaw(toString(log_comment), 'query'), '')"
+ }
+ column "lc_temporal__workflow_namespace" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_namespace`, 'String')"
+ }
+ column "lc_temporal__workflow_type" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_type`, 'String')"
+ }
+ column "lc_temporal__workflow_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_id`, 'String')"
+ }
+ column "lc_temporal__workflow_run_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.workflow_run_id`, 'String')"
+ }
+ column "lc_temporal__activity_type" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.activity_type`, 'String')"
+ }
+ column "lc_temporal__activity_id" {
+ type = "String"
+ alias = "CAST(log_comment.`temporal.activity_id`, 'String')"
+ }
+ column "lc_temporal__attempt" {
+ type = "Int64"
+ alias = "log_comment.`temporal.attempt`"
+ }
+ column "lc_dagster__job_name" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.job_name`, 'String')"
+ }
+ column "lc_dagster__run_id" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.run_id`, 'String')"
+ }
+ column "lc_dagster__owner" {
+ type = "String"
+ alias = "CAST(log_comment.`dagster.tags.owner`, 'String')"
+ }
+ column "lc_modifiers" {
+ type = "String"
+ alias = "if(is_initial_query, JSONExtractRaw(toString(log_comment), 'modifiers'), '')"
+ }
+ column "ProfileEvents2" {
+ type = "JSON(max_dynamic_paths=0, OSCPUVirtualTimeMicroseconds UInt64, ReadBufferFromS3Bytes UInt64, RealTimeMicroseconds UInt64, S3AbortMultipartUpload UInt64, S3Clients UInt64, S3CompleteMultipartUpload UInt64, S3CopyObject UInt64, S3CreateMultipartUpload UInt64, S3DeleteObjects UInt64, S3GetObject UInt64, S3GetObjectAttributes UInt64, S3HeadObject UInt64, S3ListObjects UInt64, S3PutObject UInt64, S3UploadPart UInt64, S3UploadPartCopy UInt64, WriteBufferFromS3Bytes UInt64)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/noshard/posthog.sharded_query_log_archive"
+ replica_name = "{replica}-{shard}"
+ }
+ }
+
+ table "sharded_tophog" {
+ order_by = ["pipeline", "lane", "metric", "timestamp", "key"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(30)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "metric" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ default = "'sum'"
+ }
+ column "key" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ column "count" {
+ type = "UInt64"
+ default = "0"
+ }
+ column "pipeline" {
+ type = "LowCardinality(String)"
+ }
+ column "lane" {
+ type = "LowCardinality(String)"
+ }
+ column "labels" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/tables/ops/{shard}/posthog.tophog_new"
+ replica_name = "{replica}"
+ }
+ }
+
+ table "writable_query_log_archive" {
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "JSON(max_dynamic_paths=256, access_method LowCardinality(String), alert_config_id String, api_key_label String, api_key_mask String, batch_export_id String, chargeable Bool, client_query_id String, cohort_id Int64, `dagster.job_name` String, `dagster.run_id` String, `dagster.tags.owner` String, dashboard_id Int64, experiment_feature_flag_key String, experiment_id Int64, feature LowCardinality(String), id String, insight_id Int64, is_impersonated Bool, kind LowCardinality(String), name String, org_id String, person_on_events_mode LowCardinality(String), product LowCardinality(String), query_type LowCardinality(String), request_name String, route_id String, service_name String, session_id String, table_id String, team_id Int64, `temporal.activity_id` String, `temporal.activity_type` String, `temporal.attempt` Int64, `temporal.workflow_id` String, `temporal.workflow_namespace` String, `temporal.workflow_run_id` String, `temporal.workflow_type` String, user_id Int64, warehouse_query Bool, workflow LowCardinality(String), workload LowCardinality(String), SKIP cache_key, SKIP filter, SKIP hogql_features, SKIP http_referer, SKIP http_request_id, SKIP http_user_agent, SKIP query_settings, SKIP timings, SKIP user_email)"
+ }
+ column "ProfileEvents" {
+ type = "Map(String, UInt64)"
+ }
+ engine "distributed" {
+ cluster_name = "ops"
+ remote_database = "posthog"
+ remote_table = "query_log_archive_buffer"
+ }
+ }
+
+ materialized_view "metrics_label_index_from_series_mv" {
+ to_table = "posthog.metrics_label_index"
+ query = "SELECT team_id, metric_name, tupleElement(label_pair, 1) AS label_name, tupleElement(label_pair, 2) AS label_value, id FROM posthog.metrics_series ARRAY JOIN JSONExtractKeysAndValues(labels_json, 'String') AS label_pair"
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "label_name" {
+ type = "LowCardinality(String)"
+ }
+ column "label_value" {
+ type = "String"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ }
+
+ materialized_view "ops_query_log_archive_mv" {
+ to_table = "posthog.writable_query_log_archive"
+ query = "SELECT hostname, user, query_id, initial_query_id, is_initial_query, type, event_date, event_time, event_time_microseconds, query_start_time, query_start_time_microseconds, query_duration_ms, read_rows, read_bytes, written_rows, written_bytes, result_rows, result_bytes, memory_usage, peak_threads_usage, current_database, query, formatted_query, normalized_query_hash, query_kind, exception_code, exception, stack_trace, JSONExtractInt(log_comment, 'team_id') AS team_id, if(isValidJSON(log_comment), log_comment, '{}') AS log_comment, ProfileEvents FROM system.query_log WHERE type != 'QueryStart'"
+ column "hostname" {
+ type = "LowCardinality(String)"
+ }
+ column "user" {
+ type = "LowCardinality(String)"
+ }
+ column "query_id" {
+ type = "String"
+ }
+ column "initial_query_id" {
+ type = "String"
+ }
+ column "is_initial_query" {
+ type = "UInt8"
+ }
+ column "type" {
+ type = "Enum8('QueryStart'=1, 'QueryFinish'=2, 'ExceptionBeforeStart'=3, 'ExceptionWhileProcessing'=4)"
+ }
+ column "event_date" {
+ type = "Date"
+ }
+ column "event_time" {
+ type = "DateTime"
+ }
+ column "event_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_start_time" {
+ type = "DateTime"
+ }
+ column "query_start_time_microseconds" {
+ type = "DateTime64(6)"
+ }
+ column "query_duration_ms" {
+ type = "UInt64"
+ }
+ column "read_rows" {
+ type = "UInt64"
+ }
+ column "read_bytes" {
+ type = "UInt64"
+ }
+ column "written_rows" {
+ type = "UInt64"
+ }
+ column "written_bytes" {
+ type = "UInt64"
+ }
+ column "result_rows" {
+ type = "UInt64"
+ }
+ column "result_bytes" {
+ type = "UInt64"
+ }
+ column "memory_usage" {
+ type = "UInt64"
+ }
+ column "peak_threads_usage" {
+ type = "UInt64"
+ }
+ column "current_database" {
+ type = "LowCardinality(String)"
+ }
+ column "query" {
+ type = "String"
+ }
+ column "formatted_query" {
+ type = "String"
+ }
+ column "normalized_query_hash" {
+ type = "UInt64"
+ }
+ column "query_kind" {
+ type = "LowCardinality(String)"
+ }
+ column "exception_code" {
+ type = "Int32"
+ }
+ column "exception" {
+ type = "String"
+ }
+ column "stack_trace" {
+ type = "String"
+ }
+ column "team_id" {
+ type = "Int64"
+ }
+ column "log_comment" {
+ type = "String"
+ }
+ column "ProfileEvents" {
+ type = "Map(LowCardinality(String), UInt64)"
+ }
+ }
+
+ view "custom_metrics" {
+ query = "SELECT * REPLACE(toFloat64(value) AS value) FROM posthog.custom_metrics_test UNION ALL SELECT * REPLACE(toFloat64(value) AS value) FROM posthog.custom_metrics_replication_queue UNION ALL SELECT * REPLACE(toFloat64(value) AS value) FROM posthog.custom_metrics_server_crash UNION ALL SELECT * FROM posthog.custom_metrics_table_sizes UNION ALL SELECT * REPLACE(toFloat64(value) AS value) FROM posthog.custom_metrics_part_counts UNION ALL SELECT * REPLACE(toFloat64(value) AS value) FROM posthog.custom_metrics_dictionaries UNION ALL SELECT 'ClickHouseCustomMetric_S3DiskBytesUsed' AS name, map('instance', hostname(), 'disk', disk_name) AS labels, toFloat64(sum(bytes_on_disk)) AS value, 'Bytes currently used by ClickHouse parts on S3-backed disks on this node' AS help, 'gauge' AS type FROM system.parts WHERE disk_name IN ('s3disk', 'cache') GROUP BY disk_name UNION ALL SELECT 'ClickHouseCustomMetric_MergeFailures15m' AS name, map('instance', hostname()) AS labels, toFloat64(count()) AS value, 'Number of failed merge operations in the last 15 minutes' AS help, 'gauge' AS type FROM system.part_log WHERE (event_time >= (now() - toIntervalMinute(15))) AND (event_type = 'MergeParts') AND (error > 0) AND (merge_reason != 'NotAMerge') AND (error != 40) UNION ALL SELECT 'ClickHouseCustomMetric_MergeRetriesMaxPerTable15m' AS name, map('instance', hostname()) AS labels, toFloat64(max(cnt)) AS value, 'Max failed merge retries for any single table in the last 15 minutes' AS help, 'gauge' AS type FROM (SELECT count() AS cnt FROM system.part_log WHERE (event_time >= (now() - toIntervalMinute(15))) AND (event_type = 'MergeParts') AND (error > 0) AND (merge_reason != 'NotAMerge') AND (error != 40) GROUP BY database, `table`, partition_id)"
+ }
+
+ view "custom_metrics_backups" {
+ query = "WITH ['ClickHouseCustomMetric_BackupFailed', 'ClickHouseCustomMetric_BackupSuccess', 'ClickHouseCustomMetric_BackupCancelled', 'ClickHouseCustomMetric_BackupAttempts'] AS names, [toInt64(countIf(status = 'BACKUP_FAILED')), toInt64(countIf(status = 'BACKUP_CREATED')), toInt64(countIf(status = 'BACKUP_CANCELLED')), toInt64(countIf(status = 'CREATING_BACKUP'))] AS values, ['Number of failed backups', 'Number of successful backups', 'Number of cancelled backups', 'Number of backup attempts'] AS descriptions, ['gauge', 'gauge', 'gauge', 'gauge'] AS types, arrayJoin(arrayZip(names, values, descriptions, types)) AS tpl SELECT tpl.1 AS name, map('instance', hostname()) AS labels, tpl.2 AS value, tpl.3 AS help, tpl.4 AS type FROM system.backup_log WHERE event_date = today() GROUP BY event_date"
+ }
+
+ view "custom_metrics_dictionaries" {
+ query = "SELECT 'ClickHouseCustomMetric_DictionariesFailed' AS name, map('instance', hostname(), 'database', d.database, 'dictionary', d.dict_name, 'uuid', toString(d.uuid), 'status', toString(d.status)) AS labels, toUInt64(1) AS value, 'Dictionary is in FAILED or FAILED_AND_RELOADING status' AS help, 'gauge' AS type FROM (SELECT name AS dict_name, database, uuid, status FROM system.dictionaries WHERE status IN ('FAILED', 'FAILED_AND_RELOADING')) AS d"
+ }
+
+ view "custom_metrics_part_counts" {
+ query = "SELECT 'ClickHouseCustomMetric_MaxPartCountPerPartition' AS name, map('instance', hostname(), 'database', database, 'table', `table`, 'partition', partition) AS labels, part_count AS value, 'Maximum number of active parts for any partition in a PostHog table' AS help, 'gauge' AS type FROM (SELECT database, `table`, partition, count() AS part_count FROM system.parts WHERE active AND (database = 'posthog') GROUP BY database, `table`, partition ORDER BY database ASC, `table` ASC, part_count DESC, partition ASC LIMIT 1 BY database, `table`)"
+ }
+
+ view "custom_metrics_replication_queue" {
+ query = "WITH ['ClickHouseCustomMetric_ReplicationQueueStuckEntries', 'ClickHouseCustomMetric_ReplicationQueueMaxPostponedEntrySeconds', 'ClickHouseCustomMetric_ReplicationQueueMaxErrorEntrySeconds'] AS names, [toInt64(countIf(create_time < (now() - toIntervalDay(15)))), maxIf(dateDiff('seconds', create_time, last_postpone_time), last_postpone_time != '1970-01-01'), maxIf(dateDiff('seconds', create_time, last_exception_time), (last_exception_time != '1970-01-01') AND (last_exception_time > (now() - toIntervalMinute(5))))] AS values, ['Number of entries that have been in the replication queue for more than 15 days', 'Maximum number of seconds that an entry has been postponed', 'Maximum number of seconds that an entry has been in error'] AS descriptions, ['gauge', 'gauge', 'gauge'] AS types, arrayJoin(arrayZip(names, values, descriptions, types)) AS tpl SELECT tpl.1 AS name, map('table', `table`, 'instance', hostname()) AS labels, tpl.2 AS value, tpl.3 AS help, tpl.4 AS type FROM system.replication_queue GROUP BY `table` HAVING value > 0"
+ }
+
+ view "custom_metrics_server_crash" {
+ query = "SELECT 'ClickHouseCustomMetric_ServerCrash' AS name, map('instance', hostname()) AS labels, count() AS value, 'Number of server crashes for current date' AS help, 'gauge' AS type FROM system.crash_log WHERE event_date = today() GROUP BY hostname()"
+ }
+
+ view "custom_metrics_table_sizes" {
+ query = "SELECT 'ClickHouseCustomMetric_TableTotalBytes' AS name, map('instance', hostname(), 'database', database, 'table', `table`) AS labels, CAST(total_bytes, 'Float64') AS value, 'Size of a database table on a given node (need a sum for sharded)' AS help, 'gauge' AS type FROM system.tables WHERE (database NOT IN ('INFORMATION_SCHEMA', 'information_schema')) AND (total_bytes IS NOT NULL)"
+ }
+
+ view "custom_metrics_test" {
+ query = "SELECT 'ClickHouseCustomMetric_Test' AS name, map('instance', hostname()) AS labels, 1 AS value, 'Test to check that the metric endpoint is working' AS help, 'gauge' AS type"
+ }
+
+ view "daily_aggregated_query_log_archive" {
+ query = "SELECT event_date AS day, team_id, user, current_database, query_kind, lc_kind, lc_access_method, lc_query_type, lc_product, lc_name, lc_feature, lc_query__kind, lc_api_key_label, count() AS query_count, sum(read_bytes) AS read_bytes, sum(read_rows) AS read_rows, sum(query_duration_ms) AS query_duration_ms, sum(ProfileEvents_OSCPUVirtualTimeMicroseconds) AS cpu_microseconds, countIf(exception_code != 0) AS error_count, countIf(exception_code IN (159, 160, 241)) AS timeout_oom_count FROM posthog.sharded_query_log_archive WHERE is_initial_query AND (event_date < today()) GROUP BY day, team_id, user, current_database, query_kind, lc_kind, lc_access_method, lc_query_type, lc_product, lc_name, lc_feature, lc_query__kind, lc_api_key_label"
+ }
+}
diff --git a/posthog/clickhouse/hcl/ops/prod/ops.hcl b/posthog/clickhouse/hcl/ops/prod/ops.hcl
new file mode 100644
index 000000000000..55f51a92d392
--- /dev/null
+++ b/posthog/clickhouse/hcl/ops/prod/ops.hcl
@@ -0,0 +1,234 @@
+# OPS prod layer — metrics suite, identical across prod-us and prod-eu
+#
+# Generated/maintained as the declarative source of truth for the OPS ClickHouse cluster.
+# Resolve with: hclexp load -layer <base>,<...>
+
+database "posthog" {
+ # Shared shape for the per-env sharded_tophog tables. prod-us and prod-eu
+ # differ only in the engine zoo_path (tophog_new vs tophog), so the columns
+ # and table settings live here and each env layer instantiates a concrete
+ # sharded_tophog via `extend`, supplying just its engine block.
+ table "sharded_tophog_base" {
+ abstract = true
+ order_by = ["pipeline", "lane", "metric", "timestamp", "key"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ ttl = "toDate(timestamp) + toIntervalDay(30)"
+ settings = {
+ index_granularity = "8192"
+ ttl_only_drop_parts = "1"
+ }
+ column "timestamp" {
+ type = "DateTime64(6, 'UTC')"
+ }
+ column "metric" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ default = "'sum'"
+ }
+ column "key" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ column "count" {
+ type = "UInt64"
+ default = "0"
+ }
+ column "pipeline" {
+ type = "LowCardinality(String)"
+ }
+ column "lane" {
+ type = "LowCardinality(String)"
+ }
+ column "labels" {
+ type = "Map(LowCardinality(String), String)"
+ }
+ }
+ table "metrics_exemplars" {
+ order_by = ["team_id", "id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ settings = {
+ index_granularity = "1024"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ column "labels_json" {
+ type = "String"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.metrics_exemplars"
+ replica_name = "{replica}"
+ }
+ }
+ table "metrics_histograms" {
+ order_by = ["team_id", "id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ settings = {
+ index_granularity = "1024"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ column "histogram" {
+ type = "String"
+ }
+ column "version" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.metrics_histograms"
+ replica_name = "{replica}"
+ version_column = "version"
+ }
+ }
+ table "metrics_label_index" {
+ order_by = ["team_id", "metric_name", "label_name", "label_value", "id"]
+ settings = {
+ deduplicate_merge_projection_mode = "rebuild"
+ index_granularity = "1024"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "label_name" {
+ type = "LowCardinality(String)"
+ }
+ column "label_value" {
+ type = "String"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.metrics_label_index"
+ replica_name = "{replica}"
+ }
+ }
+ table "metrics_metadata" {
+ order_by = ["team_id", "metric_family_name"]
+ settings = {
+ index_granularity = "1024"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "metric_family_name" {
+ type = "LowCardinality(String)"
+ }
+ column "type" {
+ type = "LowCardinality(String)"
+ }
+ column "unit" {
+ type = "String"
+ }
+ column "help" {
+ type = "String"
+ }
+ column "updated_at" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ engine "replicated_replacing_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.metrics_metadata"
+ replica_name = "{replica}"
+ version_column = "updated_at"
+ }
+ }
+ table "metrics_samples" {
+ order_by = ["team_id", "metric_name", "id", "timestamp"]
+ partition_by = "toYYYYMMDD(timestamp)"
+ settings = {
+ index_granularity = "1024"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "timestamp" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ column "value" {
+ type = "Float64"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.metrics_samples"
+ replica_name = "{replica}"
+ }
+ }
+ table "metrics_series" {
+ order_by = ["team_id", "metric_name", "id"]
+ settings = {
+ index_granularity = "1024"
+ }
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "labels_json" {
+ type = "String"
+ }
+ column "min_time" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ column "max_time" {
+ type = "DateTime64(3, 'UTC')"
+ }
+ engine "replicated_merge_tree" {
+ zoo_path = "/clickhouse/ops/tables/{shard}/posthog.metrics_series"
+ replica_name = "{replica}"
+ }
+ }
+ materialized_view "metrics_label_index_from_series_mv" {
+ to_table = "posthog.metrics_label_index"
+ query = "SELECT team_id, metric_name, tupleElement(label_pair, 1) AS label_name, tupleElement(label_pair, 2) AS label_value, id FROM posthog.metrics_series ARRAY JOIN JSONExtractKeysAndValues(labels_json, 'String') AS label_pair"
+ column "team_id" {
+ type = "UInt64"
+ }
+ column "metric_name" {
+ type = "LowCardinality(String)"
+ }
+ column "label_name" {
+ type = "LowCardinality(String)"
+ }
+ column "label_value" {
+ type = "String"
+ }
+ column "id" {
+ type = "UInt64"
+ }
+ }
+}
diff --git a/posthog/temporal/tests/product_analytics/__snapshots__/test_upgrade_queries_workflow.ambr b/posthog/temporal/tests/product_analytics/__snapshots__/test_upgrade_queries_workflow.ambr
index 0839c952c78f..a1c0325ab25a 100644
--- a/posthog/temporal/tests/product_analytics/__snapshots__/test_upgrade_queries_workflow.ambr
+++ b/posthog/temporal/tests/product_analytics/__snapshots__/test_upgrade_queries_workflow.ambr
@@ -11,6 +11,14 @@
OR query @? '$.** ? (
@.kind == "InsightVizNode" &&
(!exists(@.version) || @.version == null || @.version < 4)
+ )'
+ OR query @? '$.** ? (
+ @.kind == "RetentionQuery" &&
+ (!exists(@.version) || @.version == null || @.version < 2)
+ )'
+ OR query @? '$.** ? (
+ @.kind == "StickinessQuery" &&
+ (!exists(@.version) || @.version == null || @.version < 2)
)'
OR query @? '$.** ? (
@.kind == "TrendsQuery" &&