Skip to content

The only tool you need to know what is happening and how to fix it.

better DB handling

dduxc92848ac1057
diff --git a/backend/app/migrations/ch/0002_created_metric_records.up.sql b/backend/app/migrations/ch/0002_created_metric_records.up.sql
index a02674b3..bf35f643 100644
--- a/backend/app/migrations/ch/0002_created_metric_records.up.sql
+++ b/backend/app/migrations/ch/0002_created_metric_records.up.sql
@@ -1,7 +1,12 @@
CREATE TABLE IF NOT EXISTS metric_records (
+ project_id LowCardinality(String) DEFAULT '00000000-0000-0000-0000-000000000001',
name LowCardinality(String),
value Float64,
- recorded_at DateTime
+ recorded_at DateTime,
+ server_name LowCardinality(String) DEFAULT '',
+
+ INDEX idx_server_name server_name TYPE bloom_filter(0.01) GRANULARITY 4
) ENGINE = MergeTree()
-PARTITION BY toYYYYMM(recorded_at)
-ORDER BY (recorded_at, name);
+PARTITION BY toYYYYMMDD(recorded_at)
+ORDER BY (project_id, name, recorded_at)
+SETTINGS index_granularity = 8192
diff --git a/backend/app/migrations/ch/0003_created_exception_stack_traces.up.sql b/backend/app/migrations/ch/0003_created_exception_stack_traces.up.sql
index 5168ab6e..4390804b 100644
--- a/backend/app/migrations/ch/0003_created_exception_stack_traces.up.sql
+++ b/backend/app/migrations/ch/0003_created_exception_stack_traces.up.sql
@@ -1,9 +1,22 @@
-
CREATE TABLE IF NOT EXISTS exception_stack_traces (
+ id String DEFAULT '',
+ project_id LowCardinality(String) DEFAULT '00000000-0000-0000-0000-000000000001',
transaction_id Nullable(String),
+ transaction_type LowCardinality(String) DEFAULT 'endpoint',
exception_hash String,
stack_trace String,
- recorded_at DateTime
+ recorded_at DateTime,
+ scope String DEFAULT '{}',
+ app_version LowCardinality(String) DEFAULT '',
+ server_name LowCardinality(String) DEFAULT '',
+ is_message UInt8 DEFAULT 0,
+
+ INDEX idx_exception_hash exception_hash TYPE bloom_filter(0.01) GRANULARITY 4,
+ INDEX idx_transaction_id transaction_id TYPE bloom_filter(0.01) GRANULARITY 4,
+ INDEX idx_is_message is_message TYPE set(2) GRANULARITY 1,
+ INDEX idx_id id TYPE bloom_filter(0.001) GRANULARITY 1,
+ INDEX idx_stack_trace stack_trace TYPE tokenbf_v1(10240, 3, 0) GRANULARITY 4
) ENGINE = MergeTree()
-PARTITION BY toYYYYMM(recorded_at)
-ORDER BY (recorded_at, exception_hash);
+PARTITION BY toYYYYMMDD(recorded_at)
+ORDER BY (project_id, recorded_at, exception_hash)
+SETTINGS index_granularity = 8192
diff --git a/backend/app/migrations/ch/0004_created_projects.up.sql b/backend/app/migrations/ch/0004_created_projects.up.sql
index 22c29a91..9938831a 100644
--- a/backend/app/migrations/ch/0004_created_projects.up.sql
+++ b/backend/app/migrations/ch/0004_created_projects.up.sql
@@ -2,6 +2,11 @@ CREATE TABLE IF NOT EXISTS projects (
id String,
name String,
token String,
- created_at DateTime DEFAULT now()
+ framework LowCardinality(String) DEFAULT 'custom',
+ created_at DateTime DEFAULT now(),
+
+ INDEX idx_token token TYPE bloom_filter(0.001) GRANULARITY 1,
+ INDEX idx_id id TYPE bloom_filter(0.001) GRANULARITY 1
) ENGINE = MergeTree()
-ORDER BY (created_at, id)
+ORDER BY (id)
+SETTINGS index_granularity = 8192
diff --git a/backend/app/migrations/ch/0019_create_segments.up.sql b/backend/app/migrations/ch/0019_create_segments.up.sql
index f35f9f7d..78d12250 100644
--- a/backend/app/migrations/ch/0019_create_segments.up.sql
+++ b/backend/app/migrations/ch/0019_create_segments.up.sql
@@ -1,11 +1,14 @@
CREATE TABLE IF NOT EXISTS segments (
id String,
transaction_id String,
- project_id String,
- name String,
+ project_id LowCardinality(String),
+ name LowCardinality(String),
start_time DateTime64(6),
duration Int64,
- recorded_at DateTime
+ recorded_at DateTime,
+
+ INDEX idx_transaction_id transaction_id TYPE bloom_filter(0.001) GRANULARITY 1
) ENGINE = MergeTree()
-PARTITION BY toYYYYMM(recorded_at)
+PARTITION BY toYYYYMMDD(recorded_at)
ORDER BY (project_id, transaction_id, start_time)
+SETTINGS index_granularity = 8192
diff --git a/backend/app/migrations/ch/0020_create_endpoints.up.sql b/backend/app/migrations/ch/0020_create_endpoints.up.sql
index 56f7d72a..d55f6cf4 100644
--- a/backend/app/migrations/ch/0020_create_endpoints.up.sql
+++ b/backend/app/migrations/ch/0020_create_endpoints.up.sql
@@ -1,15 +1,20 @@
CREATE TABLE IF NOT EXISTS endpoints (
id String,
- project_id String,
- endpoint String,
+ project_id LowCardinality(String),
+ endpoint LowCardinality(String),
duration Int64,
recorded_at DateTime,
- status_code Int32,
+ status_code Int16,
body_size Int32,
client_ip String,
scope String DEFAULT '{}',
- app_version String DEFAULT '',
- server_name String DEFAULT ''
+ app_version LowCardinality(String) DEFAULT '',
+ server_name LowCardinality(String) DEFAULT '',
+
+ INDEX idx_endpoint endpoint TYPE bloom_filter(0.01) GRANULARITY 4,
+ INDEX idx_status_code status_code TYPE set(100) GRANULARITY 4,
+ INDEX idx_id id TYPE bloom_filter(0.001) GRANULARITY 1
) ENGINE = MergeTree()
-PARTITION BY toYYYYMM(recorded_at)
-ORDER BY (project_id, recorded_at, endpoint);
+PARTITION BY toYYYYMMDD(recorded_at)
+ORDER BY (project_id, recorded_at, endpoint)
+SETTINGS index_granularity = 8192
diff --git a/backend/app/migrations/ch/0021_create_tasks.up.sql b/backend/app/migrations/ch/0021_create_tasks.up.sql
index 2157d8a1..8056e640 100644
--- a/backend/app/migrations/ch/0021_create_tasks.up.sql
+++ b/backend/app/migrations/ch/0021_create_tasks.up.sql
@@ -1,13 +1,17 @@
CREATE TABLE IF NOT EXISTS tasks (
id String,
- project_id String,
- task_name String,
+ project_id LowCardinality(String),
+ task_name LowCardinality(String),
duration Int64,
recorded_at DateTime,
client_ip String,
scope String DEFAULT '{}',
- app_version String DEFAULT '',
- server_name String DEFAULT ''
+ app_version LowCardinality(String) DEFAULT '',
+ server_name LowCardinality(String) DEFAULT '',
+
+ INDEX idx_task_name task_name TYPE bloom_filter(0.01) GRANULARITY 4,
+ INDEX idx_id id TYPE bloom_filter(0.001) GRANULARITY 1
) ENGINE = MergeTree()
-PARTITION BY toYYYYMM(recorded_at)
-ORDER BY (project_id, recorded_at, task_name);
+PARTITION BY toYYYYMMDD(recorded_at)
+ORDER BY (project_id, recorded_at, task_name)
+SETTINGS index_granularity = 8192