perf(analytics): materialize git observations as sorted table - #1736
Conversation
The observation pipeline (FINAL dedup, joins, ten measure branches) ran on every metric query, though its silver inputs only change when a connector sync runs dbt — identical results recomputed per query, multiplied by request concurrency against a fixed memory budget. Build it once per dbt run instead; metric queries become index-pruned scans over the ordering key that mirrors the runtime filter shape (source_key, measure_key, entity_id, metric_date). Result parity verified; rebuild rides the existing sync-triggered dbt selection (tag:gitlab+). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Aleksandr Barkhatov <pm@aleks.bar>
📝 WalkthroughWalkthroughThe git metric observations dbt model changes from a view to an ordered MergeTree table. Its documentation now describes dbt-build execution, index-pruned reads, retroactive changes, and revised deduplication memory behavior. ChangesGit metric observation storage
Estimated code review effort: 2 (Simple) | ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/ingestion/gold/git_metric_observations.sql (2)
2-4: 🩺 Stability & Availability | 🔵 TrivialConsider adding a
PARTITION BYexpression for data lifecycle management.No
partition_byis configured, so all data resides in a single partition. Whilemetric_dateinorder_byenables granule-level index pruning for date-range queries, a partition expression (e.g.,toYYYYMM(metric_date)) would also enable partition-level pruning and efficient partition drops for data retention. This is especially relevant now that the table is materialized and accumulates full-history data per build.This can be deferred if data volume is manageable or retention is handled externally.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/ingestion/gold/git_metric_observations.sql` around lines 2 - 4, Consider adding a partition expression to the materialized table configuration, using the existing metric_date column (for example, monthly partitioning via toYYYYMM(metric_date)) alongside order_by. If retention or data volume does not require partition management, document or preserve the decision to defer this change.
2-4: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winMove
tenant_idahead ofsource_keyinorder_by—tenant_idis the tenant-isolation field, whilesource_keyis fixed to'git'and adds no selectivity. Leading withtenant_idgives tenant-scoped reads better pruning.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/ingestion/gold/git_metric_observations.sql` around lines 2 - 4, The order_by configuration in the git metric observations table currently leads with the non-selective source_key. Update it to place tenant_id before source_key, preserving the remaining columns and their order to improve tenant-scoped read pruning.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/ingestion/gold/git_metric_observations.sql`:
- Around line 2-4: Consider adding a partition expression to the materialized
table configuration, using the existing metric_date column (for example, monthly
partitioning via toYYYYMM(metric_date)) alongside order_by. If retention or data
volume does not require partition management, document or preserve the decision
to defer this change.
- Around line 2-4: The order_by configuration in the git metric observations
table currently leads with the non-selective source_key. Update it to place
tenant_id before source_key, preserving the remaining columns and their order to
improve tenant-scoped read pruning.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 46cedcec-255f-48a6-807c-32f869561ad8
📒 Files selected for processing (1)
src/ingestion/gold/git_metric_observations.sql
git_metric_observationsran its full pipeline (FINAL dedup, joins, ten measure branches) on every metric query, though silver inputs only change when a connector sync runs dbt. Identical results recomputed per query, multiplied by request concurrency, against a fixed ClickHouse memory budget — the source of the metric-results OOM failures.Materialize it as a MergeTree table instead:
(source_key, measure_key, entity_id, metric_date)mirrors the runtime filter shape, so single-measure queries read index-pruned ranges.tag:gitlab+); dbt handles the view-to-table transition on the next run.Result parity verified (row-level checksum); model dbt tests pass.
Refs #1733.
🤖 Generated with Claude Code
Summary by CodeRabbit