Skip to content

perf(Analytics): Read usage and evaluation reports from replicas - #9219

Open
IlarionHalushka wants to merge 3 commits into
Flagsmith:mainfrom
IlarionHalushka:perf/analytics-report-reads-replica
Open

IlarionHalushka wants to merge 3 commits into
Flagsmith:mainfrom
IlarionHalushka:perf/analytics-report-reads-replica

Conversation

@IlarionHalushka

@IlarionHalushka IlarionHalushka commented Dec 2, 2026 •

Copy link
Copy Markdown

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

Contributes to #9217

When analytics shares the main database, analytics report reads now use using_database_replica(). With a separate analytics database they stay on it, because main replicas don't copy it. Rollup, writes, and the usage reads behind billing and usage alerts stay on the writer. Reports may trail the writer by replica lag; they cover windows of days, so this is negligible.

How did you test this code?

New tests cover each report read in both setups: through a replica when analytics shares the main database, never through one when it's separate.

Usage, top-organisation, total-event, flag evaluation and features-in-use
reports read analytics buckets from the writer even when read replicas
are configured.

When analytics shares the main database, bind those reads to a main
replica with the existing `using_database_replica` helper. With a
separate analytics database, keep them on it, since main replicas do
not copy it. Bucket rollup and its writes stay on the writer.
@IlarionHalushka
IlarionHalushka requested review from a team as code owners December 2, 2026 11:52
@IlarionHalushka
IlarionHalushka requested review from bakirFS and khvn26 and removed request for a team December 2, 2026 11:52
@vercel

vercel Bot commented Dec 2, 2026

Copy link
Copy Markdown

@IlarionHalushka is attempting to deploy a commit to the Flagsmith Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added api Issue related to the REST API docs Documentation updates labels Dec 2, 2026

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 4 files

Reply to a comment to ask cubic a question or push back. It learns from your replies.

Re-trigger cubic

Top organisations usage feeds the subscription cache that drives usage
alerts, and the total events count drives overage when the deprecated
usage flag is on. Replica lag could defer those, so only dashboard
reports read from replicas.

@cubic-dev-ai cubic-dev-ai 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.

0 issues found across 2 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval skipped because this PR is from an external contributor.

Re-trigger cubic

khvn26
khvn26 previously approved these changes Dec 2, 2026

@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 👍

@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.83721% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.10%. Comparing base (5268794) to head (5e0757f).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
api/tests/unit/app_analytics/test_replica_reads.py 98.68% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9219      +/-   ##
==========================================
- Coverage   98.96%   98.10%   -0.86%     
==========================================
  Files        1724     1725       +1     
  Lines       73823    73927     +104     
==========================================
- Hits        73056    72528     -528     
- Misses        767     1399     +632     

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

@cubic-dev-ai cubic-dev-ai 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.

0 issues found across 1 file (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval skipped because this PR is from an external contributor.

Re-trigger cubic

This branch has not been deployed

No deployments
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 docs Documentation updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants