Skip to content

feat(usage): push hourly usage snapshots to Control Plane - #7831

Merged
germangarces merged 17 commits into
mainfrom
feat/push-usage
Jul 1, 2026
Merged

feat(usage): push hourly usage snapshots to Control Plane#7831
germangarces merged 17 commits into
mainfrom
feat/push-usage

Conversation

@germangarces

@germangarces germangarces commented Jun 19, 2026

Copy link
Copy Markdown
Member

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Closes #7673

refactor(app_analytics): extract bucket query and aggregation helpers

Pull the shared queryset build and per-resource aggregation out of get_usage_data_from_local_db so a windowed reader can reuse them. No behaviour change.

feat(usage): push hourly usage snapshots to Control Plane

Recurring task reports each licensed organisation's data usage to the Control Plane once an hour, authenticated with the licence signature. No-op until CONTROL_PLANE_URL is set and a licensed organisation exists.

Reads API-call counts at hourly resolution via a new app_analytics window selector; the daily billing path is left untouched.

How did you test this code?

Tested end-to-end locally.

Quick check (No control plane needed):

  1. make docker-up django-migrate
  2. LOG_LEVEL=DEBUG make django-shell
  3. In the shell:
 from unittest.mock import patch, Mock
 from organisations.usage_reporting.services import push_snapshot
 from organisations.usage_reporting.mappers import map_organisation_to_usage_snapshot
 org = Organisation.objects.first() or Organisation.objects.create(name="Test")
 snap = map_organisation_to_usage_snapshot(org)
 with patch("organisations.usage_reporting.services.requests.post",
            return_value=Mock(ok=True, status_code=201)):
     push_snapshot(base_url="http://x", snapshot=snap, signature="dummy")

You should see something like:

[info] snapshot.pushed [usage_reporting] status_code=201

Signed-off-by: germangarces <german.garces@flagsmith.com>
@vercel

vercel Bot commented Jun 19, 2026

Copy link
Copy Markdown

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

3 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview Jun 30, 2026 7:21am
flagsmith-frontend-preview Ignored Ignored Preview Jun 30, 2026 7:21am
flagsmith-frontend-staging Ignored Ignored Preview Jun 30, 2026 7:21am

Request Review

@github-actions github-actions Bot added api Issue related to the REST API docs Documentation updates feature New feature or request and removed docs Documentation updates labels Jun 19, 2026
@github-actions github-actions Bot added the docs Documentation updates label Jun 19, 2026
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request docs Documentation updates labels Jun 19, 2026
@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.62%. Comparing base (e85f77b) to head (abe0b43).
⚠️ Report is 70 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7831      +/-   ##
==========================================
+ Coverage   98.57%   98.62%   +0.05%     
==========================================
  Files        1464     1494      +30     
  Lines       56625    58797    +2172     
==========================================
+ Hits        55818    57991    +2173     
+ Misses        807      806       -1     

☔ 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.

Signed-off-by: germangarces <german.garces@flagsmith.com>
@github-actions github-actions Bot added docs Documentation updates feature New feature or request and removed feature New feature or request docs Documentation updates labels Jun 19, 2026
@germangarces
germangarces marked this pull request as ready for review June 19, 2026 08:19
@germangarces
germangarces requested review from a team as code owners June 19, 2026 08:19
@germangarces
germangarces requested review from khvn26 and removed request for a team June 19, 2026 08:19
@github-actions github-actions Bot removed the feature New feature or request label Jun 19, 2026
@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Docker builds report

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

@github-actions github-actions Bot added the feature New feature or request label Jun 19, 2026
@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  41.4 seconds
commit  c7e5332
info  🔄 Run: #17663 (attempt 1)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  45.2 seconds
commit  c7e5332
info  🔄 Run: #17663 (attempt 1)

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

passed  3 passed

Details

stats  3 tests across 3 suites
duration  54.1 seconds
commit  c7e5332
info  🔄 Run: #17663 (attempt 1)

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  59.6 seconds
commit  c7e5332
info  🔄 Run: #17663 (attempt 1)

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

passed  21 passed

Details

stats  21 tests across 16 suites
duration  1 minute, 20 seconds
commit  054fc67
info  🔄 Run: #17699 (attempt 1)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  41.4 seconds
commit  054fc67
info  🔄 Run: #17699 (attempt 1)

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  47 seconds
commit  054fc67
info  🔄 Run: #17699 (attempt 1)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  38.9 seconds
commit  d31427c
info  🔄 Run: #17702 (attempt 1)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  50.1 seconds
commit  d31427c
info  🔄 Run: #17702 (attempt 1)

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  1 minute, 1 second
commit  d31427c
info  🔄 Run: #17702 (attempt 1)

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  57.3 seconds
commit  d31427c
info  🔄 Run: #17702 (attempt 1)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  41.7 seconds
commit  778dfc5
info  🔄 Run: #17872 (attempt 1)

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  45.8 seconds
commit  778dfc5
info  🔄 Run: #17872 (attempt 1)

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

passed  3 passed

Details

