Skip to content

feat: Keep host on aggregated API usage buckets - #8471

Open
gagantrivedi wants to merge 5 commits into
mainfrom
feat/host-in-usage-buckets
Open

gagantrivedi wants to merge 5 commits into
mainfrom
feat/host-in-usage-buckets

Conversation

@gagantrivedi

Copy link
Copy Markdown
Member

Changes

Contributes to Flagsmith/flagsmith-private#256

host is written to APIUsageRaw on 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 with host="edge-proxy", that dimension is how proxy-served traffic stays distinguishable from direct traffic long-term.

  • APIUsageBucket gains a host column (default "" for existing rows).
  • The rollup (_get_api_usage_source_data) groups by host on both the raw→bucket and bucket→bucket paths, and populate_api_usage_bucket writes it.
  • The overlap check treats host as a dimension alongside resource.
  • Read paths unchanged: usage aggregations still sum across hosts, so the dashboards and usage API behave exactly as before — the data is just no longer thrown away.

FeatureEvaluationBucket is 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.

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.
@gagantrivedi
gagantrivedi requested a review from a team as a code owner September 5, 2026 02:36
@gagantrivedi
gagantrivedi requested review from matthewelwell and removed request for a team September 5, 2026 02:36
@vercel

vercel Bot commented Sep 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Actions Updated
docs Ignored Ignored Preview Sep 12, 2026 6:48am UTC
flagsmith-frontend-preview Ignored Ignored Preview Sep 12, 2026 6:48am UTC
flagsmith-frontend-staging Ignored Ignored Preview Sep 12, 2026 6:48am UTC

Request Review

@github-actions github-actions Bot added the api Issue related to the REST API label Sep 5, 2026
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-e2e:pr-8471 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api-test:pr-8471 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-8471 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api:pr-8471 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-8471 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-8471 Finished ✅ Results

@github-actions github-actions Bot added the feature New feature or request label Sep 5, 2026
@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

📝 Walkthrough

Walkthrough

The API usage bucket model and migration add a host field. Overlap checks and usage aggregation now use resource and host. Bucket creation stores the host and removes matching legacy hostless rows during recomputation. Tests cover separate host buckets, legacy row replacement, empty-host rows, and host-specific totals.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: 🔵 Low · up to f0083

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.82%. Comparing base (2ce9498) to head (f0083b9).
⚠️ Report is 32 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor
✅ private-cloud · depot-ubuntu-latest-16 — run #20419 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  55 seconds
commit  f0083b9
info  🔄 Run: #20419 (attempt 1)

🗂️ Previous results
✅ private-cloud · depot-ubuntu-latest-arm-16 — run #20419 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  43.3 seconds
commit  f0083b9
info  🔄 Run: #20419 (attempt 1)

✅ oss · depot-ubuntu-latest-arm-16 — run #20419 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  46.2 seconds
commit  f0083b9
info  🔄 Run: #20419 (attempt 1)

✅ oss · depot-ubuntu-latest-16 — run #20419 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  34.9 seconds
commit  f0083b9
info  🔄 Run: #20419 (attempt 1)

✅ private-cloud · depot-ubuntu-latest-arm-16 — run #20418 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  4 passed

Details

stats  4 tests across 4 suites
duration  38.8 seconds
commit  c4ada09
info  🔄 Run: #20418 (attempt 1)

✅ private-cloud · depot-ubuntu-latest-16 — run #20418 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  4 passed

Details

stats  4 tests across 4 suites
duration  33.9 seconds
commit  c4ada09
info  🔄 Run: #20418 (attempt 1)

✅ oss · depot-ubuntu-latest-arm-16 — run #20418 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  39.7 seconds
commit  c4ada09
info  🔄 Run: #20418 (attempt 1)

✅ oss · depot-ubuntu-latest-16 — run #20418 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  41.6 seconds
commit  c4ada09
info  🔄 Run: #20418 (attempt 1)

✅ private-cloud · depot-ubuntu-latest-arm-16 — run #20417 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  1 minute, 13 seconds
commit  95b2988
info  🔄 Run: #20417 (attempt 1)

✅ oss · depot-ubuntu-latest-arm-16 — run #20417 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  39.9 seconds
commit  95b2988
info  🔄 Run: #20417 (attempt 1)

✅ private-cloud · depot-ubuntu-latest-16 — run #20417 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  3 passed

Details

stats  3 tests across 3 suites
duration  33.1 seconds
commit  95b2988
info  🔄 Run: #20417 (attempt 1)

✅ oss · depot-ubuntu-latest-16 — run #20417 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  34.1 seconds
commit  95b2988
info  🔄 Run: #20417 (attempt 1)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: ccf868b1-727f-4ea5-a929-b42caf2afa63

📥 Commits

Reviewing files that changed from the base of the PR and between 2ce9498 and 2f7671e.

📒 Files selected for processing (4)
  • api/app_analytics/migrations/0009_apiusagebucket_host.py
  • api/app_analytics/models.py
  • api/app_analytics/tasks.py
  • api/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.

Comment thread api/app_analytics/tasks.py
Comment thread api/tests/unit/app_analytics/test_tasks.py
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Visual Regression

19 screenshots compared. See report for details.
View full report

…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.
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Sep 12, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: d0e764ab-4c02-4955-8026-e83b172f8c0d

📥 Commits

Reviewing files that changed from the base of the PR and between 2f7671e and 95b2988.

📒 Files selected for processing (2)
  • api/app_analytics/tasks.py
  • api/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.

Comment thread api/app_analytics/tasks.py
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Sep 12, 2026
A raw group with host "" processed before a real host would have had
its freshly written bucket deleted as legacy.
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Sep 12, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: ad885eef-d3e0-446d-923c-d2ab71903f2c

📥 Commits

Reviewing files that changed from the base of the PR and between c4ada09 and f0083b9.

📒 Files selected for processing (2)
  • api/app_analytics/tasks.py
  • api/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.

Comment thread api/app_analytics/tasks.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant