Skip to content

Commit 1bb80b5

Browse files
committed
feat: add app_id to ClickHouse runtime_logs and dev Vector config
- ClickHouse migration adds app_id column to runtime_logs_raw_v1 - Schema reference updated to include app_id - Dev Vector config extracts unkey.com/app.id pod label
1 parent f2003b2 commit 1bb80b5

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

dev/k8s/manifests/vector-logs.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ data:
119119
.project_id = .kubernetes.pod_labels."unkey.com/project.id" || ""
120120
.environment_id = .kubernetes.pod_labels."unkey.com/environment.id" || ""
121121
.deployment_id = .kubernetes.pod_labels."unkey.com/deployment.id" || ""
122+
.app_id = .kubernetes.pod_labels."unkey.com/app.id" || ""
122123
123124
# Keep k8s metadata
124125
.k8s_pod_name = .kubernetes.pod_name || ""
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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;

pkg/clickhouse/schema/023_runtime_logs_raw_v1.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ CREATE TABLE IF NOT EXISTS default.runtime_logs_raw_v1
1717
`workspace_id` String CODEC(ZSTD(1)),
1818
`project_id` String CODEC(ZSTD(1)),
1919
`environment_id` String CODEC(ZSTD(1)),
20+
`app_id` String DEFAULT '' CODEC(ZSTD(1)),
2021
`deployment_id` String CODEC(ZSTD(1)),
2122

2223
-- K8s metadata (pod name for identifying specific replica)
@@ -43,6 +44,6 @@ CREATE TABLE IF NOT EXISTS default.runtime_logs_raw_v1
4344
)
4445
ENGINE = MergeTree()
4546
PARTITION BY toDate(fromUnixTimestamp64Milli(inserted_at))
46-
ORDER BY (workspace_id, project_id, environment_id, time, deployment_id)
47+
ORDER BY (workspace_id, project_id, environment_id, app_id, time, deployment_id)
4748
TTL expires_at + INTERVAL 7 DAY
4849
SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;

0 commit comments

Comments
 (0)