|
| 1 | +-- Breaking change: drop and recreate runtime_logs_raw_v1 to add app_id to ORDER BY. |
| 2 | +-- ClickHouse doesn't allow altering the ORDER BY of a MergeTree table. |
| 3 | +-- All existing log data will be lost — acceptable since logs are ephemeral. |
| 4 | + |
| 5 | +DROP TABLE IF EXISTS default.runtime_logs_raw_v1; |
| 6 | + |
| 7 | +CREATE TABLE IF NOT EXISTS default.runtime_logs_raw_v1 |
| 8 | +( |
| 9 | + `time` Int64 CODEC(Delta, LZ4), |
| 10 | + `inserted_at` Int64 DEFAULT toUnixTimestamp64Milli(now64(3)), |
| 11 | + `severity` LowCardinality(String), |
| 12 | + `message` String CODEC(ZSTD(1)), |
| 13 | + `workspace_id` String CODEC(ZSTD(1)), |
| 14 | + `project_id` String CODEC(ZSTD(1)), |
| 15 | + `environment_id` String CODEC(ZSTD(1)), |
| 16 | + `app_id` String DEFAULT '' CODEC(ZSTD(1)), |
| 17 | + `deployment_id` String CODEC(ZSTD(1)), |
| 18 | + `k8s_pod_name` String CODEC(ZSTD(1)), |
| 19 | + `region` LowCardinality(String), |
| 20 | + `attributes` JSON CODEC(ZSTD(1)), |
| 21 | + `attributes_text` String MATERIALIZED toJSONString(attributes) CODEC(ZSTD(1)), |
| 22 | + `expires_at` DateTime64(3) DEFAULT now64(3) + INTERVAL 90 DAY, |
| 23 | + INDEX idx_workspace_id workspace_id TYPE bloom_filter(0.001) GRANULARITY 1, |
| 24 | + INDEX idx_deployment_id deployment_id TYPE bloom_filter(0.001) GRANULARITY 1, |
| 25 | + INDEX idx_message message TYPE tokenbf_v1(32768, 3, 0) GRANULARITY 1, |
| 26 | + INDEX idx_attributes_text attributes_text TYPE tokenbf_v1(32768, 3, 0) GRANULARITY 1 |
| 27 | +) |
| 28 | +ENGINE = MergeTree() |
| 29 | +PARTITION BY toDate(fromUnixTimestamp64Milli(inserted_at)) |
| 30 | +ORDER BY (workspace_id, project_id, environment_id, app_id, time, deployment_id) |
| 31 | +TTL expires_at + INTERVAL 7 DAY |
| 32 | +SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1; |
0 commit comments