feat: Keep host on aggregated API usage buckets - #8471
gagantrivedi wants to merge 5 commits into
Conversation
host was written to APIUsageRaw and then dropped by the hourly rollup, so it only survived the raw-data retention window. Buckets now carry it: the rollup groups by host and the overlap check treats it as a dimension. Read paths are unchanged — aggregations still sum across hosts — so dashboards behave exactly as before while the data stays available.
|
The latest updates on your projects. Learn more about Vercel for GitHub. 3 Skipped Deployments
|
Docker builds report
|
📝 WalkthroughWalkthroughThe API usage bucket model and migration add a Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: 🔵 Low · up to Host-heavy usage windows perform unnecessary database deletes during hourly bucket recomputation. Deduplicating these deletes is advisable to avoid avoidable analytics database load. 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8471 +/- ##
========================================
Coverage 98.81% 98.82%
========================================
Files 1621 1623 +2
Lines 66299 66780 +481
========================================
+ Hits 65514 65995 +481
Misses 785 785 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
✅ private-cloud · depot-ubuntu-latest-16 — run #20419 (attempt 1)Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
🗂️ Previous results✅ private-cloud · depot-ubuntu-latest-arm-16 — run #20419 (attempt 1)Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
✅ oss · depot-ubuntu-latest-arm-16 — run #20419 (attempt 1)Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
✅ oss · depot-ubuntu-latest-16 — run #20419 (attempt 1)Playwright Test Results (oss - depot-ubuntu-latest-16)Details
✅ private-cloud · depot-ubuntu-latest-arm-16 — run #20418 (attempt 1)Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
✅ private-cloud · depot-ubuntu-latest-16 — run #20418 (attempt 1)Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
✅ oss · depot-ubuntu-latest-arm-16 — run #20418 (attempt 1)Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
✅ oss · depot-ubuntu-latest-16 — run #20418 (attempt 1)Playwright Test Results (oss - depot-ubuntu-latest-16)Details
✅ private-cloud · depot-ubuntu-latest-arm-16 — run #20417 (attempt 1)Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
✅ oss · depot-ubuntu-latest-arm-16 — run #20417 (attempt 1)Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
✅ private-cloud · depot-ubuntu-latest-16 — run #20417 (attempt 1)Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
✅ oss · depot-ubuntu-latest-16 — run #20417 (attempt 1)Playwright Test Results (oss - depot-ubuntu-latest-16)Details
|
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Team
Run ID: ccf868b1-727f-4ea5-a929-b42caf2afa63
📒 Files selected for processing (4)
api/app_analytics/migrations/0009_apiusagebucket_host.pyapi/app_analytics/models.pyapi/app_analytics/tasks.pyapi/tests/unit/app_analytics/test_tasks.py
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.
Visual Regression19 screenshots compared. See report for details. |
…computed Buckets written before host existed hold every host's count under "". Recomputing such a window from raw data now removes that row before writing the per-host rows, instead of adding to it and double counting. Also covers host grouping on the bucket-to-bucket path.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Advanced
Run ID: d0e764ab-4c02-4955-8026-e83b172f8c0d
📒 Files selected for processing (2)
api/app_analytics/tasks.pyapi/tests/unit/app_analytics/test_tasks.py
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.
A raw group with host "" processed before a real host would have had its freshly written bucket deleted as legacy.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Advanced
Run ID: ad885eef-d3e0-446d-923c-d2ab71903f2c
📒 Files selected for processing (2)
api/app_analytics/tasks.pyapi/tests/unit/app_analytics/test_tasks.py
Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review.
Changes
Contributes to Flagsmith/flagsmith-private#256
hostis written toAPIUsageRawon every tracked request, but the hourly rollup dropped it — aggregated buckets carried no host, so the dimension only survived the raw-data retention window (30 days). With the Edge Proxy reporting its served requests withhost="edge-proxy", that dimension is how proxy-served traffic stays distinguishable from direct traffic long-term.APIUsageBucketgains ahostcolumn (default""for existing rows)._get_api_usage_source_data) groups byhoston both the raw→bucket and bucket→bucket paths, andpopulate_api_usage_bucketwrites it.hostas a dimension alongsideresource.FeatureEvaluationBucketis untouched (no host on its raw rows).How did you test this code?
New test: raw events from two hosts in one bucket window roll up into separate buckets, each keeping its host. Full
test_tasks.py(20) and the bucket read-path tests (test_analytics_db_service.py,test_commands.py, 29) pass against Postgres; ruff + mypy clean.