stats  3 tests across 3 suites
duration  1 minute, 6 seconds
commit  778dfc5
info  🔄 Run: #17872 (attempt 1)

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

passed  4 passed

Details

stats  4 tests across 4 suites
duration  42 seconds
commit  778dfc5
info  🔄 Run: #17872 (attempt 1)

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  38.3 seconds
commit  8b34d57
info  🔄 Run: #17884 (attempt 1)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  42.1 seconds
commit  8b34d57
info  🔄 Run: #17884 (attempt 1)

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  54.6 seconds
commit  8b34d57
info  🔄 Run: #17884 (attempt 1)

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  1 minute, 1 second
commit  8b34d57
info  🔄 Run: #17884 (attempt 1)

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

passed  4 passed

Details

stats  4 tests across 3 suites
duration  45.4 seconds
commit  ae73dd2
info  🔄 Run: #17940 (attempt 1)

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

passed  5 passed

Details

stats  5 tests across 4 suites
duration  48.3 seconds
commit  ae73dd2
info  🔄 Run: #17940 (attempt 1)

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

failed  2 failed
passed  2 passed

Details

stats  4 tests across 3 suites
duration  32.5 seconds
commit  ae73dd2
info  📦 Artifacts: View test results and HTML report
🔄 Run: #17940 (attempt 1)

Failed tests

firefox › tests/flag-tests.pw.ts › Flag Tests › Feature flags can be created, toggled, edited, and deleted across environments @oss
firefox › tests/mv-options-tests.pw.ts › Multivariate Options › Variants can be added and removed in a single save @oss

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

passed  4 passed

Details

stats  4 tests across 3 suites
duration  58 seconds
commit  ae73dd2
info  🔄 Run: #17940 (attempt 1)

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

passed  4 passed

Details

stats  4 tests across 3 suites
duration  41.4 seconds
commit  4bb4479
info  🔄 Run: #17941 (attempt 1)

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

passed  5 passed

Details

stats  5 tests across 3 suites
duration  18.8 seconds
commit  4bb4479
info  🔄 Run: #17941 (attempt 1)

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

passed  5 passed

Details

stats  5 tests across 4 suites
duration  34.3 seconds
commit  4bb4479
info  🔄 Run: #17941 (attempt 1)

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

passed  5 passed

Details

stats  5 tests across 4 suites
duration  42.3 seconds
commit  4bb4479
info  🔄 Run: #17941 (attempt 1)

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

passed  4 passed

Details

stats  4 tests across 3 suites
duration  17.6 seconds
commit  635441b
info  🔄 Run: #17942 (attempt 1)

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

passed  3 passed

Details

stats  3 tests across 3 suites
duration  44.8 seconds
commit  635441b
info  🔄 Run: #17942 (attempt 1)

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

passed  6 passed

Details

stats  6 tests across 4 suites
duration  35 seconds
commit  635441b
info  🔄 Run: #17942 (attempt 1)

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

passed  4 passed

Details

stats  4 tests across 4 suites
duration  40.8 seconds
commit  635441b
info  🔄 Run: #17942 (attempt 1)

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

failed  1 failed
passed  3 passed

Details

stats  4 tests across 3 suites
duration  32.8 seconds
commit  9125b21
info  📦 Artifacts: View test results and HTML report
🔄 Run: #17944 (attempt 1)

Failed tests

firefox › tests/mv-options-tests.pw.ts › Multivariate Options › Variants can be added and removed in a single save @oss

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

passed  6 passed

Details

stats  6 tests across 4 suites
duration  11.6 seconds
commit  9125b21
info  🔄 Run: #17944 (attempt 1)

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

passed  4 passed

Details

stats  4 tests across 3 suites
duration  1 minute, 4 seconds
commit  9125b21
info  🔄 Run: #17944 (attempt 1)

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

passed  5 passed

Details

stats  5 tests across 4 suites
duration  51.5 seconds
commit  86d4210
info  🔄 Run: #17946 (attempt 1)

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

passed  6 passed

Details

stats  6 tests across 4 suites
duration  4.8 seconds
commit  86d4210
info  🔄 Run: #17946 (attempt 1)

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

passed  5 passed

Details

stats  5 tests across 4 suites
duration  59.3 seconds
commit  86d4210
info  🔄 Run: #17946 (attempt 1)

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

failed  2 failed

Details

stats  2 tests across 2 suites
duration  1 minute, 6 seconds
commit  86d4210
info  📦 Artifacts: View test results and HTML report
🔄 Run: #17946 (attempt 1)

Failed tests

firefox › tests/environment-permission-test.pw.ts › Environment Permission Tests › Environment-level permissions control access to features, identities, and segments @enterprise
firefox › tests/project-permission-test.pw.ts › Project Permission Tests › Project-level permissions control access to features, environments, audit logs, and segments @enterprise

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

passed  4 passed

Details

stats  4 tests across 3 suites
duration  41.4 seconds
commit  496e3fb
info  🔄 Run: #17948 (attempt 1)

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

passed  6 passed

Details

