perf(analytics): precompute provider state - #2228
Conversation
Provider inventory rebuilt per-ID latest-row state across tens of millions of metric-stream records and exceeded the worker timeout. Add an aggregate projection; historical parts still require explicit post-deploy materialization.\n\nRefs DOFEK-SERVER-5A
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
|
🤖 Review skipped: Repository rate limit exceeded. Free accounts are limited to 2 reviews per 4 hours per repository. Upgrade to a paid plan for unlimited reviews. |
|
Warning Review limit reached
Next review available in: 2 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (12)
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 |
Reviewer's GuideAdds a ClickHouse aggregate projection that precomputes latest provider-level deletion state for metric_stream rows, wires provider_stats to prefer this projection with in-order aggregation, and introduces regression tests plus documentation and migration wiring to ensure correct rollout and bounded-memory exact counts. Flow diagram for migration 0061 provider current-state projection rolloutflowchart TD
Dev[Developer creates migration 0061_provider_current_state_projection] --> Deploy[Deploy runs ALTER TABLE ingest.metric_stream ADD PROJECTION by_provider_current_state]
Deploy --> NewParts[New metric_stream parts populate projection automatically]
Operator[Operator runs MATERIALIZE PROJECTION by_provider_current_state] --> Materialize[ClickHouse rewrites historical parts]
Materialize --> VerifyParts[Check system.parts for missing_projection_parts = 0]
VerifyParts --> ProviderStatsQuery[provider_stats query with preferred_optimize_projection_name = by_provider_current_state]
ProviderStatsQuery --> BoundedCount[Exact metric_stream counts within bounded memory]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
PR Summary by Qodoperf(analytics): precompute provider current-state via ClickHouse projection
AI Description
Diagram
High-Level Assessment
Files changed (12)
|
|
Storybook previews for This comment updates automatically on each PR push. |
Code Review by Qodo
Context used✅ Compliance rules (platform):
181 rules✅ Skills:
fix-provider, write-tests, cloudflare 1.
|
|
LGTM! This PR adds the Summary of Changes:
🤖 Reviewed by codereviewbot.ai - Catch bugs before your team does. |
Summary
provider_statsprefer the projection while retaining the existing exact fallback semanticsRoot cause
Dirty-provider discovery was already bounded to one provider, but the exact metric-stream count still rebuilt an
argMaxhash entry for each of Apple Motion's 33.7 million record IDs. That query exceeded the unchanged four-minute worker ceiling. The existing provider projection pruned the range but did not precompute current state.Validation
DBT_CLICKHOUSE_SCHEMA=analytics_lint pnpm lintpnpm tsc --noEmitcd packages/server && pnpm tsc --noEmitcd packages/web && pnpm tsc --noEmitpnpm test(14,097 passed)pnpm setup-dbpnpm analytics:build(38 models)Production rollout
Migration
0061adds the projection definition only. After deployment, materializeby_provider_current_stateexplicitly, monitorsystem.mutations, verify no active part lacks the projection, and observe a complete analytics/cache cycle before resolving Sentry. No timeout or retry ceiling changes are included.Summary by Sourcery
Introduce a ClickHouse aggregate projection and query settings to precompute and preferentially use provider current-state metric-stream counts, improving performance and documenting the associated production incident and rollout.
Enhancements:
Documentation:
Tests:
Summary by cubic
Precomputes provider current-state for metric-stream records with a ClickHouse projection and makes
analytics.provider_statsprefer it, preventing provider inventory recount timeouts (refs DOFEK-SERVER-5A).New Features
ingest.metric_streamaggregate projectionby_provider_current_statethat stores mergeableargMax(is_deleted, (version, ingested_at))per(user_id, provider_id, id); included in ClickHouse bootstrap and migration registry.analytics.provider_statsto prefer the projection withoptimize_aggregation_in_order = 1andpreferred_optimize_projection_name = 'by_provider_current_state', retaining exact fallback semantics.Migration
0061_provider_current_state_projectionadds the projection definition only.ALTER TABLE ingest.metric_stream MATERIALIZE PROJECTION by_provider_current_state;then monitorsystem.mutationsand verify no active parts lack the projection.Written for commit dcaf177. Summary will update on new commits.