stats  6 tests across 4 suites
duration  37.9 seconds
commit  32c5ac0
info  🔄 Run: #17949 (attempt 1)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  19.5 seconds
commit  496e3fb
info  🔄 Run: #17948 (attempt 1)

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

passed  6 passed

Details

stats  6 tests across 5 suites
duration  33.4 seconds
commit  496e3fb
info  🔄 Run: #17948 (attempt 1)

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

passed  7 passed

Details

stats  7 tests across 6 suites
duration  19.6 seconds
commit  496e3fb
info  🔄 Run: #17948 (attempt 1)

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

passed  3 passed

Details

stats  3 tests across 3 suites
duration  1 minute, 2 seconds
commit  32c5ac0
info  🔄 Run: #17949 (attempt 1)

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

failed  2 failed

Details

stats  2 tests across 2 suites
duration  1 minute, 6 seconds
commit  32c5ac0
info  📦 Artifacts: View test results and HTML report
🔄 Run: #17949 (attempt 1)

Failed tests

firefox › tests/environment-permission-test.pw.ts › Environment Permission Tests › Environment-level permissions control access to features, identities, and segments @enterprise
firefox › tests/project-permission-test.pw.ts › Project Permission Tests › Project-level permissions control access to features, environments, audit logs, and segments @enterprise

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

passed  5 passed

Details

stats  5 tests across 4 suites
duration  51.5 seconds
commit  90b08ef
info  🔄 Run: #17950 (attempt 1)

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

passed  4 passed

Details

stats  4 tests across 3 suites
duration  44.4 seconds
commit  90b08ef
info  🔄 Run: #17950 (attempt 1)

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

passed  5 passed

Details

stats  5 tests across 4 suites
duration  11.4 seconds
commit  90b08ef
info  🔄 Run: #17950 (attempt 1)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  35.6 seconds
commit  90b08ef
info  🔄 Run: #17950 (attempt 1)

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

passed  4 passed

Details

stats  4 tests across 3 suites
duration  34 seconds
commit  fc200c8
info  🔄 Run: #17951 (attempt 1)

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

passed  5 passed

Details

stats  5 tests across 4 suites
duration  45.7 seconds
commit  fc200c8
info  🔄 Run: #17951 (attempt 1)

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

passed  6 passed

Details

stats  6 tests across 5 suites
duration  10.7 seconds
commit  fc200c8
info  🔄 Run: #17951 (attempt 1)

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

passed  6 passed

Details

stats  6 tests across 5 suites
duration  11.4 seconds
commit  fc200c8
info  🔄 Run: #17951 (attempt 1)

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

passed  4 passed

Details

stats  4 tests across 3 suites
duration  41.6 seconds
commit  1285ba8
info  🔄 Run: #17954 (attempt 1)

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

passed  5 passed

Details

stats  5 tests across 4 suites
duration  4.5 seconds
commit  1285ba8
info  🔄 Run: #17954 (attempt 1)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  30.9 seconds
commit  1285ba8
info  🔄 Run: #17954 (attempt 1)

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

passed  4 passed

Details

stats  4 tests across 4 suites
duration  11.3 seconds
commit  1285ba8
info  🔄 Run: #17954 (attempt 1)

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

passed  4 passed

Details

stats  4 tests across 3 suites
duration  17.5 seconds
commit  abe0b43
info  🔄 Run: #17955 (attempt 1)

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  38 seconds
commit  abe0b43
info  🔄 Run: #17955 (attempt 1)

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

passed  3 passed

Details

stats  3 tests across 2 suites
duration  38.5 seconds
commit  abe0b43
info  🔄 Run: #17955 (attempt 1)

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  1 minute
commit  abe0b43
info  🔄 Run: #17955 (attempt 1)

@github-actions github-actions Bot added docs Documentation updates feature New feature or request and removed feature New feature or request docs Documentation updates labels Jun 30, 2026
Signed-off-by: germangarces <german.garces@flagsmith.com>
@github-actions github-actions Bot added docs Documentation updates feature New feature or request and removed feature New feature or request docs Documentation updates labels Jun 30, 2026
Signed-off-by: germangarces <german.garces@flagsmith.com>
@github-actions github-actions Bot added docs Documentation updates feature New feature or request and removed feature New feature or request docs Documentation updates labels Jun 30, 2026
Signed-off-by: germangarces <german.garces@flagsmith.com>
@github-actions github-actions Bot added the docs Documentation updates label Jun 30, 2026
Signed-off-by: germangarces <german.garces@flagsmith.com>
@github-actions github-actions Bot added feature New feature or request docs Documentation updates and removed feature New feature or request docs Documentation updates labels Jun 30, 2026
Signed-off-by: germangarces <german.garces@flagsmith.com>
Signed-off-by: germangarces <german.garces@flagsmith.com>
Signed-off-by: germangarces <german.garces@flagsmith.com>
Signed-off-by: germangarces <german.garces@flagsmith.com>

@khvn26 khvn26 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM 👍

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.

Push hourly usage snapshots to Control Plane

3 participants